carlos / platform Public

Record final demo alert verification and review

claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev beb0ba607b9ceb6f15f3f9a92de13f145642e36b parent 4f0f08a
3 files changed, +103 −4
  • docs/superpowers/notes/demo-abuse-alerts.md +4 −4
  • docs/superpowers/reviews/REVIEW-CHECK-FINDINGS-demo-abuse-alerts-R1.md +29 −0
  • docs/superpowers/reviews/VERIFICATION-demo-abuse-alerts.md +70 −0
diff --git a/docs/superpowers/notes/demo-abuse-alerts.md b/docs/superpowers/notes/demo-abuse-alerts.md
index e00b50dad..80c2adec6 100644
--- a/docs/superpowers/notes/demo-abuse-alerts.md
+++ b/docs/superpowers/notes/demo-abuse-alerts.md
@@ -61,8 +61,8 @@ Existing app abuse metadata and its retention are unchanged.
A persistent firing bit per recipient prevents repeated mail while a condition
stays true. A quiet observation rearms it without sending a clear. Failed sends
-retry on later passes; a crash after mail acceptance but before recording
-success can duplicate mail. Failed transient conditions retry while still firing.
+retry on later passes; a stop or receipt-write failure after mail acceptance
+can duplicate mail. Failed transient conditions retry while still firing.
No reminders are added. Digests remember the report IDs in each successful
snapshot, bounded by the existing 2,000-report queue. A late commit with an
older request timestamp still appears next time. Failed sends never advance
@@ -101,8 +101,8 @@ alerts, even if fleet reads failed. Demo sends have a 60s pass budget and stop
on a transport timeout. Demo errors are logged separately from the fleet job.
Immediate reports therefore arrive on the next pass rather than waiting for
the digest. Costs are a handful of indexed SQLite aggregates per minute,
-local counter writes on refused admissions, and mail only on transitions or
-nonempty digests. Alert text contains aggregate counts, never IP hashes,
+local counters, digest receipts (up to about 100 KB per recipient on empty
+passes; recorded as a P3), and mail on transitions or nonempty digests. Alert text contains aggregate counts, never IP hashes,
report details, demo names or claim tokens.
Implementation: `internal/console/demo_alerts.go:101` evaluates signals;
diff --git a/docs/superpowers/reviews/REVIEW-CHECK-FINDINGS-demo-abuse-alerts-R1.md b/docs/superpowers/reviews/REVIEW-CHECK-FINDINGS-demo-abuse-alerts-R1.md
new file mode 100644
index 000000000..5fe14afbd
--- /dev/null
+++ b/docs/superpowers/reviews/REVIEW-CHECK-FINDINGS-demo-abuse-alerts-R1.md
@@ -0,0 +1,29 @@
+# Opus round 1 fix check
+
+Reviewed tip: `4f0f08a3aec542f11e3782375befe6864f5d6979`.
+
+**Verdict: READY.** Both P2s are fixed, and the fixes add no P1 or P2. I found two P3 follow-ups. As the brief asked, I ran no tests, made no edits and created no scratch files.
+
+## P2.1, fleet liveness: resolved
+- The demo pass now runs after `s.jobs.Run(..., alertEnginePass)` and outside it (`alertengine_pass.go:99-104`). The fleet step, the drain and the heartbeat all finish first. Demo errors are only logged, through `demoAlertPassLog`. They are no longer joined into the job result (`alertengine_pass.go:128-152`).
+- The whole pass has one 60-second deadline (`alertPassBudget`, `demo_alerts.go:172`). Each send's own 20-second timeout comes from that pass deadline, so a send can't outlast it.
+- The pass stops on the first timeout. `sendDemoAlert` adds the per-send `ctx.Err()` to the send's error (`demo_alerts.go:236`, `:244`), and `demoAlertTimedOut` stops the pass on a signal send (`:209`) or a digest (`:218`). The digest error keeps the timeout visible because `demoAlertDeliveryError` wraps with `%w`.
+- A stalled mail lock is also covered. `acquire` wraps `ctx.Err()` with `%w` (`consolemail.go:113`), so the timeout check sees it.
+- At worst, the next fleet pass now starts about 60 seconds late. The heartbeat counts as stale only after 10 minutes (`host/enginebeat.go:29`), so `engine_silent` won't trip.
+- The signals and recipients still read only SQLite: `demoAlertSignals`, then `GrantToken` in `grantRecipients`. There are no S3 reads.
+
+## P2.2, report completeness: resolved
+- **Schema:** `report_ids TEXT NOT NULL DEFAULT '[]'` (`demo_alerts.go:86-89`). It is added through `CREATE TABLE IF NOT EXISTS`, which is acceptable only because the table was never deployed.
+- **Bound:** the 2,000-row cap is real (`demo_reports.go:131`). IDs are a Unix time plus a random 16-byte nonce (`:137`), so an ID is never reused.
+- **Commit only after success:** the snapshot of IDs is taken from rows with `created_at<now` (`:279`). It is written only after the send succeeds (`:317`). A failed send returns at `:315` without writing anything.
+- **Late commits:**
+ - A report that commits after the read is missing from the saved snapshot. The next digest counts it as unseen, whatever its timestamp.
+ - A report whose ID is already in the snapshot is never counted twice.
+- **Empty days:** the update at `:309` only removes IDs whose reports were deleted. It doesn't use up the day's send.
+- **First digest:** with no row yet, it counts only the last 24 hours. Every ID it sees, older ones included, goes into the snapshot, so older reports are never counted later.
+- **Mail cache (fix 3):** when a later check finds the domain not verified, it clears `ensuredConfigSet` (`consolemail.go:170`). `Send` is unchanged. `SendReady` still reads only memory under the lock, never the control store.
+- **SQL gate (fix 4):** only the NonApp description changed (`store_gate.go:201`). The table carries no app authority.
+
+## New issues from these fixes (P3 only)
+1. **The empty-day prune rewrites the snapshot every minute** (`demo_alerts.go:309`). After a digest day with no new reports, every pass rescans up to 2,000 rows and writes up to about 100 KB of JSON per recipient, even when nothing changed. That adds a needless SQLite write every minute, which a database replica would have to copy. Fix: write only when the encoded list differs from `raw`. Fault family: efficiency, not completeness.
+2. **A digest sent near the 60-second deadline can go out twice** (`demo_alerts.go:317`). The receipt write uses the pass context. If a send succeeds just before the deadline, `ExecContext` fails on the expired context and the receipt is never saved. The next pass then sends the same digest again that day. Reports are never lost, so completeness holds. Fix: write the receipt with `context.WithoutCancel(ctx)` and a short timeout of its own. Fault family: digest dedupe and retry.
diff --git a/docs/superpowers/reviews/VERIFICATION-demo-abuse-alerts.md b/docs/superpowers/reviews/VERIFICATION-demo-abuse-alerts.md
new file mode 100644
index 000000000..da2f32682
--- /dev/null
+++ b/docs/superpowers/reviews/VERIFICATION-demo-abuse-alerts.md
@@ -0,0 +1,70 @@
+# Demo abuse alert verification
+
+Source tip: `4f0f08a3aec542f11e3782375befe6864f5d6979` on `demo-abuse-alerts`.
+Later changes only record the review, costs and these results. Nothing was
+pushed, merged, tagged, released or activated. No AWS account was accessed.
+
+## Checks
+
+- `nice -n 10 go test -json ./internal/console -run 'TestDemo|TestAlert|TestConsoleMailer|TestClaimSQLTableCensus|TestClaimSQLSeamCallers|TestClaimAuthoritySourceCensus' -count=1 -timeout=30m`
+ passed in 861.136s: 416 top-level tests passed, two skipped; 1,105 cases
+ passed when subtests are counted. This run used the b9f4b53a source, before
+ the final delivery scheduling change. The first run hit the default 10m
+ timeout in TestDemoClaimUXHeadless; no assertion had failed before timeout.
+- `nice -n 10 go test ./internal/console -run '^TestDemoAlert|^TestAlertEngine|^TestClaimSQLTableCensus$|^TestDemoProtectionsSQLScopes$' -count=1`
+ passed on the final source in 4.154s. The existing engine tests are named
+ TestEngine rather than TestAlertEngine, so they were checked separately below.
+- `nice -n 10 go test ./internal/console -run '^TestEngine|^TestDemoAlert' -count=1`
+ passed on the final source in 12.765s. All 18 new test functions passed.
+ New tests inject time and use no sleeps. The late-report and rejected-mail
+ regressions were each observed failing before their respective fixes.
+- `nice -n 10 go vet ./internal/console/ ./` passed on the final source.
+- `nice -n 10 go build ./...` passed on the final source.
+- `gofmt -l .` produced no output; `git diff --check` passed.
+
+TestDemoClaimDevAcceptance skipped because it requires a designated live
+sandbox and prebuilt host/instance-control witnesses. TestDemoReportBrowser
+skipped because CARLOS_DEMO_BROWSER_TESTS was not enabled. The existing demo
+claim headless tests ran and passed. The full Go suite was not run, as instructed.
+
+Only console source, console tests and documentation changed. The linux amd64
+and arm64 root dependency lists exclude internal/console; no root census
+change, overlay or CLI cross-compile was needed. Go caches stayed at their
+defaults. Both temporary test directories left by the timed-out runs were
+removed by their exact paths after checking that no process referenced them.
+Task-created logs and briefs were removed; unrelated scratch files were kept.
+
+## Review
+
+Opus round 1 found no P1 and two P2. Both were fixed. The bounded check of the
+new digest storage and mail/scheduling behaviour returned READY, with no new
+P1 or P2. Review is closed. The original findings and fix-check findings beside
+this file retain the P3 follow-up lists. The reviewer also ran a wider targeted
+SQL probe that hit its default 10m timeout; its subsequent focused alert and
+SQL scope checks passed. That wider probe was not repeated.
+
+Paul still needs to edit the draft copy, confirm recipients and thresholds,
+and choose the flagship activation date. Settings use the brief's permitted
+CONSOLE_DEMO_ALERT_* fallback and take effect after a console restart.
+
+## Changed files
+
+- `cmd/console/main.go`
+- `docs/superpowers/notes/demo-abuse-alerts.md`
+- `docs/superpowers/reviews/REVIEW-BRIEF-demo-abuse-alerts-R1.md`
+- `docs/superpowers/reviews/REVIEW-CHECK-FINDINGS-demo-abuse-alerts-R1.md`
+- `docs/superpowers/reviews/REVIEW-CHECK-demo-abuse-alerts-R1.md`
+- `docs/superpowers/reviews/REVIEW-FINDINGS-demo-abuse-alerts-R1.md`
+- `docs/superpowers/reviews/VERIFICATION-demo-abuse-alerts.md`
+- `internal/console/alertengine_pass.go`
+- `internal/console/alertstore.go`
+- `internal/console/apidemo.go`
+- `internal/console/consolemail.go`
+- `internal/console/demo_alert_admission.go`
+- `internal/console/demo_alert_admission_test.go`
+- `internal/console/demo_alert_copy.go`
+- `internal/console/demo_alerts.go`
+- `internal/console/demo_alerts_test.go`
+- `internal/console/demo_store.go`
+- `internal/console/server.go`
+- `internal/console/store_gate.go`