reviews: G6 fence branch round 1 (Astra NOT READY, Fable after fixes)
docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-BRANCH-R1.md+57 −0docs/superpowers/reviews/FABLE-FINDINGS-G6-FENCE-BRANCH-R1.md+98 −0
CI failed — run details
Intent
<task-notification> <task-id>b1v8n92ap</task-id> <tool-use-id>toolu_01YGdEWQmESqCLB1CgN3gB5E</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/1be65f1d-61c8-4308-afb1-2c756edd9c6e/tasks/b1v8n92ap.output</output-file> <status>completed</status> <summary>Background command "Wait for both fence branch reviews" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 30.9 g CO₂e (3,767,274 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-BRANCH-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-BRANCH-R1.md| new file mode 100644 |
| index 000000000..e3dc16d5c |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-FINDINGS-G6-FENCE-BRANCH-R1.md |
| @@ -0,0 +1,57 @@ |
| +Reviewed tip `62e87bde8f3ea65c731f30dc41b8c3e6fb04c227`. The supplied diff matches the implementation diff exactly; the subsequent commit adds only the brief. |
| + |
| +1. **P1 — A fence can race finalization and publish a clean or finalized marker.** |
| + |
| + **Evidence:** [fencerun.go:50](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fencerun.go:50) checks `Done()` separately from `tripFence`. The latter closes `Fenced()` before latching the renewer’s error, at lines 97–106. Meanwhile, [release.go:281](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/release.go:281) caches `finishErr` from `rn.Err()` once. Subsequent finalizations return that cached answer; `ReleaseMarker` clears `Clean` and `Finalized` only when that answer is non-nil. |
| + |
| + **Failure scenario:** During an ordinary release, the fence samples an overdue obligation and passes its `Done()` check. Storage recovers and finalization caches a successful result. The fence then fires before finalization returns, or before the marker is written. Its later error cannot change the cached result. `releaseHAClean` can consequently supply `Clean: true` or `Finalized: true`, and [MarkerOpensAt:58](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/hafresh/lock.go:58) permits immediate takeover, bypassing the required lease-term wait. |
| + |
| + **Fix:** Serialize fence publication with finalization’s terminal decision using a short, separate state lock. A fence that wins must permanently poison finalization and clear both marker flags; completed finalization must prevent a later fence. Do not hold that lock across I/O or use `finMu` to block cancellation. Add deterministic tests for both orderings. |
| + |
| + **Fault family:** release classification and successor storage exclusion. |
| + |
| +2. **P2 — Finalization’s deadline does not bound its wait behind a hung monitor upload.** |
| + |
| + **Evidence:** [release.go:264](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/release.go:264) calls Litestream `SyncAndWait`. Litestream’s [Replica.Sync:134](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/replica.go:134) acquires `syncMu` without observing the caller’s context. The monitor upload’s gate context is cancelled by the fence, not by the waiting finalization’s deadline. |
| + |
| + **Failure scenario:** Start a five-second release immediately after an upload hangs. The release deadline expires while waiting for `syncMu`; it cannot reach a marker or owed release until the roughly 31-second fence trips. The new [test:580](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fence_test.go:580) advances 31 seconds of fence time rapidly and waits eight seconds **after the trip**, so it does not establish the claimed release budget. |
| + |
| + **Fix:** When finalization takes ownership, cancel outstanding non-finalization replica work independently of the fence timer, while preserving its own permitted sync and the join-before-marker ordering. Test an actual release deadline without advancing fence time past it. |
| + |
| + **Fault family:** release cancellation and bounded finalization. |
| + |
| +3. **P2 — A cancelled wake forgets the fence’s refusal after cleanup.** |
| + |
| + **Evidence:** [haleaseloss.go:97](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/haleaseloss.go:97) refuses a marked waking entry without latching HA loss. [activator.go:2286](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:2286) wraps the error for existing waiters, then deletes the entry at line 2299. |
| + |
| + **Failure scenario:** After fenced-wake cleanup finishes, another request starts an ordinary wake while storage remains unavailable. It can wait up to `wakeWaitBound` and receive the ordinary timeout response—`Retry-After: 5`, without the required holder header—instead of the immediate HA refusal. This confirms the deferred Task 3 minor. |
| + |
| + **Fix:** Preserve a host-level HA-loss refusal across failed-wake removal. Keep cleanup as the sole stop owner, and clear the refusal only through successful recovery. Add a request after cleanup to the blocked-publisher test. |
| + |
| + **Fault family:** persistent admission refusal during recovery. |
| + |
| +No P3 findings. The other deferred minors need no merge fix: Task 1’s regression tests are present; I found no concrete concurrent `markerPutHook` access in the current serial test path; refusing an invalid dry run follows the existing rail ordering. The copy placeholder and accepted non-stream import paths remain outside these findings. |
| + |
| +Census approvals concern root-read authority, separately from the functional defects above. The new filesystem reads remain on the agent’s existing database and Litestream paths; the changes add no root execution or input authority. |
| + |
| +| Unit or envelope | Verdict | Lines read | |
| +|---|---|---| |
| +| `Service.doWakeOnce` | Approve | [activator.go:3421–3453](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:3421) | |
| +| `Service.installProcLocked` | Approve | [activator.go:3586–3607](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:3586) | |
| +| `Service.wake` | Approve | [activator.go:2206–2211](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:2206), 2277–2300, 2352–2403 | |
| +| `type Service` | Approve | [activator.go:1715–1728](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/activator.go:1715) | |
| +| `Service.haLeaseRefusalLocked` | Approve | [haleaseloss.go:95–135](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/haleaseloss.go:95) | |
| +| `Held.Replicate` | Approve | [lease.go:417–456](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/lease.go:417) | |
| +| `runRouteReplication` | Approve | [cli.go:2060–2085](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/cli.go:2060) | |
| +| `replicationHARail` — new legacy disposition | Approve | [cli.go:2120–2133](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/cli.go:2120) | |
| +| `Replicator.fenceSample` — new legacy disposition | Approve | [fencerun.go:73–88](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fencerun.go:73) | |
| +| `Replicator.newestL0Header` — new legacy disposition | Approve | [fencerun.go:163–182](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fencerun.go:163) | |
| +| `readAtMost` — new legacy disposition | Approve | [fencerun.go:152–159](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fencerun.go:152) | |
| +| `readCoverage` — new legacy disposition | Approve | [fencerun.go:124–149](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fencerun.go:124) | |
| +| Envelope `.` | Approve | `cli.go` ranges above; [route_replication_test.go:336–425](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/route_replication_test.go:336) | |
| +| Envelope `internal/activator` | Approve | Ranges above; [writefence.go:1–105](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/activator/writefence.go:1), `stateless.go:259–274`, `swapadmit.go:80–105`, `writefence_test.go:1–802` | |
| +| Envelope `internal/lease` | Approve | Ranges above; [fence.go:1–177](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/g6-fence/internal/lease/fence.go:1), `fencegate.go:1–168`, `fencerun.go:1–182`, `lease.go:539–570,620–666`, `release.go:88–109,252–339`; all added fence tests and test exports | |
| + |
| +`git diff --check` and formatting checks passed. Targeted tests could not start because the read-only sandbox prevented Go from creating its build directory; no runtime or census-test pass is claimed. No files were changed, subagents spawned, or full suites run. |
| + |
| +**NOT READY** |
| \ No newline at end of file |
diff --git a/docs/superpowers/reviews/FABLE-FINDINGS-G6-FENCE-BRANCH-R1.md b/docs/superpowers/reviews/FABLE-FINDINGS-G6-FENCE-BRANCH-R1.md| new file mode 100644 |
| index 000000000..e908b115d |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/FABLE-FINDINGS-G6-FENCE-BRANCH-R1.md |
| @@ -0,0 +1,98 @@ |
| +# G6 write fence branch review, round 1 (Fable 5.2), tip 62e87bde |
| + |
| +**Verdict: READY AFTER FIXES.** No P1. Four P2s, all in the fence algorithm's fit with litestream v0.5.14: release and storage safety, termination, admission, the rail and the merge all hold as specified. |
| + |
| +Checked by reading code, not by running it, except: |
| +- `go vet ./internal/lease ./internal/activator` is clean. |
| +- `go test ./internal/lease -run 'TestFenceQueue|TestWalCovered|TestReadCoverage|TestFenceGate'` passes. |
| +- I could **not** run the root package build, `TestPlan14RootReadCensus` or `TestReplicationHARail`: the sandbox's Go cache is read-only and the sandbox-off run was refused. CI must show those. |
| + |
| +## P2 |
| + |
| +**P2-1. A store outage well under 30 s fences a writing instance.** |
| +- **Where:** `internal/lease/fence.go:21` (`fenceLimit`), `fencerun.go:38-70`; spec §4 line 410, §5 line 552. |
| +- **Problem:** the fence assumes litestream retries about every second. It does not. |
| +- **Evidence:** `Replica.monitor` (litestream `replica.go:327-394`) waits one tick plus a doubling backoff (1, 2, 4, 8, 16 s) after each failed sync that is not a context error. The platform leaves `SyncInterval` at 1 s (`lease.go:480-482`). The fence never asks for a sync itself. |
| +- **Failure scenario:** S3 answers 5xx (or refuses, or DNS fails) from t=0 to t=20 with a write at t=0. Attempts fall at about 0, 2, 5, 10 and 19 s, all failing; the next is at about 31-36 s. The fence trips at tick 31. Every writing HA stream instance goes 503 for at least 15 minutes after a 20 s blip. The drill's "20 s cut with writes (no fence)" control should fail under fast-failing faults. |
| +- **Test gap:** `TestWriteFenceShortOutageNoTrip` (`fence_test.go:516-533`) calls `SyncAndWait` itself each step, with litestream's monitor parked at 1 h (`:161`), so it cannot see this. |
| +- **Fix (recommended):** while the queue is non-empty and the oldest obligation is past about 5 s, have `runFence` start a non-overlapping `r.db.Replica.Sync` each tick under a gate-admitted, non-finalization context. Add a real-monitor test. This is new production-storage behaviour, so the fix needs its own check under the stopping rules. |
| +- **Fix (cheaper):** state the real tolerance (about 15 s of failed requests) in §4, §6 and RHA §5.5, and cut the drill control to 10 s. |
| +- **Fault family:** the outstanding-write age depends on a retry schedule the fence does not own. |
| + |
| +**P2-2. An idle instance is fenced by litestream's own deferred checkpoint write.** |
| +- **Where:** spec §3.1 line 246 ("an idle instance has an empty queue"), §4 line 409, §5 line 553. |
| +- **Evidence:** `checkpointIfNeeded` (litestream `db.go:1318-1343`) runs a passive checkpoint once the database file is 1 minute old, if anything was synced since the last one. `checkpointWithExecutor` then writes `_litestream_seq` into the WAL (`db.go:2231`) and captures it. `newStore` leaves `CheckpointInterval` at its 1-minute default (`lease.go:460-469`). |
| +- **Failure scenario:** the last tenant write is at T and is stored. The store goes out at T+20. At up to T+60 litestream writes its bookkeeping frame, the WAL changes and L advances. Thirty-one seconds later the fence trips with nothing of the tenant's unsynced. The drill's "2-minute cut with the fixture idle" control fails if the fixture was written in the minute before the cut. |
| +- **Test gap:** `TestWriteFenceIdleNeverTrips` runs with the monitor at 1 h, so no checkpoint ever happens. |
| +- **Fix:** state it as residual (d) in the spec and at `fence.go`, and make the drill's idle control idle for more than 90 s before the cut. Alternatively set `db.CheckpointInterval = 0` on armed replicators, which is also a storage change needing its own check. |
| +- **Fault family:** idle never trips. |
| + |
| +**P2-3. A write transaction that spills and runs longer than 30 s is fenced on a healthy store.** |
| +- **Where:** `fence.go:169-173`; spec residual (b), line 255, covers only the rolled-back case. |
| +- **Evidence:** spilled frames carry the current salts and sit past the captured end, so `walCovered` answers not covered. Litestream captures only committed frames (`db.go:1889-1896`), so L does not move until the commit. |
| +- **Failure scenario:** a migration, bulk import or VACUUM in one transaction dirties more than the page cache and commits after 31 s or more. The fence trips mid-transaction, the instance stops and is out for 15 minutes, and every retry does the same. |
| +- **Fix:** at minimum state it beside residual (b) and in §6. A real fix scans frame headers past the captured end for a commit frame (non-zero commit size at bytes 4..7) and counts the WAL as covered when there is none. That also removes residual (b). |
| +- **Fault family:** spurious trip outside the stated residuals. |
| + |
| +**P2-4. An obligation can be discharged at TXID 0 without proof.** |
| +- **Where:** `fencerun.go:48-50` and `:74-76`, `fence.go:153-155`, `fence.go:120-122`. |
| +- **Evidence:** when `db.Pos()` fails, `s.L` is 0 and `lOK` is false, but `readCoverage` is still handed `s.L`. A missing or frameless WAL then answers "covered at 0", and `q.r >= 0` drops every unknown obligation. |
| +- **Failure scenario:** an unknown obligation is waiting, `DB.Pos` errors (an unreadable metadata directory or LTX file), and the WAL is frameless on the same tick. This is rare, but it is the proof rule the brief names. |
| +- **Fix:** in `step`, do not call `covered` when `!s.lOK` (or have the closure answer `(0, false)`). Add a queue test. |
| +- **Fault family:** discharge without proof. |
| + |
| +## P3 (follow-up list) |
| + |
| +- Spec §3.1 says `Done()` closes "after the marker". `finalize` closes it on return, before the marker PUT (`release.go:256`). This is harmless. |
| +- Residual (c) is wider than worded: the `L > R` arm (`fence.go:123`) also trips a wake whose first sync fails for 30 s with no WAL frames, because `Replica.Pos` is zero until the first sync. |
| +- `finishRecoveryProbe` (`recoveryprobe.go:227-238`) goes awake without reading `e.writeFenced`. An event between `doClaimWake` returning and that lock leaves the entry awake until the next request stops it. This is the claims path only. |
| +- A trip that lands exactly as a clean finalization ends marks a stopping entry, and the next request latches an HA loss over a clean marker (`haleaseloss.go:107`). It heals itself and needs an unlikely race. |
| +- `provision/reconcile.go:1068-1071` marks an existing row HA whatever its class. This is a third door beside the two accepted ones; add it to §3.3 or refuse it in slice 3. |
| + |
| +## Deferred minors: none must be fixed before merge |
| + |
| +- **Task 1:** folded in; both tests exist. |
| +- **Task 2** (`markerPutHook` race): test-only, same pattern as `finalSyncHook`. Follow-up. |
| +- **Task 3** (no HA loss latched after a fence-cancelled wake): same behaviour as main for a wake that fails with the store out. Latching there is not a one-liner, because `l.old.stopped` is nil for a waking entry. Follow-up. |
| +- **Task 4** (`--dry-run` refused too): correct as built; note it in the spec. |
| + |
| +## Checks that hold |
| + |
| +- **Release and storage:** |
| + - The gate wraps the client before `DB.Open` hands it to the compactor (litestream `db.go:748`), and the replica monitor runs on `db.ctx`, not the finalization's (`db.go:1077`). |
| + - Tagged calls pass and are bounded only by their own context. |
| + - `DB.Close` and `Store.Close` join every monitor inside `finalize`, so nothing is sent after the marker. |
| + - `finishErr` joins `rn.Err()`, and `ReleaseMarker` forces `Settled` false and clears `Clean` and `Finalized` (`release.go:312-318`), so `MarkerOpensAt` waits the lease term. |
| +- **Termination:** every `beginStopLocked` is under `a.mu` with a state check. The watcher only cancels a waking entry. `wake` reads `writeFenced` before `e.ready` closes (`activator.go:2382`). The seams have no production assignment. |
| +- **Rail:** `cli.go:2063-2065` and `:2125-2130` only add a refusal. |
| +- **Merge:** the diff against main deletes no line of main's unclean-marker or files-only logic. |
| + |
| +## Census |
| + |
| +I am the same model family as the author (Opus 5.5), so AGENTS.md needs Astra's verdict as the one of record; mine is a second read. I did not run the census test, so the seal is unverified here. |
| + |
| +| Unit or envelope | Verdict | Lines read | |
| +|---|---|---| |
| +| `activator.go` `Service.doWakeOnce` | approve | 3419-3442 | |
| +| `activator.go` `Service.installProcLocked` | approve | 3586-3599 | |
| +| `activator.go` `Service.wake` | approve | 2150-2211, 2277-2296, 2372-2392 | |
| +| `activator.go` `type Service` | approve | 1708-1727 | |
| +| `haleaseloss.go` `Service.haLeaseRefusalLocked` | approve | 95-136 | |
| +| `lease.go` `Held.Replicate` | approve | 421-456 | |
| +| `cli.go` `runRouteReplication` | approve | 2060-2080 | |
| +| new `cli.go` `replicationHARail` | approve | 2119-2132 | |
| +| new `fencerun.go` `Replicator.fenceSample` | approve | 72-90 | |
| +| new `fencerun.go` `Replicator.newestL0Header` | approve | 160-182 | |
| +| new `fencerun.go` `readAtMost` | approve | 148-157 | |
| +| new `fencerun.go` `readCoverage` | approve | 118-146 | |
| +| envelope `.` | approve | the two `cli.go` hunks | |
| +| envelope `internal/activator` | approve | `writefence.go` whole; `stateless.go` 260-275; `swapadmit.go` 89-104; the hunks above | |
| +| envelope `internal/lease` | approve | `fence.go`, `fencerun.go`, `fencegate.go` whole; `lease.go` 431-456, 534-560, 620-650; `release.go` 84-109, 252-290 | |
| + |
| +Basis for the approvals: |
| +- Nothing new runs as root. The fence runs in the agent as `carlos` (`carlos-edge.service`, `User=carlos`). |
| +- The new reads are the instance's own `-wal` and litestream's own L0 file, which litestream already opens in the same process. They are app-writable, but what is read only decides that instance's own fence. |
| +- Every other change only refuses or stops more. |
| +- `legacy`, `accepted-legacy` is what `census-propose` writes for a new unit, and it fits these reads. |
| + |
| +No files were edited and no subagents were used. |