carlos / platform Public

review: Astra round 1 findings and scoped-check brief, console shutdown

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a60c26f6b827f109860626f9fb6776e104cb0651 parent a2e41df
2 files changed, +82 −0
  • docs/superpowers/reviews/CHECK-BRIEF-audit-console-shutdown-R1-fix.md +30 −0
  • docs/superpowers/reviews/FINDINGS-audit-console-shutdown-R1.md +52 −0

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/reviews/CHECK-BRIEF-audit-console-shutdown-R1-fix.md b/docs/superpowers/reviews/CHECK-BRIEF-audit-console-shutdown-R1-fix.md
new file mode 100644
index 000000000..7ed541611
--- /dev/null
+++ b/docs/superpowers/reviews/CHECK-BRIEF-audit-console-shutdown-R1-fix.md
@@ -0,0 +1,30 @@
+# Scoped check: audit-console-shutdown, after round 1 (not a review round)
+
+Repo carlos/platform, branch `audit-console-shutdown` (tip in the prompt).
+
+Round 1 (`docs/superpowers/reviews/FINDINGS-audit-console-shutdown-R1.md`)
+ended READY AFTER FIXES with four P2s and one P3. The fix is commit
+a2e41dfe. AGENTS.md "Stopping rules" rule 1: the review does not reopen,
+but newly changed termination behaviour is checked. This is that check.
+
+Scope: `git show a2e41dfe` only.
+
+Check:
+1. Each round-1 finding: resolved, partly, not (one line each).
+2. Does the fix introduce a path where the process never exits, exits 0
+ after a second signal, releases the policy lease while the capacity
+ observer runs, or releases it twice?
+3. Worker admission closes before cancel and join; startup steps on the
+ worker context; a failing startup step during an early stop waits for
+ the stop. Any deadlock between those?
+4. StartRelay now joins its writer-lease loop before returning; the
+ verify reader and the GeoIP loops are joined workers. Could any of
+ these now block startup or shutdown forever (a join on a loop that
+ never sees cancellation)?
+5. New tests: deterministic enough for a loaded runner (one waits 200 ms;
+ one pins GOMAXPROCS=1)?
+
+Answer each item: OK, or a finding with file:line, failure scenario and
+fix, marked P1 (unsafe or broken) or P2. End with exactly one line:
+CHECK PASSED, or CHECK FAILED with the P1s. Do not edit files, do not
+spawn reviewers or agents, do not run full test suites.
diff --git a/docs/superpowers/reviews/FINDINGS-audit-console-shutdown-R1.md b/docs/superpowers/reviews/FINDINGS-audit-console-shutdown-R1.md
new file mode 100644
index 000000000..3fdec05a1
--- /dev/null
+++ b/docs/superpowers/reviews/FINDINGS-audit-console-shutdown-R1.md
@@ -0,0 +1,52 @@
+Reviewed `c4b44c34..b0f70f0c311a61e46e29ac3c3688930ef3023baf`, round 1 of 3. The requested tip adds only the brief to the implementation commit named there.
+
+No P1 findings.
+
+1. **P2 — A queued second signal can lose to lease release and a successful exit.**
+ **Location:** [stop.go:152](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop.go:152), [stop.go:171](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop.go:171).
+ **Invariant:** A second signal forces exit status 1 and prevents initiation of graceful lease release.
+ The second-signal goroutine sets `hurried` asynchronously. If a second signal is already buffered but that goroutine has not run, completed request and worker waits can lead directly to `p.release(force)` and return `false`. Deferred cancellation can then make the watcher exit without consuming the signal. The existing test avoids this race by keeping shutdown blocked on a handler until the watcher cancels it.
+
+ **Fix:** Serialize second-signal handling, the release decision and the final exit status. Add coverage with a queued second signal and already-completed workers, plus signals during worker waiting and release. Define the release boundary accurately: cancellation cannot undo a remote release already issued.
+
+2. **P2 — The worker join omits live background loops.**
+ **Location:** [main.go:789](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/main.go:789), [stop.go:227](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop.go:227).
+ **Invariant:** Background workers receive cancellation and are joined or named when the shutdown budget expires.
+ `StartVerifyReader` receives `work.ctx`, but its internal goroutine is never registered or joined. `StartRelay` starts `relayWriterLoop` in another goroutine and returns without joining it. The GeoIP follower and override-expiry watcher started through `consoleGeoReader` still run outside the worker context altogether.
+
+ Consequently, shutdown can report completion while these loops remain active; a stuck nested relay renewal is absent from the worker timeout report.
+
+ **Fix:** Give these loops completion signals or blocking entry points and include them in the bounded join. Make `StartRelay` join its child before returning. Add coverage that holds a nested worker open and checks that shutdown waits or names it.
+
+3. **P2 — Early shutdown does not close worker admission.**
+ **Location:** [stop.go:108](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop.go:108), [stop.go:269](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop.go:269).
+ **Invariant:** Once shutdown starts joining workers, startup cannot introduce work outside that join.
+ `untilServing` runs shutdown concurrently with the remainder of `serve`. Startup continues calling `work.Go`, which accepts work even after cancellation. If the registry becomes empty, `wait` can return; a subsequent `Go` rearms the registry, but shutdown does not wait again. The new worker can execute its initial pass while lease release proceeds. Receiving an already-cancelled context does not prevent that function from running.
+
+ **Fix:** Close worker admission atomically before cancellation and joining, and reject subsequent starts. Pass the startup cancellation context through remaining startup operations. Test a worker start attempted after the shutdown join has begun.
+
+4. **P2 — The stuck-worker test depends on cooperative goroutines running within 50 ms.**
+ **Location:** [stop_test.go:316](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop_test.go:316).
+ **Invariant:** Tests distinguish shutdown defects from runner scheduling delays.
+ The test requires both the ordinary worker and capacity observer to finish within 50 ms. On a loaded runner, either may miss that window. Correct production behavior then logs another outstanding worker or retains the lease, failing the exact-count or release assertion.
+
+ **Fix:** Pre-complete the unrelated worker and observer in this timeout-specific test, or control deadline advancement explicitly. Keep cancellation-and-join ordering covered separately by the channel-coordinated drain test.
+
+5. **P3 — The handoff test leaves its fixture goroutines running.**
+ **Location:** [stop_test.go:363](/home/paulca/amadan.net/carlos/platform-audit-console-shutdown/cmd/console/stop_test.go:363).
+ **Invariant:** Test fixtures clean up goroutines they start.
+ The handoff subtest never cancels the worker context, leaving the ordinary worker and capacity observer blocked after the test returns.
+
+ **Fix:** Register fixture cleanup that cancels and joins both. Track this as follow-up work.
+
+The normal serving shutdown order is sound: HTTP shutdown starts first, upgraded connections close through the shutdown hook, outstanding handlers receive the shared drain budget and cut grace, then workers are cancelled. The policy release is gated on actual capacity-observer completion. I found no duplicate release path in the new coordinator.
+
+The nominal budgets total 37 seconds, assuming the release implementation honors its cancellation and timeout. Twenty seconds is a reasonable bounded drain for ordinary requests, but cannot complete every supported operation: rootfs uploads allow an hour, and import checking continues asynchronously after HTTP 202. Interrupted uploads surface as CLI errors, generally transport errors rather than an explanation that the console restarted. Detached import checking remains outside this shutdown lifecycle; its existing restart-and-sweep recovery still applies.
+
+In the cancellation paths inspected, I found no newly introduced durable state requiring operator repair solely because these worker contexts now cancel. Mail deliveries may remain due and be retried; scan callbacks are best effort; seed, lifetime and purchase work retains recovery state.
+
+The four changed source-reading tests retain their principal checks. The new functional shutdown tests distinguish draining, forced cuts, upgraded connections and observer-before-release ordering from the old behavior. Their second-signal and startup coverage needs the additions above.
+
+The targeted test command could not start because the read-only sandbox prevented Go from creating its build directory. No tests executed, no full suites ran, and no files were changed.
+
+READY AFTER FIXES
\ No newline at end of file