reviews: Astra round 1 on the G6 write fence plan (NOT READY)
docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-PLAN-R1.md+67 −0
CI passed — run details
Intent
<task-notification> <task-id>bk8da0u4c</task-id> <tool-use-id>toolu_01QeiegxecmMusWpt5W75Cby</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/1be65f1d-61c8-4308-afb1-2c756edd9c6e/tasks/bk8da0u4c.output</output-file> <status>completed</status> <summary>Background command "Wait for the first Astra plan review to finish" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 11.1 g CO₂e (1,239,996 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on g6-fence, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-PLAN-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-PLAN-R1.md| new file mode 100644 |
| index 000000000..c484667ef |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-PLAN-R1.md |
| @@ -0,0 +1,67 @@ |
| +Reviewed commit `041a7317f9a47ac9076c4d5d08cb043ac1a235f8`, plan review round 1. No files changed, subagents spawned, or full suites run. |
| + |
| +1. **P1 — Tasks 1–2: uncaptured writes before the first sample never enter the queue.** |
| + |
| + [Plan:109](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:109) treats the first WAL observation as a baseline; the fallback at line 137 only handles `L > R`. The app starts before replication ([activator.go:3310](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:3310)), and Litestream initialization contacts storage before completing capture ([db.go:1063](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/db.go:1063)). |
| + |
| + A fresh app can commit before the first sample, then become idle while initialization hangs. `L = R = 0`, the nonempty WAL stays unchanged, and no obligation is created. A direct transcription of the planned algorithm confirmed no trip through 120 simulated seconds. |
| + |
| + **Fix:** Establish an initial obligation for a nonempty WAL whose capture coverage is unproven, while preserving the missing/empty-WAL exceptions. Add this exact witness. **Fault family:** outstanding-write age. |
| + |
| +2. **P1 — Tasks 2 and 4: an earlier lease-loss error disables fence cancellation.** |
| + |
| + [Plan:191](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:191) permits `latchFence` only when `rn.err == nil`; line 217 closes the gate only when that latch succeeds. The watcher at line 331 exits when the original loss is not `ErrReplicaStale`. Renewal failure already permanently latches another error ([health.go:278](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/health.go:278)). |
| + |
| + If renewal fails during the first 30 seconds of a hung upload, ordinary shutdown can block behind `syncMu`. When the write-age limit arrives, the gate remains open and the watcher has exited. Finalization still cannot reach the marker: Litestream’s mutex acquisition ignores the release context ([replica.go:135](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/replica.go:135)). |
| + |
| + **Fix:** Track the write-fence event independently of the renewer’s first error. Trip cancellation and writer termination once even when ownership was already lost. Test renewal loss followed by the fence during blocked finalization. **Fault family:** release cancellation. |
| + |
| +3. **P1 — Task 3: counting `systemctl` calls does not account for queued starts.** |
| + |
| + [Plan:263](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:263) decrements `starting` when `Systemctl` returns. Both command paths use `start --no-block`; the existing code explicitly says this returns when the job is merely queued ([cmd.go:119](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/instancectl/cmd.go:119), [rootfs.go:1119](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/instancectl/rootfs.go:1119)). |
| + |
| + A queued job can therefore remain after `starting == 0`. Both kills can run before its process exists, and the slice can read empty before that job starts a writer. Cancellation of a blocking `systemctl` has the same underlying problem: existing stop code deliberately replaces submitted jobs with stop jobs ([server.go:1179](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/instancectl/server.go:1179)). The claim that in-flight starts die with instance control is also false for manager-owned jobs. |
| + |
| + **Fix:** Account for and cancel or replace queued starts before accepting emptiness. Preserve or reconstruct that protection across control-service restart. Test a queued job whose process appears after the proposed empty proof, including `--no-block` and cancelled-client cases. **Fault family:** writer cessation. |
| + |
| +4. **P1 — Task 3: egress enforcement bypasses the fence through `try-restart`.** |
| + |
| + The proposed AST guard checks only literal `"start"` calls ([plan:279](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:279)). However, egress revocation restarts services in the host slice through [`EgressAsserter.restartRunning`, egress.go:503](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/instancectl/egress.go:503). Its existing admission callback checks sandbox policy, not the host fence ([sandbox.go:104](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/instancectl/sandbox.go:104)). |
| + |
| + An overlapping egress restart can queue another invocation without being refused or counted. `Restart=no` does not prevent an explicit restart. |
| + |
| + **Fix:** Put every operation capable of starting an invocation, including `try-restart`, behind the same host fence and job accounting. Extend the guard and add an egress-revoke/fence interleaving test. **Fault family:** writer cessation. |
| + |
| +5. **P1 — Task 4: the watcher starts after a potentially blocked wake.** |
| + |
| + [Plan:318](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:318) installs the watcher through `installProcLocked`. That happens after `doWake` returns ([activator.go:2326](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:2326)). Replication starts earlier, before files-publisher opening and sidecar startup ([activator.go:3389](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:3389)). Publisher opening can perform a storage GET ([hafiles.go:338](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/hafiles.go:338)). |
| + |
| + While that GET blocks, the app is already running and the lease fence can trip, but no watcher exists to kill its writers. Setting `writeFenced` manually in a test does not exercise this gap. |
| + |
| + **Fix:** Attach fence supervision as soon as the replicator exists, covering the waking entry and failed-wake cleanup without creating a second stop owner. Test a trip while publisher opening remains blocked. **Fault family:** writer cessation. |
| + |
| +6. **P1 — Tasks 3–4: an old fence can kill a newly acquired incarnation.** |
| + |
| + The endpoints carry only a hostname, and `/unfence` simply deletes its mark ([plan:260–267](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:260)). The watcher checks entry identity before releasing `a.mu` and making the RPC; release does not await that RPC ([plan:331](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:331)). Recovery waits for the old stop, not the fence operation ([haleaseloss.go:164](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/haleaseloss.go:164)). |
| + |
| + Pause the old fence before its kill, let ordinary shutdown and release finish, then acquire again and unfence. When the old operation resumes, it can kill the new holder’s processes or leave that holder marked. |
| + |
| + **Fix:** Order fence completion against release/reacquire, and make root reject stale fence operations using an acquisition identity. Serialize unfence with an active fence. Add a deterministic old-fence/new-acquire interleaving test. **Fault family:** incarnation ownership across asynchronous termination. |
| + |
| +7. **P2 — Task 2: coverage-reader instructions contradict the no-frame cases.** |
| + |
| + [Plan:217](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:217) says to read the LTX header, WAL header and trailing frame, returning false on any read error. Task 1 instead requires missing/empty WALs and short trailing frames to resolve ([plan:87–95](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:87)). |
| + |
| + Following the reader instruction literally turns expected absence or EOF into unresolved obligations and can fence an idle, fully replicated database. |
| + |
| + **Fix:** Specify early missing/empty-WAL handling, skip unnecessary trailing reads, and distinguish expected EOF from actual read failure. Exercise the filesystem reader, not only `walCovered`. **Fault family:** coverage proof and idle false positives. |
| + |
| +8. **P2 — Task 5: the tests do not prove the CLI calls the rail.** |
| + |
| + The new test exercises only `replicationHARail`, and the mutation changes its predicate ([plan:383](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/docs/superpowers/plans/2026-11-12-g6-write-fence.md:383)). Existing command tests create a non-HA route ([route_replication_test.go:149](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/route_replication_test.go:149)). Omitting the new call from `runRouteReplication` leaves those tests green. |
| + |
| + **Fix:** Exercise the CLI against an HA route, assert refusal and an unchanged replication column, and mutate away the call. **Fault family:** enforcement-test coverage. |
| + |
| +The outstanding-write-age, writer-cessation and release-cancellation findings recur in families already identified by the plan’s stopping-rule history. They require the stated decision from Paul before another fix cycle. |
| + |
| +**NOT READY** |
| \ No newline at end of file |