carlos / platform Public

lease: arm the early-refusal fake after the store opens (#810)

TestDrainReleaseSnapshotEarlyRefusalReleasesTheWAL failed twice on main
(63706d9c): the WAL stayed open for over 60 s, held by a litestream
SnapshotReader goroutine blocked writing to a pipe nobody read. It was
not the drain release's snapshot but the store monitor's Open-time one:
the fake refused every level-9 write from the start, and litestream's
DB.Snapshot leaves its reader (and the WAL) open when the upload fails
and the client does not close the body. Arming the refusal after the
store has opened, as the sibling failure test already does, leaves only
the drain's own snapshot refused. #802 is not the cause: with its
quietStoreLogs call reverted the test still failed 3 of 6 batches.
50 runs pass after the fix; the drain release itself frees the WAL in
about 1.5 ms (measured).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1e4d3978a30ed8bf95b7a59395213ad1223d9972 parent 63706d9
1 file changed, +9 −1
  • internal/lease/release_snapshot_test.go +9 −1

CI failed — run details

Intent

Human

<task-notification> <task-id>aaac076393ec2af43</task-id> <tool-use-id>toolu_013ioT4Pjg7KmgA8x32Cqe78</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a99cbe46-f458-4f72-8b8a-294aae9cdf21/tasks/aaac076393ec2af43.output</output-file> <status>completed</status> <summary>Agent "Build held-floor-capability" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Both changes are in as new commits, and the WAL-wait test change is reverted. Tests, mutations and census all pass. Nothing was pushed or amended. **Commits (newest first)** - **7b61a0c9** census: re-propose held-floor-capability for the signed drain answer (seal `837f27a6…` to `fa9aea00…`) - **75ff7187** lease: drop the WAL-wait change, it lands on its own branch. It reverts 802f9264, which I had already committed; `internal/lease/release_snapshot_test.go` now matches its earlier content. - **4976e386** grouproll: declare no fixed boxes explicitly with no_fixed_boxes - **45992c2e** region HA: drain acknowledgements are signed for the ask **(1) Signed acknowledgement answer** (`internal/edge/hadrain.go`) - The asker now puts a fresh nonce in each ask: 16 bytes from `crypto/rand`, as lower-case hex, inside the body the ask's existing signature already covers. - The receiver refuses an ask without a valid 32-hex-digit nonce with a bare 404. - The answer is now `{"seen":&lt;bool&gt;,"sig":"&lt;hex&gt;"}`. `sig` is an HMAC-SHA256 under the mesh key (the same signing key the ask uses) over these parts, each followed by a newline: 1. the domain string `carlos-ha-drain-answer\x00` 2. the receiver 3. the asker 4. the transaction 5. the phase (one part more than the ruling listed) 6. the drain id 7. the nonce 8. the seen value - The asker verifies the answer under either mirrored key, in constant time. It counts anything else as not acknowledged and returns an error, never a seen value. That covers an unsigned body, a missing `seen`, a bad signature, an answer to another ask, a 404, and an HTML page. - There is no compatibility path. Bounds and retries are unchanged. - Spec §24 E12 and E15 and §25.4 step 1 are reworded to say this. Tests: - `TestHADrainAnswerMustBeSignedForTheAsk`: - A correct signed answer is accepted. - On a peer acting as an old binary, a tenant answer of `{"seen":true}` is refused, along with an empty or zeroed `sig`, a body with no `seen`, and HTML. - A replayed earlier answer fails as "not signed for this ask". - `TestHADrainAnswerWireShape` pins the exact answer body by recomputing the MAC by hand. - The forgery test now also refuses a missing, short or upper-case nonce. **(2) `no_fixed_boxes`** - `no_fixed_boxes` must be a JSON boolean. A string, number, null or list is rejected as `config_invalid`. - The floor needs exactly one of a non-empty `fixed_boxes` and `"no_fixed_boxes": true`: - Neither (a missing or empty list, with the flag false or absent) is a floor error, `floor_fixed_boxes`. - Both is a floor error, `floor_fixed_both`. - A box's edges file still counts toward the floor whatever is declared. - `TestFloorFixedBoxesDeclaration` covers all 9 combinations, and the config tests cover the type checks. - Spec §24 E14, §25.9 and §25.11 and the verb design doc are updated. **Tests and mutations** - Full `internal/grouproll` package: ok (270 s). - Targeted internal/edge tests (drain, take, control paths, forward, wake): ok. Targeted internal/host tests (drain, edges file, group-name and other census tests): ok. internal/provision census tests: ok. - `go vet` on the changed packages: ok. `gofmt`: clean. Cross-builds for darwin/arm64, windows/amd64 and linux/arm64: ok. - Mutations, each reverted: - Skipping the answer's MAC check fails `TestHADrainAnswerMustBeSignedForTheAsk`. - Accepting both `fixed_boxes` and `no_fixed_boxes` fails `TestFloorFixedBoxesDeclaration`. - Reading `no_fixed_boxes: false` as "none" fails `TestFloorFixedBoxesDeclaration`. **Census** - `make census-card` showed `Edge.serveHAControl` as a changed unit, and the edge and grouproll envelopes moved. - The first `census-propose` failed because it also wanted a claim for `Edge.AskDrainSeen`. I added one and reran it, and the census tests pass. - `AskDrainSeen` doesn't appear in the card's table, but its claim is in the overlay TSV. - The CLAIMS file `.superpowers/held-floor-capability-claims.tsv` now has three lines: ``` internal/host/edgesfile.go:edgesFileWriteClaims held floor capability (region HA §25.9, agent manager 8a3d302, 2026-11-10): sets the constant ha_handover=1 on the box's own edges file on every pass, whatever its capabilities (this build understands the held-requests headers and the drain acknowledgement); the group roll floor reads it. Not from config or any read; ha_take unchanged; a report other tools read, not a root decision; no read added; F,J1 authority retained. One-off cost: the first pass after the upgrade writes once per box. internal/edge/hadrain.go:Edge.serveHAControl held floor capability (region HA §25.4 step 1, agent manager 8a3d302, 2026-11-10): a drain ask must also carry a nonce of 32 lower-case hex digits (else a bare 404, like any other malformed ask), and the JSON answer gains sig, an HMAC-SHA256 under the same mesh key (signingKey of the mirrored pair) over a distinct domain, this box, the asker, the transaction, the phase, the publication id, the nonce and the seen value. Computed in memory from the already verified ask; no read added, no file, record or store access added; the take path is unchanged. internal/edge/hadrain.go:Edge.AskDrainSeen held floor capability (region HA §25.4 step 1, agent manager 8a3d302, 2026-11-10): the ask gains a nonce, 16 bytes from crypto/rand in lower-case hex, inside the already signed body; the answer must carry sig, an HMAC-SHA256 under either mirrored mesh key over a distinct domain, the peer, this box, the transaction, the phase, the id, that nonce and the seen value, verified in constant time; an unsigned, wrongly signed or other-ask answer is an error (not acknowledged), never seen. Reads only the in-memory mesh keys it already used; no store, file or record read added; a drain only fails more often, never proceeds on less. ``` **Operator-facing strings for copy review** (`internal/grouproll/text.go`; none of these has been reviewed) - `floor_box` (changed in round 0): "Box {box} does not publish ha_handover: 1" - `floor_fixed_missing` (new): "Fixed box {box} is in fixed_boxes but has no edges file" - `floor_fixed_boxes` (new, reworded this round): "The config must list the deployment's fixed boxes in fixed_boxes, or set no_fixed_boxes to true if it has none" - `floor_fixed_both` (new): "The config lists fixed_boxes and also sets no_fixed_boxes to true. Keep only one" The drain-report reasons operators see in the drain summary, all new: - "the %s state could not be acknowledged: %v" - "ha-drain: the edges files have not all been read" - "ha-drain: %s's answer is not signed for this ask" **Config keys, as an operator would read them** - `fixed_boxes`: a list of box references, one for every fixed box in the deployment that can forward requests to a group member, in any region. For example `["adi", "tito-1"]`. Each reference appears once and is the name of the box's edges file without `.json`. If a listed box has no edges file, the tool uses DR-4 and names the box. - `no_fixed_boxes`: `true` or `false`. Set it to `true` only if the deployment has no fixed boxes at all. - Use exactly one of the two: a non-empty `fixed_boxes`, or `"no_fixed_boxes": true`. With neither, or with both, the tool refuses the transaction and changes nothing. - The superseded `region-group-roll.py` refuses a config that contains either key. **Not done** - The runbook still needs your copy-reviewed edits: - `docs/region-ha-runbook.md` lines 62 and 64 (the old `ha_take` and `CARLOS_REGION_HA` sentences). - Its "Add three keys" list, which now needs `fixed_boxes` / `no_fixed_boxes`.</result> <usage><subagent_tokens>304954</subagent_tokens><tool_uses>101</tool_uses><duration_ms>1967339</duration_ms></usage> </task-notification>

diff --git a/internal/lease/release_snapshot_test.go b/internal/lease/release_snapshot_test.go
index a0228bc3c..4c6e431d9 100644
--- a/internal/lease/release_snapshot_test.go
+++ b/internal/lease/release_snapshot_test.go
@@ -228,8 +228,16 @@ func TestDrainReleaseSnapshotEarlyRefusalReleasesTheWAL(t *testing.T) {
haBox(t)
fx := leasetest.NewLockFixture(t)
dir := t.TempDir()
- rc := &countingReplica{ReplicaClient: lsfile.NewReplicaClient(dir), refuseEarly: true}
+ rc := &countingReplica{ReplicaClient: lsfile.NewReplicaClient(dir)}
r, path := manyL0(t, fx, "instances/h", rc, 5)
+ // Armed only now, for the drain's own snapshot (#810). Armed from the
+ // start, it also refused the store monitor's Open-time snapshot, and
+ // litestream's DB.Snapshot leaves its reader, and with it the WAL, open
+ // when an upload fails and the client does not close the body (this
+ // fake does not). That leak was the fixture's, not the drain release's.
+ rc.mu.Lock()
+ rc.refuseEarly = true
+ rc.mu.Unlock()
txid, snapErr, err := r.FinishSnapshot(ctx)
if err != nil || snapErr == nil {
t.Fatalf("FinishSnapshot: txid %d, snapshot %v, %v; want the snapshot's failure alone", txid, snapErr, err)