carlos / platform Public

review: Astra brief for race-activator-1249, round 3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3579a282f3e59e9b9e19949fc3a80d876d3160c9 parent 862dc78
1 file changed, +149 −0
  • docs/superpowers/reviews/REVIEW-BRIEF-race-activator-1249-r3.md +149 −0

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-race-activator-1249-r3.md b/docs/superpowers/reviews/REVIEW-BRIEF-race-activator-1249-r3.md
new file mode 100644
index 000000000..5bcb62608
--- /dev/null
+++ b/docs/superpowers/reviews/REVIEW-BRIEF-race-activator-1249-r3.md
@@ -0,0 +1,149 @@
+# Review brief: branch race-activator-1249, round 3 of 3 (the last)
+
+Repo carlos/platform, branch `race-activator-1249`, commit 862dc78c1a9b4c51768ed5deca1bfbebf4801279.
+Under review: the diff `origin/main...862dc78c`, mainly what changed since
+round 2 (fb49b811). Authorities: amadan #1249 (the last four posts),
+AGENTS.md ("The census", "Stopping rules", the `70-race` paragraph).
+
+The invariant (the fault family across rounds 1 and 2): every goroutine
+that reads a package-level setting must have finished, with a
+happens-before edge, before a test restores that setting.
+
+Round 2 found one P1: a subtest restored a package-wide setting while its
+parent's Service (or one the subtest built before its first restoreKnob)
+was still alive, and that Service's parked lease watch could wake on a
+lease timer and read `roleEmptyBound` during the restore. Paul chose
+"refuse up front" on 2026-11-19. CI on fb49b811 also failed:
+`TestSwapReleaseRefusedByRootAbandons` reported a lease watch still
+running 10 s after the test.
+
+## What changed since round 2
+
+All in `internal/activator` unless named.
+
+1. `knobrestore_test.go`: `setKnob(t, &v, x)` replaces `restoreKnob`. It
+ takes knobRestores' lock, checks the rule, records the old value and
+ the restore, and only then writes. The rule: a subtest (a name with
+ "/") may not change a setting while a tracked Service it does not own
+ is running. It owns the Services it built after its first setKnob.
+ Broken, setKnob calls t.Fatalf naming the rule and the builder, and
+ writes nothing. Top-level tests are not checked; their restores join
+ every tracked Service, as in round 2.
+2. `newTrackedService(t, ...)` now takes the test. Each tracked Service
+ records its builder's name, whether the builder had already called
+ setKnob, and (through a cleanup) when the builder ended.
+ `firstOwned`, `ownedServices` and the subtest slicing are gone: at any
+ restore, under the rule, the running tracked Services are the
+ restoring test's own, so the join acts on all of them. Ended ones are
+ pruned after each restore.
+3. Converted callers: all 118 restoreKnob sites, and 31 deferred
+ restores of package settings that never went through restoreKnob
+ (`defer func() { x = old }()`, `defer func(d) { x = d }(x)`): for
+ example `sidecarSettle`, `spawnHealthTimeout` and `randRead` in
+ activator_test.go, `firstWakeKillBound` in exec_gate_test.go,
+ `respawnJoinBound` in swap_executed_test.go, `inputsStampRacy` in
+ inputs_test.go, and `hasOwnReplica`, `restoreReplica` and
+ `checkSeedDB` in seedplace_linux_test.go. A `defer` runs before the
+ test's cleanups, so before its rig stops the Service.
+4. Overrides the guard refused, now moved to the parent. One test was
+ refused: `TestPoolGateIndependentAdmissions/placement generation
+ lost` (ha_pool_test.go), whose `haService` rig sets `restoreReplica`
+ while the parent's Service and three loop rigs run. It is now a block
+ of the parent. Three tables whose subtests wrote a setting directly
+ under a parent-level restore now set it with setKnob in each subtest,
+ before building anything: `TestSwapCanarySettle` (settle_test.go),
+ `TestSwapHoldCanarySettles` and the hold-stop case of
+ `TestSwapHoldReleasesItsCallerWhileTheStopIsPending` (swap_hold_test.go;
+ it had set `wakeWaitBound` after building its fixture).
+5. The CI failure's root cause: that test installs its entry by hand and
+ registers a cleanup, after `shrinkCmdBounds`' setKnob, that deletes the
+ entry from `a.entries` without closing `ownerDone`. Cleanups run last
+ first, so the entry was gone before the restores, and
+ `endLeaseWatches`, which reached watches only through `a.entries`,
+ could not end it. It failed every time locally on fb49b811. Fix, in
+ production: `Service.leaseWatchStop` (activator.go), a channel that
+ is nil in production, and one more case in `watchResidentLease`'s
+ select (rootfs_service.go). `newTrackedService` makes the channel
+ before anything can start a watch (New starts no goroutine), and
+ `endLeaseWatches` closes it once per Service (sync.Once), then waits
+ on `leaseWork`. Tests no longer touch `ownerDone`.
+6. New tests: `TestSetKnobRefusesASubtestWhileAServiceItDoesNotOwnRuns`
+ (the refusal for a parent's Service and for one built first, both
+ before any write, through a testing.TB whose Fatalf ends only its own
+ goroutine; and no refusal for a Service built after the first
+ setKnob), and `TestEndLeaseWatchesEndsAWatchWhoseEntryWasDropped`. It
+ fails at the 10 s bound when the close is taken out.
+7. AGENTS.md's `70-race` paragraph states the rule. Census re-sealed
+ (`docs/superpowers/notes/census-proposal-race-activator-1249.md`).
+ `.amadan/code-health.tsv`: activator.go's file-lines record is raised
+ from 3779 to 3780 (the new field), and activator_test.go's is lowered
+ to 5481.
+
+Left as they are, with the reason:
+
+- Test writes swapped and put back inline in the test goroutine around a
+ synchronous call, with no Service or backend goroutine running
+ (escrow_test.go's ledger seams, rootfs_processes_test.go's
+ `rootfsBoxPlatform`, startrule_test.go:410 and seedplace_linux_test.go:466
+ `setAsideRename` and `restoreReplica`, seedpurge's `restoreReplica`).
+- Seams guarded by their own mutex, which production takes to read them
+ (`adminTokenMu`: instanceKeyWrite, instanceKeySync, adoptionRecordSync;
+ `ttyPeerMu`: ttyPeerOK).
+- haleaseloss_test.go:504, whose deferred restore of `acquireHALease`
+ first waits on `s.a.haLoss.joined`, the WaitGroup of the only goroutine
+ that reads it.
+- Writes after a setKnob of the same setting in the same test (for
+ example demo_durability_test.go:601, rootfsdb_test.go:419,
+ probewake_test.go:363). The restore that setKnob recorded still runs
+ after the join. A write while the test's own Service runs is a separate
+ question from this invariant, which is about restores.
+- TestMain's one write of `sidecarSettle`, before any test runs.
+
+## What to check
+
+1. The invariant holds for every override in `internal/activator`'s
+ tests: no reader of a setting runs after its restore or without a
+ happens-before edge to it. Look for a test write to a package-level
+ setting that is not setKnob and whose restore can run while a
+ production goroutine reads it. Look for a schedule that breaks the
+ rule's claim that the running tracked Services at a restore are the
+ restoring test's own (parallel tests, nested subtests, Services built
+ by helpers with another test's t).
+2. The guard runs before any mutation: no path through setKnob writes
+ `*p` before the check, and a refusal leaves no restore registered.
+3. No test is refused: the guard fires only in
+ `TestSetKnobRefusesASubtestWhileAServiceItDoesNotOwnRuns`'s fake.
+4. Every lease watch a Service starts is reachable: is there a watch
+ that does not select on `leaseWatchStop`, a tracked Service whose
+ channel is not made before its first watch, or a double close?
+5. Production is unchanged: `leaseWatchStop` is nil outside tests and
+ nothing in production writes, closes or waits on it or on `leaseWork`.
+6. Census: a verdict for every changed unit and envelope below.
+
+## Census
+
+Per `docs/superpowers/notes/census-proposal-race-activator-1249.md` (seal
+`5d4a5eea…` → `c2580d30…`), approve or reject each:
+
+- `internal/activator/activator.go` `type Service` (body): two test-only
+ fields, `leaseWork` and `leaseWatchStop`; no read added.
+- `internal/activator/rootfs_service.go` `Service.residentLeaseShort`
+ (body): unchanged since round 2 (counts each one-shot stop in
+ `leaseWork`).
+- Envelope `internal/activator`, re-pinned. Its changed functions are
+ the two above, `watchResidentLeaseLocked` (`leaseWork.Add`, unchanged
+ since round 2) and `watchResidentLease` (`leaseWork.Done`, and the new
+ select case on `leaseWatchStop`).
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+- **P2**: wrong or missing. Fixed without reopening this review.
+- **P3**: clarity or polish. Follow-up list only.
+
+## Output
+
+Findings ranked P1, P2, P3, each with file:line, the failure scenario and
+the fix, then the census verdicts. End with exactly one of: READY, READY
+AFTER FIXES, NOT READY. Do not edit files, spawn reviewers or run full
+suites.