carlos / platform Public

G6 fence rev 3.1: apply Fable 5.2 spot check

Root-side start fence for all seven roles, same-run obligations by WAL
offset, 32 s bound, K as writers dead, upload wording, monitor kept off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b6d4107066a91baaa192303845a455c77862615f parent 6c21254
2 files changed, +109 −26
  • docs/superpowers/reviews/FABLE-SPOTCHECK-G6-FENCE.md +43 −0
  • docs/superpowers/specs/2026-11-11-g6-write-fence-design.md +66 −26

CI failed — run details

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="3b8cd443-c809-488b-8357-759b269f8eca"> Agent manager 8a3d302: thanks. Open Paul&apos;s copy review for the 11 draft strings now and send me the link. Run the Fable 5.2 spot check of fence §3.1-3.2 now as well (claude -p --model claude-fable-5-2, read-only) and report its verdict. Hold the build until Paul rules on the three decisions. </paseo-system>

Human

<task-notification> <task-id>b5jnbxlav</task-id> <tool-use-id>toolu_013D8YEHRCR7K9SjUdQTUyj2</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/64640e60-2586-4892-aa4d-d341a15a1881/tasks/b5jnbxlav.output</output-file> <status>completed</status> <summary>Background command "Run Fable 5.2 read-only spot check of fence §3.1-3.2" completed (exit code 0)</summary> </task-notification>

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="2b92e683-c1f5-4a6d-aef5-fc119550b755"> Agent manager 8a3d302: run that one copy-review submit command with the sandbox off. It only talks to the internal review app, and the W6 agent did the same today. Send me the link. </paseo-system>

Human

<task-notification> <task-id>b1lpi5sny</task-id> <tool-use-id>toolu_01VHqzr1tPHG5WbBmBbwYYeT</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/64640e60-2586-4892-aa4d-d341a15a1881/tasks/b1lpi5sny.output</output-file> <status>completed</status> <summary>Background command "Rerun Fable spot check with prompt on stdin" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 12.5 g CO₂e (1,444,205 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-g6, 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/FABLE-SPOTCHECK-G6-FENCE.md b/docs/superpowers/reviews/FABLE-SPOTCHECK-G6-FENCE.md
new file mode 100644
index 000000000..fbb16bf73
--- /dev/null
+++ b/docs/superpowers/reviews/FABLE-SPOTCHECK-G6-FENCE.md
@@ -0,0 +1,43 @@
+**Verdict up front: READY AFTER FIXES** — one P1 (start race), four P2 text/mechanism fixes, two P3. The `Replica.Stop(true)` mechanism and the slice kill are sound against the code. I did not trace every activator start path; finding 1's missing-role list rests on the role list and the stop's `startDone` wait.
+
+**1. P1 — §3.2 step 3: an activator-side `e.fenced` flag cannot stop a start already in flight, and the list misses roles**
+- Evidence: the slice holds roles `run`, `gvisor-run`, `seed`, `sidecar`, `cmd`, `worker`, `tty` (`internal/instancectl/names.go:33-48`, `gen.go:65-69`). The spec names only respawn, sidecar, generation and swap (spec `:149-151`).
+- Spawns run outside `a.mu` (root RPC, then `systemctl start`), so one that passed the check before the latch can land after the slice is proven empty.
+- The unchanged stop then waits for it (`activator.go:4852-4853`) and stops it gracefully on the 20 s budget (`carlos-instance-gen@.service:43-44`). That writer runs well past `K`.
+- Fix: make the kill a root-side fence. The instance-control kill operation marks the host refused under the same lock `/start` takes, every role's start checks it, and it clears at the next acquire. Keep `e.fenced` as the fast path, list all seven roles, and add a test where a start is sent before the latch and lands after the kill.
+
+**2. P2 — §3.1 obligation queue: a same-run "W changed and L advanced" can clear a commit early**
+- Evidence: spec `:79-82` assigns `txid = L` to obligations appended in the same run. A write that lands after the capture but before the sample gets a TXID that does not contain it, and is removed when `R ≥ L`.
+- It is re-added only by the next capture, via the empty-queue rule with `t = now`, or by the next write. If capture then stalls (`db.go:2696-2715` backoff) with no further writes, the commit's age is lost. This is the G6-2.1 family in a narrow window.
+- Fix: assign a TXID only from an `L` advance seen in a strictly later run. To avoid a false trip when idle, resolve same-run obligations by WAL offset from the newest L0 header (`DB.Pos` already opens that file, `db.go:574-587`). Otherwise state the residual in the text. Add a witness for a write between capture and sample followed by a capture stall.
+
+**3. P2 — §3.1/§4/§5: the bound is 32 s plus K, not 31 s**
+- Evidence: `t` is stamped up to 1 s after the write (spec `:88-89`), and the trip needs `now − t > 30` on a 1 s tick, so it fires up to 31 s after `t`. A write at 0.01 s is sampled at 1.0 s and trips at 32.0 s.
+- The exit test's "committed between 31 s before the fence line" (spec `:252`) can fail on a correct build.
+- Fix: say 32 s in §3.1, §4 and the exit test, or trip at `≥ 29 s`.
+
+**4. P2 — §3.2 `K`: the "slice empty" return includes `ExecStopPost`, and the fake-backed `K < 2 s` test proves nothing**
+- Evidence: every unit in the slice runs `ExecStopPost=carlos instance-exit …` after the kill, in the same cgroup (`carlos-instance-gen@.service:38`, and the rootfs units likewise). The slice is populated again until those finish.
+- Real `K` is `a.mu` wait, plus the root RPC, plus systemd, plus `ExecStopPost`. Only the drill measures it.
+- Units are `Restart=no` (`:42`), so systemd does not respawn them; that part of the design holds.
+- Fix: define `K` as latch to main processes dead (writers gone) and report slice-empty separately. Drop the unit-test bound or call it a wiring test. Treat a drill `K` over 2 s as a fail.
+
+**5. P2 — §3.1: "uploads after the latch can only come from that bounded final attempt" is false, though nothing follows the marker**
+- Evidence: `Replica.Stop` stops only the replica monitor (`replica.go:118-130`). The store's compaction and snapshot monitors keep uploading until `store.Close` (`internal/lease/lease.go:459-461`, `release.go:252`).
+- `DB.Close` makes a second replica attempt through `syncReplicaWithRetry` (`db.go:786-790`).
+- All of it is inside `finalize`, so the invariant holds.
+- Fix: reword to "every upload after the latch runs inside the one finalization, before the marker", and name the three sources.
+
+**6. P3 — §3.1: a late `DB.init` can restart the monitor after the fence stopped it**
+- Evidence: `init` calls `Replica.Start(db.ctx)` (`db.go:1077`), and it can first succeed inside finalize's `SyncAndWait`. The restarted monitor can take `syncMu` on `db.ctx` and hang again.
+- Fix: set `Replica.MonitorEnabled = false` at the latch before `Stop`; `Start` then returns without starting anything (`replica.go:96-98`).
+
+**7. P3 — §3.1: no deadlock found in the stop path; record why**
+- `Stop(true)` only cancels and joins: `r.f` is never assigned in v0.5.14 (the only reference is `replica.go:124-125`), so the hard flag closes nothing.
+- The monitor exits on context at every wait and passes it to `Sync` (`replica.go:340-378`).
+- The fence goroutine holds none of `rn.mu`, `finMu` or `syncMu` while waiting. `DB.Close` calling `Stop(true)` again is harmless (`db.go:791`).
+- `DB.Pos` takes only its own cache lock (`db.go:559-561`), so a hung capture cannot block the check.
+- One finalization owner holds (`release.go:225-231`).
+- Fix: none to the mechanism. Add a line that the fence goroutine must be joined outside `finMu`, or not joined by `finalize` at all.
+
+READY AFTER FIXES
diff --git a/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md b/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md
index eaa9fb274..48a3d20c9 100644
--- a/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md
+++ b/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md
@@ -1,4 +1,4 @@
-# G6 slice 2: the minimal write fence (F-C) (design, rev 3, 2026-11-11)
+# G6 slice 2: the minimal write fence (F-C) (design, rev 3.1, 2026-11-11)
Design only. Paul approves before any build. Parent: region HA spec
`2026-10-26-region-ha-without-claims-design.md` (**RHA §n**). Evidence:
@@ -8,6 +8,8 @@ Line citations are to `origin/main` at 01d6ca78.
Rev 2 answers Astra round 1 (`docs/superpowers/reviews/CODEX-FINDINGS-G6-R1.md`): the trip condition now tracks the oldest outstanding capture and WAL changes litestream has not captured (G6-1.1, G6-1.2); a fenced holder kills its writers at once instead of draining (G6-1.5); the stop is started only from awake and the watcher ends with the replicator (G6-1.4); a fenced release cancels and joins replication before its marker (G6-1.3).
+**Rev 3.1** applies the Fable 5.2 spot check of §3.1-3.2 (`docs/superpowers/reviews/FABLE-SPOTCHECK-G6-FENCE.md`, READY AFTER FIXES): a root-side start fence (F1), same-run obligations resolved by WAL offset (F2), the 32 s bound (F3), `K` defined as writers dead (F4), the upload wording (F5), the monitor kept off after the latch (F6), and the join rule (F7).
+
**Rev 3 (not reviewed; the two-round budget is spent)** answers Astra round 2 (`CODEX-FINDINGS-G6-R2.md`): an obligation queue keeps the oldest unresolved write's age through later writes and captures (G6-2.1); the fence kills the host's systemd slice through the root path, not the exec cgroup (G6-2.2); replication is stopped at the latch, outside `finMu`, and the kill runs from the watcher, so no blocked stop has to notice anything (G6-2.3); the bound now includes the latch-to-kill interval and makes no zero-acknowledgement claim (G6-2.4). The same three families drew findings in both rounds (stopping rule 2); §8 puts the choice to Paul.
**Paul's ruling (2026-11-11, via 8a3d302, approving Fable 5.2 §3 decision 2):**
@@ -77,20 +79,32 @@ second** until the replicator closes. Each run reads only memory and one
**The obligation queue** (G6-2.1). Each run that finds `W` changed since the
previous run appends an obligation `{t: now, txid: unknown}`. Each run that
-finds `L` advanced assigns `txid = L` to every obligation still unknown
-(frames that changed the WAL before this capture are in transactions up to
-`L`). Obligations are removed from the front only when `R ≥ txid`. A run that
+finds `L` advanced assigns `txid = L` to every obligation still unknown from
+**earlier** runs (frames that changed the WAL before this capture are in
+transactions up to `L`). An obligation appended in the **same** run as an `L`
+advance may hold a write made after that capture (Fable F2), so it gets
+`txid = L` only if the WAL size the `stat` saw is within the WAL range the
+newest L0 LTX file records (litestream reads that file's header for
+`DB.Pos`, `db.go:574-587`; the build confirms the header's WAL offset and
+size fields). Otherwise it waits for a later `L` advance. If the header does
+not carry the range, the build states the residual instead: a write in that
+same-run window followed by a capture stall with no further writes is not
+fenced. Obligations are removed from the front only when `R ≥ txid`. A run that
finds `L > R` with the queue empty (captured before the first sample) appends
`{t: now, txid: L}`. A failed `stat` appends an obligation as if `W` changed.
The oldest obligation's `t` is therefore never reset by later writes, by a
late capture, or by a slow upload: it goes only when replication proves its
transaction is in the store. A commit not in the store changed the WAL no
-later than the run after it, so it is no older than `now − t_oldest + 1 s`.
+later than the run after it, so it is no older than `now − t_oldest + 1 s`. With the 1 s tick the trip fires up
+to 31 s after `t_oldest`, so the oldest lost write is at most **32 s** old at
+the fence line (Fable F3).
**Trip:** if the queue is non-empty and `now − t_oldest > 30 s`: under
`rn.mu`, `loseLocked(ErrReplicaStale)`, then (outside `rn.mu` and outside
-`finMu`) `Replica.Stop(true)` (litestream `replica.go:118-130`), which cancels
+`finMu`) set `Replica.MonitorEnabled = false`, so a late `DB.init` cannot
+restart the monitor (`db.go:1077`, `replica.go:96-98`; Fable F6), and call
+`Replica.Stop(true)` (litestream `replica.go:118-130`), which cancels
the monitor's context, aborts an in-flight upload and joins the monitor
goroutine. Log once:
`lease: <path>: a write has waited <age> to reach storage (local <L>, stored <R>); standing down (write fence)`.
@@ -102,8 +116,18 @@ litestream `replica.go:134-136`) gets `syncMu` once the monitor's sync
returns, makes its own attempt under its own release budget, fails while the
store is down, and writes `clean: false` because `finishErr` includes
`rn.Err()` (`release.go:254`). No second finalizer exists, so there is one
-finalization owner, as today. Uploads after the latch can only come from that
-bounded final attempt, which runs before the marker, never after it.
+finalization owner, as today. Every upload after the latch runs inside that one finalization, before the
+marker (Fable F5): the final `SyncAndWait` attempt, the store's compaction
+and snapshot monitors until `store.Close` (`lease.go:459-461`,
+`release.go:252`), and `DB.Close`'s `syncReplicaWithRetry`
+(`db.go:786-790`). None follows the marker.
+
+No deadlock (Fable F7): `Stop(true)` only cancels and joins (`r.f` is never
+assigned in v0.5.14); the monitor exits on its context at every wait
+(`replica.go:340-378`); the fence goroutine holds none of `rn.mu`, `finMu`
+or `syncMu` while waiting, and `finalize` never joins it (it ends with the
+replicator's `Done()`); `DB.Pos` takes only its own cache lock
+(`db.go:559-561`), so a hung capture cannot block the check.
An idle instance has an empty queue, so it is never fenced; its lease renewal
handles an outage as today. A hung upload never raises `R`, so it trips like
@@ -146,15 +170,24 @@ stop's progress:
slice's cgroup is empty, the same proof `haHostEmpty` already reads
(`harelease.go:50-72`). The build adds this as one instance-control
operation beside the existing slice reads (`instancectl/size.go`).
-3. **No restarts.** While `e.fenced` is set, every start path for the entry
- (respawn, sidecar start, generation start, swap) refuses, so a start that
- races the kill cannot bring a writer back. The stop goroutine itself is
- unchanged: its waits end because the processes are gone and replication is
- stopped, and it then releases through the normal path (§3.1).
-
-The cessation bound is the latch-to-empty-slice interval, `K`. It is measured,
-not assumed: the unit test asserts `K < 2 s` with a fake instance control, and
-the drill records it.
+3. **No restarts, enforced by root** (Fable F1). Spawns run outside `a.mu`
+ (a root RPC, then `systemctl start`), so an activator flag cannot stop a
+ start already in flight. The instance-control kill operation therefore
+ first marks the host **fenced** under the same lock its `/start` takes,
+ then kills. Every role's start in the slice refuses while the mark is set:
+ `run`, `gvisor-run`, `seed`, `sidecar`, `cmd`, `worker`, `tty`
+ (`internal/instancectl/names.go:33-48`, `gen.go:65-69`). The mark clears at
+ the host's next lease acquire. `e.fenced` in the activator stays as the
+ fast path. Units are `Restart=no` (`carlos-instance-gen@.service:42`), so
+ systemd does not respawn them. The stop goroutine itself is unchanged: its
+ waits end because the processes are gone and replication is stopped, and
+ it then releases through the normal path (§3.1).
+
+`K` is the time from the fence line to every main process in the slice being
+dead, that is, writers gone (Fable F4). Slice-empty comes later, after each
+unit's `ExecStopPost=carlos instance-exit` (`carlos-instance-gen@.service:38`),
+and is reported separately. Only the drill measures `K`; a drill `K` over 2 s
+is a fail. The unit test with a fake instance control is a wiring test.
### 3.3 Only the stream class in an HA pool (cli.go, registry)
@@ -181,10 +214,10 @@ For a stream instance on an HA box:
| Event | Before | After |
|---|---|---|
| Box dies | about 1 s of writes lost (RHA §5.3) | unchanged |
-| Box loses the store, with writes arriving | every write acknowledged until the next renewal fails: 0 to about 5 min | at most the writes committed from about 31 s before the fence line to the moment the slice is empty (`K`, about 2 s); new requests get 503 with `Retry-After: 10` from the fence line; a request admitted before it may still be acknowledged until its process dies |
+| Box loses the store, with writes arriving | every write acknowledged until the next renewal fails: 0 to about 5 min | at most the writes committed from 32 s before the fence line to the moment the slice is empty (`K`, about 2 s); new requests get 503 with `Retry-After: 10` from the fence line; a request admitted before it may still be acknowledged until its process dies |
| Box loses the store, idle | nothing lost; lease renewal handles it | unchanged |
| Store outage shorter than 30 s | nothing lost | unchanged |
-| Store outage longer than 30 s, with writes, no renewal inside it | nothing lost: the sync catches up when the store returns | **the instance is killed, and the unsynced tail (about 31 s + `K`) is lost** when the unclean marker lands and the instance restores from the store; the local copy is set aside as `<db>.stale` (RHA §5.3), so an operator can still recover it by hand |
+| Store outage longer than 30 s, with writes, no renewal inside it | nothing lost: the sync catches up when the store returns | **the instance is killed, and the unsynced tail (32 s + `K`) is lost** when the unclean marker lands and the instance restores from the store; the local copy is set aside as `<db>.stale` (RHA §5.3), so an operator can still recover it by hand |
The last row is the price Paul's ruling accepts: a bounded loss in place of an
unbounded one. Without the late flush (deferred), a fenced holder cannot hand
@@ -232,12 +265,16 @@ Unit (no AWS, run under `-run`), with the seam clock:
- an ordinary stop already blocked in each of its waits (start-done, op
join, process drain) when the fence trips: the kill still runs, the stop
completes, no second stop starts (G6-2.3);
- - the kill targets `SliceName(host)` with the exec cgroup absent, and a
- respawn racing it is refused (G6-2.2);
+ - the kill targets `SliceName(host)` with the exec cgroup absent (G6-2.2);
+ - **start in flight** (Fable F1): a start sent before the latch that
+ reaches instance control after the fence mark is refused, for each of the
+ seven roles; the mark clears at the next acquire;
+ - **same-run write** (Fable F2): a write between a capture and the sample,
+ then a capture stall with no further writes, still trips;
- a clean hibernation ends the watcher (no goroutine left, no stop);
- - **latch-to-kill** (G6-2.4): an in-flight write request and a worker
- writing every 100 ms both stop within `K < 2 s` of the latch; new requests
- after the latch get 503.
+ - **latch-to-kill** (G6-2.4, wiring only): an in-flight write request and a
+ worker writing every 100 ms are killed after the latch; new requests after
+ the latch get 503.
- `cli`: the rail refuses `batched` and `daily` on an HA route and allows them
on a non-HA route.
@@ -249,8 +286,9 @@ entries:
2. **Pass:** the fence line appears between t0+30 s and t0+35 s; from it every
request started after it gets 503 with `Retry-After: 10`, with no hangs;
acknowledged and lost writes (probe acks against `/ranges`) were all
- committed between 31 s before the fence line and the slice-empty line, and
- number at most 35 (was 131); `K` (fence line to slice empty) is under 2 s; after the fault ends the unclean marker lands and the fixture serves
+ committed between 32 s before the fence line and the writers-dead line, and
+ number at most 36 (was 131); `K` (fence line to writers dead) is under 2 s;
+ slice-empty is recorded; after the fault ends the unclean marker lands and the fixture serves
again within the bound of RHA §9.8; no other box takes the lease before the
marker or a terminate; the F-A, F-B and F-D rows of the rerun still pass.
3. Two controls in the same window: a 20 s cut with writes (no fence, 0 lost)
@@ -283,3 +321,5 @@ findings in both Astra rounds. Rev 3 answers round 2 but is unreviewed. Options:
2. **Cut the precision:** keep §3 but state the bound only as measured by the
drill, not derived, and drop the capture-stall half (a stalled capture is
a local-disk fault, not the S3 loss F-C was about).
+
+**2026-11-11 (8a3d302):** option 1 taken. Fable 5.2 spot check: READY AFTER FIXES (1 P1, 4 P2, 2 P3); all applied in rev 3.1. The build still waits for Paul's rulings.