Merge remote-tracking branch 'origin/main' into claim-source
# Conflicts: # internal/provision/testdata/plan14-root-reads-chain.tsv
docs/superpowers/notes/2026-11-07-region-ha-g3-fixes-follow-ups.md+1 −0docs/superpowers/notes/census-proposal-claim-source.md+1 −1docs/superpowers/notes/census-proposal-region-ha-dr2.md+19 −0internal/host/hadepartures_dr2_test.go+208 −0internal/host/hadepartures_scan.go+46 −0internal/provision/testdata/plan14-root-reads-chain.tsv+2 −1internal/provision/testdata/plan14-root-reads-region-ha-dr2.tsv+5 −0
Intent
<task-notification> <task-id>a57775d8d661befd0</task-id> <tool-use-id>toolu_014CzrL4v1AnqsPeKpeX1j6X</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/a57775d8d661befd0.output</output-file> <status>completed</status> <summary>Agent "Opus security review claimed source" 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>**Verdict: BLOCK.** One P1 and one P2. The rest of the feature is sound. I reviewed `ca027e85..ac851b77` plus the three merge files at tip 5b8d7b61. **P1: the kept link reveals the claimant's email and sqid** (`internal/console/demo_claim_page.go:154-171` at the tip) - **Cause:** when the merge was resolved, the "Keep going" identity fill landed inside the branch that also serves the kept-link status cookie (`keptErr == nil`). Commit ce7576a6 promised that path "never names the account or claimant". - **Scenario:** a fresh claimant's account is auto-minted with the person's email as its name (`demo_claim_target.go:78`). Whoever first opens the `kept_url` handed to the chat agent gets a page with "in my account <email>", the sqid and filled commands. That browser never completed the claim, so this breaks item 7. - **Why tests miss it:** `demo_claim_kept_test.go:253` asserts the page does not contain `op.Person`. It passes only because the fixture names the account "shop" (`demo_claim_target_test.go:49`). - **Fix:** fill AccountName, AccountSqid, agentLine and SourceSteps only on the proven-flow path, or when a signed-in session is a current owner/member of the target. Change the kept fixture to an auto-minted account. **P2: locks are held while bytes go to the client** (`internal/console/app_source.go:224-226, 241, 268`) - **Cause:** the members, account and app locks and the global buffer slot are released by `defer`, after `w.Write(b)`. The console's HTTP server has no WriteTimeout (`httpserver.go:16`), and the 30-second context does not stop a blocked Write. - **Scenario:** a member whose client stops reading (zero window), on an archive bigger than the socket buffers, holds `lockMembers` indefinitely. The owner can't remove them (`ownership.go:52`), and invites, Trash/purge of the app and claim aborts in that account stall. Four such connections stop source downloads everywhere. - **Fix:** release the locks and the slot after the recheck and audit, before writing. Set a write deadline with `http.ResponseController`. **P3s** - `internal/demobuild/source.go:79`: `ValidateArchive` refuses a gzip header with the optional "extra" field (FEXTRA), but `ValidateSource` accepts it at publish. Such uploads publish fine, then every claim aborts. Also, any later tightening of `forbiddenFile` would make existing snapshots permanently unreadable (503). Make the archive check exactly the structural set used at publish. - `apps_source.go:97`: the CLI's 401 "sign in" branch can't be reached, because admission turns a missing or expired token into a 404. There are uncommitted edits in the worktree right now (`app_source.go`, `svcroutes_test.go`) that address this. I did not review them. - `apps_source.go:69`: the output file is created before the request, so Ctrl-C leaves an empty file. Download to a temp file and link it into place. - `app_source.go:243`: storage failures return 503 with no log line. **Checked and sound** - **Authorisation:** both doors refuse with the same 404 before any storage read. Membership is rechecked in SQL (`app_source.go:210`) and again after the read (`:249`), with membership removal serialised by the members lock. No key, job or account comes from the request; the key uses the validated sqid, app and op ID (`:64`, `:41`). - **Pinning:** exactly one published job matching the version and digest (`demo_claim_transfer.go:276-316`). - **Copy:** create-only PUT; an uncertain PUT is verified against the destination (`app_source.go:83-94`). Abort can't touch a committed claim (`demo_claim_transfer.go:837`). - **Validator:** the `ValidateSource` path is unchanged. Neither the console nor the CLI extracts or runs the archive. - **Headers and audit:** headers are correct, and the audit happens before any bytes go out. - **CLI:** `O_EXCL`, mode 0600, refuses symlinks, no redirects, `Accept-Encoding: identity`, size and digest checked. - **Retention:** rename and move are refused in the store transaction. - **Done page:** commands are single-quoted over regex-validated values, html/template escapes everything, and the CSP is unchanged. - **Merge:** columns and placeholders line up (22 each). **Tests** - `TestAppSource*`: 18 of 19 pass. `TestAppSourceHeadless` fails because Chromium hits ECONNRESET in the sandbox, which looks environmental. - `TestAppsSource*`: did not run. With the default TMPDIR the harness refuses because `~/.carlos/config` sits above it. With a clean TMPDIR, `go-build` reported a read-only filesystem. The scratch directory has been removed. **Census lines** (tip 5b8d7b61) - `apps_source.go:pullAppSource` accepted-legacy: **APPROVE**. It creates an operator-chosen file exclusively, refuses symlinks and never follows or extracts tenant bytes. - `internal/demobuild/source.go:validateSource` accepted-legacy: **APPROVE**. In-memory reads only; the `ValidateSource` checks are unweakened. - `internal/demobuild/source.go:ValidateSource` retired: **APPROVE**. It is now a thin wrapper that reads nothing. - Envelope `.`: **APPROVE**. `RunApps` dispatch and `runAppsSource` reach only existing session and console calls. - Envelope `internal/demobuild`: **APPROVE**. - Record-write overlay `claim_source_census_test.go`: **APPROVE**. The source key has 7 segments, so `IsRecordKey` (`record_sequence.go:18`) never matches it; "nonrecord sel:Put" is correct, and both route registries are unchanged apart from the new GET doors.</result> <usage><subagent_tokens>142452</subagent_tokens><tool_uses>53</tool_uses><duration_ms>516718</duration_ms></usage> </task-notification>
<task-notification> <task-id>b7y7ig8ki</task-id> <tool-use-id>toolu_01FSbPJXeAr3PQCqEhfsqUdZ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/b7y7ig8ki.output</output-file> <status>completed</status> <summary>Background command "S=/home/paulca/.cache/tmp/cux; until [ -f $S/web/done ]; do sleep 30; done; tail -1 $S/web/log; cat $S/web/final.md" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>a57775d8d661befd0</task-id> <tool-use-id>toolu_014Uv8ZpN5D3SLnPV8RhExPK</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/a57775d8d661befd0.output</output-file> <status>completed</status> <summary>Agent "Opus security review claimed source" 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>**Verdict: APPROVE WITH NITS.** Commit 08bf8193 fixes the P1 and the P2. I read the diff only and ran no tests, as asked. **P1 (fixed).** `internal/console/demo_claim_page.go:158-161` now fills the Keep going block in only two cases: - the browser holds the claim's own flow cookie (`keptErr != nil`, the flow hash matches the operation's, and the operation has a person), or - the browser has a signed-in session whose address is a current owner or member of the target account. A kept-link or status-only cookie therefore gets no account name, sqid or commands. The template drops the whole section in that case (`demo_claim.html:176`), and the JS handles the section being absent. The sqid in the public app hostname was already disclosed, so that's acceptable. **P2 (fixed).** `app_source.go`: - The locks and the buffer slot are now released inside a closure (`:233-264`), and the slot's `done()` at `:248` runs before any write. - A 30-second write deadline is set before the bytes go out (`:267`). - The audit still happens before bytes, and an audit failure still means no bytes. **P3s.** - FEXTRA is accepted again, and the file-exclusion check is skipped only when re-reading a stored archive. Publishing and the build worker still go through `ValidateSource` with the full checks (`apidemo.go:456`, `worker.go:223`, `host/demo_jobs.go:588`). - The CLI writes the download atomically: `Lstat` refuses an existing file or symlink, `CreateTemp` makes a mode-0600 file in the same directory, and `Link` puts it in place without overwriting (`apps_source.go:70,75,134`). - Storage failures are logged without any source bytes. **Your change.** A request with no credential now falls through to `cliGate`'s standard 401. Service credentials and non-members still get the identical 404. **Nits.** - `apps_source.go:134`: `os.Link` fails on filesystems without hard links (some FUSE and network mounts), and the user only sees "temporarily unavailable". You could fall back to `Rename` after re-checking with `Lstat`, or say why it failed. - `app_source.go:267`: with a flat 30-second deadline, a 5 MB archive fails for clients slower than about 170 KB/s. Acceptable as it stands. **Census (tip 08bf8193).** - `apps_source.go:pullAppSource` (Lstat, CreateTemp in the operator's own directory, ReadAll ×2): **APPROVE**. Nothing comes from a tenant-named path, and nothing is followed or extracted. - `internal/demobuild/source.go:validateSource`: **APPROVE**. It skips the file exclusions only on the archive-only path; the publish and worker path is unchanged. - `ValidateSource` retired: **APPROVE**. - Envelope `.`: **APPROVE**. - Envelope `internal/demobuild`: **APPROVE**.</result> <usage><subagent_tokens>157415</subagent_tokens><tool_uses>6</tool_uses><duration_ms>42397</duration_ms></usage> </task-notification>
<task-notification> <task-id>b59b4tstt</task-id> <tool-use-id>toolu_01JfGGHULTJPkAXMfVdajyoY</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/b59b4tstt.output</output-file> <status>completed</status> <summary>Background command "sleep 45; until amadan ci status carlos/platform -branch claim-source 2>&1 | head -1 | grep -q '@ 08bf8193'; do sleep 30; done; while amadan ci status carlos/platform -branch claim-source 2>&1 | head -1 | grep -q 'running\|queued\|pending'; do sleep 60; done; amadan ci status carlos/platform -branch claim-source 2>&1 | head -1" completed (exit code 0)</summary> </task-notification>
diff --git a/docs/superpowers/notes/2026-11-07-region-ha-g3-fixes-follow-ups.md b/docs/superpowers/notes/2026-11-07-region-ha-g3-fixes-follow-ups.md| index 085035753..2701fcc83 100644 |
| --- a/docs/superpowers/notes/2026-11-07-region-ha-g3-fixes-follow-ups.md |
| +++ b/docs/superpowers/notes/2026-11-07-region-ha-g3-fixes-follow-ups.md |
| @@ -11,6 +11,7 @@ Branch `region-ha-g3-fixes` (2026-11-07). These are the P3s and deferred items f |
| 6. The simulation's churn never mutates records that carry duties. (T2 review) |
| 7. The journal `Visited` map grows with the deployment: about 40 KB per save at 300 records. (T2 review) |
| 8. Retiring a group member leaves its `status/boxes`, `alerts/boxes` and `metrics/boxes` objects behind until they age out (24 h). This branch makes the readers that page or block ignore a proven member with no edges file. The departure itself should delete these objects on their ETags after the edges file. That is a new delete on the termination path, so it needs its own review and census row. (8a3d302 finding, inv/status-rows.md) |
| + DR-2 (2026-11-07) does the `status/boxes` part: a group member's departure deletes that snapshot on its ETag after the edges file, best-effort. `alerts/boxes` stays: deleting it would clear a firing alert as gone, which wants its own decision. `metrics/boxes` stays: it is history under many keys and blocks nothing. |
| ## Steering |
| 9. Bisecting a refused chunk is not paced against Route 53's 5 requests per second. Known foreign latency records in the same region are not filtered out up front, and the shrink guard can refuse a whole pass after a large drop. (T1 review) |
diff --git a/docs/superpowers/notes/census-proposal-claim-source.md b/docs/superpowers/notes/census-proposal-claim-source.md| index 889152d96..97d3523ca 100644 |
| --- a/docs/superpowers/notes/census-proposal-claim-source.md |
| +++ b/docs/superpowers/notes/census-proposal-claim-source.md |
| @@ -12,6 +12,6 @@ New dispositions, which census-propose wrote and the reviewer checks against the |
| - new `internal/demobuild/source.go:validateSource`: reads +file:ReadAll ×3; written legacy, accepted-legacy, frozen |
| - quiet `internal/demobuild/source.go:ValidateSource`: reads nothing now; retired while it reads nothing (or its row keeps no sites) |
| -Seal: `5b31785441c6a48ddae93e9f3c0f8962f7983b55d89b3acb90d9a6b505647b36` → `7868de86ba3ff8e973713f04081f76ea003380ca5b7a6db7e0f5d20d10d535d8`. |
| +Seal: `7247af7f4de84593d83c6f60c0147d0a04836146197dd60c2ed2bf78919cad22` → `9d909e0157aba52540f0cdb71a9f3cf8140abf95203b5a2b3f826d77ee83e0bd`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-claim-source.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/notes/census-proposal-region-ha-dr2.md b/docs/superpowers/notes/census-proposal-region-ha-dr2.md| new file mode 100644 |
| index 000000000..0ff4759ae |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-region-ha-dr2.md |
| @@ -0,0 +1,19 @@ |
| +# Census approval: region-ha-dr2 |
| + |
| +Ruling `census-ruling-region-ha-dr2`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/host/hadepartures_scan.go` `Controller.complete` | sites | +whole:HADeparture | DR-2: after the edges phases, calls retireStatusSnapshot, which for a deterministic account/iid group reference only does one GET of status/boxes/<ref>.json in the deployment store and a conditional delete of that exact revision (ETag). Best-effort and time-bounded (at most 5 s, always leaving 2 s of the step for the completion save; Astra R1 P2): any failure or timeout is logged and never holds completion, paging or acknowledgement. Fixed refs untouched. No filesystem, executable or new authority read; no change to the edges deletion, completion gates or ordering. | |
| + |
| +Envelopes re-pinned: `internal/host`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/host/hadepartures_scan.go` `Controller.complete`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-region-ha-p1b3b-t;basis=B4: Read the durable departure/scan and current inventory, then conditionally delete only the retained exact edges key/revision. Reread uncertain results and refuse replacement identities. Persist deletion and acknowledged index phases before complete; queue receipts stay in memory and only complete rows acknowledge. Fresh process evidence is required before authority checkpoint reuse. Fix r1/P15: ignore the old scan-level ETag override and delete only the original departure ETag. Exact-key readback retries the same tag; a changed tag is never deleted and advances only with a different verified iid under the same ref/account/scope, otherwise holds and pages. Persist permission fault episodes; route completion faults through bounded retry. No new filesystem or executable input. B4 fix r4/P18 supersedes fixed-ref deletion: only the deterministic account/iid group reference may delete its retained exact ETag. Every other ref performs an exact-key GET and stays pending unless absent or the existing verified newer-incarnation check succeeds; the live replacement file is left intact. Group revision changes stay pending. No new key or authority read. B5: Increment completion counter only after the durable complete phase; C4 ordering stays after that commit.;rev3=census-ruling-region-ha-p3b;basis=Require registered admitted work before completing a departure or acknowledging it. Existing coverage, inventory, lease and successor reads remain; closed members defer rather than clear obligations.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: drops the per-departure nudge bookkeeping (moved to a fixed-size global limiter). Completion gates, exact-ETag deletion and reads unchanged.;rev3=census-ruling-region-ha-g3-fixes;basis=Require current inventory visit coverage and re-read group edges before conditional deletion. Verify identity and scope before rebinding a changed ETag; preserve fixed-ref retention and exact-ETag deletion. Reads scan EdgesETag and coverage state; no new object key or read source. |
| + |
| +Seal: `5b31785441c6a48ddae93e9f3c0f8962f7983b55d89b3acb90d9a6b505647b36` → `7247af7f4de84593d83c6f60c0147d0a04836146197dd60c2ed2bf78919cad22`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-dr2.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/host/hadepartures_dr2_test.go b/internal/host/hadepartures_dr2_test.go| new file mode 100644 |
| index 000000000..813d13b98 |
| --- /dev/null |
| +++ b/internal/host/hadepartures_dr2_test.go |
| @@ -0,0 +1,208 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "os" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/edgesfile" |
| + "github.com/carlosframework/platform/internal/hafresh" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// DR-2 (dev rehearsal 2026-11-07): a retired group member's status snapshot |
| +// stays fresh for 3 x status.SnapshotPeriod after its last write, while the |
| +// departure deletes its edges file within minutes. edgesfile.JoinLive reads a |
| +// fresh snapshot with no edges file as incomplete evidence (ruling (A)), so |
| +// every automatic non-home create was refused until the snapshot aged out. |
| +// The departure that deletes the edges file must take the snapshot with it. |
| + |
| +// dr2Finalize drives the departure to "complete" with the dead box's status |
| +// snapshot written lastWrite before the finalize, and returns the store's |
| +// snapshot read the console joins on, one minute after the finalize. |
| +func dr2Finalize(t *testing.T, x *g3Departure, lastWrite time.Duration) edgesfile.Snapshot { |
| + t.Helper() |
| + ctx := t.Context() |
| + for _, b := range []struct { |
| + ref string |
| + at time.Time |
| + }{{x.dead.Ref, x.now.Add(-lastWrite)}, {x.peer.Ref, x.now}} { |
| + if err := status.WriteBox(ctx, x.store, status.Box{Label: b.ref, GeneratedAt: b.at}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + // The live peer publishes its own edges file: the read below must still |
| + // see one fresh, published box, so a pass that deleted everything fails. |
| + peer := x.dead |
| + x.dead = x.peer |
| + key, tag := x.edgesKey, x.edgesTag |
| + x.edgesKey, x.edgesTag = edgesfile.Key(x.peer.Ref), "" |
| + x.writeEdges(t) |
| + x.dead, x.edgesKey, x.edgesTag = peer, key, tag |
| + |
| + entry, _ := provision.LifetimeEntryOf(x.records[0]) |
| + raw, _ := hafresh.MarkerBody(5, hafresh.Marker{V: 1, Box: x.dead.Ref, IID: x.dead.InstanceID, Lifetime: entry.ID}) |
| + x.fx.PutLock("instances/"+x.records[0].Host, raw) |
| + for i := 0; i < 6 && x.row(t).Phase != "complete"; i++ { |
| + if err := x.c.step(ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + x.now = x.now.Add(31 * time.Second) |
| + } |
| + if d := x.row(t); d.Phase != "complete" { |
| + t.Fatalf("departure never finalized: %+v", d) |
| + } |
| + if _, _, err := x.store.Get(ctx, x.edgesKey); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("edges file survived the departure: %v", err) |
| + } |
| + snap, err := edgesfile.ReadLiveSnapshot(ctx, x.store, x.now.Add(time.Minute)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return snap |
| +} |
| + |
| +func TestDepartureDR2RetiredSnapshotGoesWithEdges(t *testing.T) { |
| + x := newG3Departure(t, 1) |
| + // The rehearsal's shape: last snapshot about four minutes before the |
| + // edges delete, so it stays fresh for another eleven. |
| + snap := dr2Finalize(t, x, 4*time.Minute) |
| + if !snap.BoxesComplete { |
| + t.Fatal("DR-2: a retired member's fresh status snapshot leaves the live read incomplete after its departure finalized") |
| + } |
| + if _, _, err := x.store.Get(t.Context(), "status/boxes/"+x.dead.Ref+".json"); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("retired member's status snapshot survived: %v", err) |
| + } |
| + if _, _, err := x.store.Get(t.Context(), "status/boxes/"+x.peer.Ref+".json"); err != nil { |
| + t.Fatalf("live peer's status snapshot was touched: %v", err) |
| + } |
| + fresh := 0 |
| + for _, f := range snap.Files { |
| + if f.Fresh { |
| + fresh++ |
| + } |
| + } |
| + if fresh != 1 || !snap.EvidenceComplete() { |
| + t.Fatalf("live read after departure: %d fresh, complete %v", fresh, snap.EvidenceComplete()) |
| + } |
| +} |
| + |
| +// statusDeleteRefused fails every delete of a status snapshot. |
| +type statusDeleteRefused struct { |
| + release.Store |
| + tries int |
| +} |
| + |
| +func (s *statusDeleteRefused) refuse(key string) error { |
| + if strings.HasPrefix(key, "status/boxes/") { |
| + s.tries++ |
| + return errors.New("AccessDenied") |
| + } |
| + return nil |
| +} |
| +func (s *statusDeleteRefused) Delete(ctx context.Context, key string) error { |
| + if err := s.refuse(key); err != nil { |
| + return err |
| + } |
| + return s.Store.Delete(ctx, key) |
| +} |
| +func (s *statusDeleteRefused) DeleteIfMatch(ctx context.Context, key, etag string) error { |
| + if err := s.refuse(key); err != nil { |
| + return err |
| + } |
| + return release.DeleteIfMatch(ctx, s.Store, key, etag) |
| +} |
| +func (s *statusDeleteRefused) DeleteRevision(ctx context.Context, key, etag string) error { |
| + if err := s.refuse(key); err != nil { |
| + return err |
| + } |
| + return s.Store.(release.IndexedDeleter).DeleteRevision(ctx, key, etag) |
| +} |
| +func (s *statusDeleteRefused) IndexDeletion(ctx context.Context, key string) error { |
| + return s.Store.(release.IndexedDeleter).IndexDeletion(ctx, key) |
| +} |
| + |
| +// The snapshot delete is a cleanup: refusing it must not hold the departure |
| +// (its duties are recovered and its edges file is gone), so the worst case is |
| +// the pre-fix window, never a stuck departure or a page. |
| +func TestDepartureDR2SnapshotDeleteFailureDoesNotBlock(t *testing.T) { |
| + x := newG3Departure(t, 1) |
| + refused := &statusDeleteRefused{Store: x.store} |
| + x.c.cfg.OpenStore = func(context.Context) (release.Store, error) { return refused, nil } |
| + snap := dr2Finalize(t, x, 4*time.Minute) |
| + if refused.tries == 0 { |
| + t.Fatal("the departure never tried to delete the retired snapshot") |
| + } |
| + if x.pages != 0 { |
| + t.Fatalf("a refused snapshot delete paged %d times", x.pages) |
| + } |
| + if snap.BoxesComplete { |
| + t.Fatal("the refused delete left no snapshot, so this test proves nothing") |
| + } |
| + if _, _, acks := x.queue.counts(); acks != 1 { |
| + t.Fatal("departure not acknowledged", acks) |
| + } |
| +} |
| + |
| +// A fixed reference is reused by the box that replaces it, so its departure |
| +// must leave the snapshot under that label alone: it may be the new box's. |
| +func TestDepartureDR2FixedReferenceKeepsSnapshot(t *testing.T) { |
| + store := release.NewDirStore(t.TempDir()) |
| + if err := status.WriteBox(t.Context(), store, status.Box{Label: "fixed", GeneratedAt: time.Now()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + c := &Controller{cfg: DepartureConfig{Logf: func(string, ...any) {}}} |
| + d := registry.HADeparture{} |
| + d.Box.Ref, d.Box.Account, d.Box.InstanceID = "fixed", "111122223333", "i-1123456789abcdef0" |
| + c.retireStatusSnapshot(t.Context(), store, d) |
| + if _, _, err := store.Get(t.Context(), "status/boxes/fixed.json"); err != nil { |
| + t.Fatalf("a fixed reference's departure took the snapshot under its label: %v", err) |
| + } |
| +} |
| + |
| +// statusReadHangs answers every status snapshot read only when its context |
| +// ends: a store that has stopped answering. |
| +type statusReadHangs struct{ statusDeleteRefused } |
| + |
| +func (s *statusReadHangs) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if strings.HasPrefix(key, "status/boxes/") { |
| + s.tries++ |
| + <-ctx.Done() |
| + return nil, "", ctx.Err() |
| + } |
| + return s.Store.Get(ctx, key) |
| +} |
| + |
| +// Astra R1 P2: the cleanup must not spend the time the departure needs to |
| +// record that it is complete. A hung status read near the end of a step's |
| +// budget would otherwise fail save("complete") and page for a departure |
| +// whose duties and edges file are already settled. |
| +func TestDepartureDR2HungSnapshotReadDoesNotPage(t *testing.T) { |
| + x := newG3Departure(t, 1) |
| + hung := &statusReadHangs{statusDeleteRefused{Store: x.store}} |
| + x.c.cfg.OpenStore = func(context.Context) (release.Store, error) { return hung, nil } |
| + entry, _ := provision.LifetimeEntryOf(x.records[0]) |
| + raw, _ := hafresh.MarkerBody(5, hafresh.Marker{V: 1, Box: x.dead.Ref, IID: x.dead.InstanceID, Lifetime: entry.ID}) |
| + x.fx.PutLock("instances/"+x.records[0].Host, raw) |
| + for i := 0; i < 6 && x.row(t).Phase != "complete"; i++ { |
| + ctx, cancel := context.WithTimeout(t.Context(), snapshotRetireReserve+time.Second) |
| + _ = x.c.step(ctx) |
| + cancel() |
| + x.now = x.now.Add(31 * time.Second) |
| + } |
| + if d := x.row(t); d.Phase != "complete" { |
| + t.Fatalf("a hung snapshot read held the departure: %+v", d) |
| + } |
| + if x.pages != 0 { |
| + t.Fatalf("a hung snapshot read paged %d times", x.pages) |
| + } |
| + if hung.tries == 0 { |
| + t.Fatal("the cleanup never ran, so this test proves nothing") |
| + } |
| +} |
diff --git a/internal/host/hadepartures_scan.go b/internal/host/hadepartures_scan.go| index 990828a87..b9302e3ab 100644 |
| --- a/internal/host/hadepartures_scan.go |
| +++ b/internal/host/hadepartures_scan.go |
| @@ -669,6 +669,7 @@ func (c *Controller) complete(ctx context.Context, id string) (result error) { |
| return err |
| } |
| } |
| + c.retireStatusSnapshot(ctx, store, d) |
| if err = save("complete"); err != nil { |
| return err |
| } |
| @@ -679,6 +680,51 @@ func (c *Controller) complete(ctx context.Context, id string) (result error) { |
| return c.ackDeparture(ctx, d) |
| } |
| +// retireStatusSnapshot deletes a departed group member's status snapshot once |
| +// its edges file is gone (DR-2). The snapshot stays fresh for three status |
| +// periods after the box's last write, and edgesfile.JoinLive reads a fresh |
| +// snapshot with no edges file as incomplete evidence, which refuses every |
| +// automatic create outside the home region until it ages out. |
| +// |
| +// Only a group reference qualifies: it names one account and instance |
| +// forever, and that instance is proven terminated, so nothing else writes |
| +// this key. A fixed reference is reused by its replacement, whose snapshot |
| +// this must never take. The delete is conditional on the revision read here, |
| +// and it is a cleanup: any failure leaves the snapshot to age out as before |
| +// and never holds the departure. |
| +// snapshotRetireReserve is the time retireStatusSnapshot leaves for the |
| +// durable completion save that follows it. |
| +const snapshotRetireReserve = 2 * time.Second |
| + |
| +func (c *Controller) retireStatusSnapshot(ctx context.Context, store release.Store, d registry.HADeparture) { |
| + if d.Box.Ref != groupReferenceOf(d.Box.Account, d.Box.InstanceID) { |
| + return |
| + } |
| + key := "status/boxes/" + d.Box.Ref + ".json" |
| + // Leave the step the time it needs to record completion (Astra R1 P2): |
| + // a hung read here must not fail save("complete") and page. |
| + budget := 5 * time.Second |
| + if deadline, ok := ctx.Deadline(); ok { |
| + budget = min(budget, time.Until(deadline)-snapshotRetireReserve) |
| + } |
| + if budget <= 0 { |
| + c.logf("Box %s left its status report %s behind (no time left in this pass). It stops counting as fresh within 15 minutes.", d.Box.Ref, key) |
| + return |
| + } |
| + call, cancel := context.WithTimeout(ctx, budget) |
| + defer cancel() |
| + _, tag, err := store.Get(call, key) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return |
| + } |
| + if err == nil { |
| + err = release.DeleteIfMatch(call, store, key, tag) |
| + } |
| + if err != nil { |
| + c.logf("Box %s left its status report %s behind (%v). It stops counting as fresh within 15 minutes.", d.Box.Ref, key, err) |
| + } |
| +} |
| + |
| func (c *Controller) bindDepartureEdges(ctx context.Context, d registry.HADeparture, raw []byte, tag string) error { |
| if tag == "" || c.cfg.Identities == nil || d.Box.Ref != groupReferenceOf(d.Box.Account, d.Box.InstanceID) { |
| return errDepartureIdentity |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 009790e13..7e67d2ef7 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -117,4 +117,5 @@ plan14-root-reads-signin-first-run-mobile.tsv 61027a32e31cb7ce017304f526f668c269 |
| plan14-root-reads-claim-ux-edge.tsv 889ce9f72f93b581b29527e5c5d4410b47732424ce8ce45c080904ebb6c52195 |
| plan14-root-reads-region-ha-g3-fixes.tsv cd001bf3a9a8871f12d1ca9cfa0a925760c1fc345dc911246ffaabc235dfabf6 |
| plan14-root-reads-claim-countdown.tsv 5b31785441c6a48ddae93e9f3c0f8962f7983b55d89b3acb90d9a6b505647b36 |
| -plan14-root-reads-claim-source.tsv 7868de86ba3ff8e973713f04081f76ea003380ca5b7a6db7e0f5d20d10d535d8 |
| +plan14-root-reads-region-ha-dr2.tsv 7247af7f4de84593d83c6f60c0147d0a04836146197dd60c2ed2bf78919cad22 |
| +plan14-root-reads-claim-source.tsv 9d909e0157aba52540f0cdb71a9f3cf8140abf95203b5a2b3f826d77ee83e0bd |
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-dr2.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-dr2.tsv| new file mode 100644 |
| index 000000000..c836b8b8b |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-region-ha-dr2.tsv |
| @@ -0,0 +1,5 @@ |
| +# Census overlay region-ha-dr2, written by census-propose (#369). census-ruling-region-ha-dr2, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-region-ha-dr2.md. |
| +# 0 body, 1 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 96bc6eeef386b0a0a2cbbb9fcda68a84e458f26bd385510e2425f73f869dc337 internal/host/hadepartures_scan.go Controller.complete legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b3b-t;basis=B4: Read the durable departure/scan and current inventory, then conditionally delete only the retained exact edges key/revision. Reread uncertain results and refuse replacement identities. Persist deletion and acknowledged index phases before complete; queue receipts stay in memory and only complete rows acknowledge. Fresh process evidence is required before authority checkpoint reuse. Fix r1/P15: ignore the old scan-level ETag override and delete only the original departure ETag. Exact-key readback retries the same tag; a changed tag is never deleted and advances only with a different verified iid under the same ref/account/scope, otherwise holds and pages. Persist permission fault episodes; route completion faults through bounded retry. No new filesystem or executable input. B4 fix r4/P18 supersedes fixed-ref deletion: only the deterministic account/iid group reference may delete its retained exact ETag. Every other ref performs an exact-key GET and stays pending unless absent or the existing verified newer-incarnation check succeeds; the live replacement file is left intact. Group revision changes stay pending. No new key or authority read. B5: Increment completion counter only after the durable complete phase; C4 ordering stays after that commit.;rev3=census-ruling-region-ha-p3b;basis=Require registered admitted work before completing a departure or acknowledging it. Existing coverage, inventory, lease and successor reads remain; closed members defer rather than clear obligations.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: drops the per-departure nudge bookkeeping (moved to a fixed-size global limiter). Completion gates, exact-ETag deletion and reads unchanged.;rev3=census-ruling-region-ha-g3-fixes;basis=Require current inventory visit coverage and re-read group edges before conditional deletion. Verify identity and scope before rebinding a changed ETag; preserve fixed-ref retention and exact-ETag deletion. Reads scan EdgesETag and coverage state; no new object key or read source.;rev3=census-ruling-region-ha-dr2;basis=DR-2: after the edges phases, calls retireStatusSnapshot, which for a deterministic account/iid group reference only does one GET of status/boxes/<ref>.json in the deployment store and a conditional delete of that exact revision (ETag). Best-effort and time-bounded (at most 5 s, always leaving 2 s of the step for the completion save; Astra R1 P2): any failure or timeout is logged and never holds completion, paging or acknowledgement. Fixed refs untouched. No filesystem, executable or new authority read; no change to the edges deletion, completion gates or ordering. registry:DeleteUncertain@3813,registry:DeleteUncertain@4198,registry:EdgesETag@1894,registry:EdgesETag@2906,registry:Hosts@5076,registry:InventoryGeneration@1846,registry:PermissionAlerted@2426,registry:PermissionAlerted@3559,registry:PermissionAlerted@4342,registry:PermissionAlerted@4746,registry:PermissionAlerted@841,registry:PermissionAlerted@883,registry:Phase@1002,registry:Phase@1042,registry:Phase@1538,registry:Phase@262,registry:Phase@3692,registry:Phase@4460,registry:Phase@680,registry:Phase@950,registry:Phase@967,registry:Version@665,whole:HADeparture@2846,whole:HADeparture@315,whole:HADeparture@442,whole:HADeparture@4872,whole:HADeparture@5125,whole:HADepartureHostScan@5078,whole:HADepartureScan@1718,whole:HADepartureScan@643 d27948e878037f10244e753357cf0686a69bfb065e44d5584117fabb707259c3 |
| +internal/host/hadepartures_scan.go Controller.complete legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b3b-t;basis=B4: Read the durable departure/scan and current inventory, then conditionally delete only the retained exact edges key/revision. Reread uncertain results and refuse replacement identities. Persist deletion and acknowledged index phases before complete; queue receipts stay in memory and only complete rows acknowledge. Fresh process evidence is required before authority checkpoint reuse. Fix r1/P15: ignore the old scan-level ETag override and delete only the original departure ETag. Exact-key readback retries the same tag; a changed tag is never deleted and advances only with a different verified iid under the same ref/account/scope, otherwise holds and pages. Persist permission fault episodes; route completion faults through bounded retry. No new filesystem or executable input. B4 fix r4/P18 supersedes fixed-ref deletion: only the deterministic account/iid group reference may delete its retained exact ETag. Every other ref performs an exact-key GET and stays pending unless absent or the existing verified newer-incarnation check succeeds; the live replacement file is left intact. Group revision changes stay pending. No new key or authority read. B5: Increment completion counter only after the durable complete phase; C4 ordering stays after that commit.;rev3=census-ruling-region-ha-p3b;basis=Require registered admitted work before completing a departure or acknowledging it. Existing coverage, inventory, lease and successor reads remain; closed members defer rather than clear obligations.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: drops the per-departure nudge bookkeeping (moved to a fixed-size global limiter). Completion gates, exact-ETag deletion and reads unchanged.;rev3=census-ruling-region-ha-g3-fixes;basis=Require current inventory visit coverage and re-read group edges before conditional deletion. Verify identity and scope before rebinding a changed ETag; preserve fixed-ref retention and exact-ETag deletion. Reads scan EdgesETag and coverage state; no new object key or read source.;rev3=census-ruling-region-ha-dr2;basis=DR-2: after the edges phases, calls retireStatusSnapshot, which for a deterministic account/iid group reference only does one GET of status/boxes/<ref>.json in the deployment store and a conditional delete of that exact revision (ETag). Best-effort and time-bounded (at most 5 s, always leaving 2 s of the step for the completion save; Astra R1 P2): any failure or timeout is logged and never holds completion, paging or acknowledgement. Fixed refs untouched. No filesystem, executable or new authority read; no change to the edges deletion, completion gates or ordering. registry:DeleteUncertain@3813,registry:DeleteUncertain@4198,registry:EdgesETag@1894,registry:EdgesETag@2906,registry:Hosts@5076,registry:InventoryGeneration@1846,registry:PermissionAlerted@2426,registry:PermissionAlerted@3559,registry:PermissionAlerted@4342,registry:PermissionAlerted@4746,registry:PermissionAlerted@841,registry:PermissionAlerted@883,registry:Phase@1002,registry:Phase@1042,registry:Phase@1538,registry:Phase@262,registry:Phase@3692,registry:Phase@4460,registry:Phase@680,registry:Phase@950,registry:Phase@967,registry:Version@665,whole:HADeparture@2846,whole:HADeparture@315,whole:HADeparture@442,whole:HADeparture@4872,whole:HADeparture@5125,whole:HADepartureHostScan@5078,whole:HADepartureScan@1718,whole:HADepartureScan@643 d27948e878037f10244e753357cf0686a69bfb065e44d5584117fabb707259c3 |
| +@coverage internal/host 384d3a2e206f25d36cd2045f96e3311d618dc363fdc8ce633a3ccd8de7b8937c |