carlos / platform Public

region HA: witness a restore caught at the finalization gate

Astra R1 (READY AFTER FIXES) P2: the restore witness was caught by the
rescan, not the gate. The new witness restores the app during the
finalize's edges read; removing the gate's trashed recheck fails it.
P3: the trashed() comment now says which hosts cost a marker read.
Findings in docs/superpowers/reviews/ASTRA-R1-ha-1192.md; census
re-proposed for the comment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e6946e7d8a14a9b2c424843161bec3b98e0bddc0 parent 591cd2e
4 files changed, +78 −5
  • docs/superpowers/reviews/ASTRA-R1-ha-1192.md +42 −0
  • internal/host/hadepartures_scan.go +5 −4
  • internal/host/hadepartures_trash_test.go +30 −0
  • internal/provision/testdata/plan14-root-reads-ha-1192.tsv +1 −1

CI passed — run details

diff --git a/docs/superpowers/reviews/ASTRA-R1-ha-1192.md b/docs/superpowers/reviews/ASTRA-R1-ha-1192.md
new file mode 100644
index 000000000..6181f5e3f
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-R1-ha-1192.md
@@ -0,0 +1,42 @@
+Reviewed `03ff5d17..d3eb89cc99cbb2845a9f96868566856f9f8c7319`, round 1. No P1 findings.
+
+- **P2 — Task 2 / witnesses: the restore test does not exercise the finalization gate.** At [hadepartures_trash_test.go:140](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_trash_test.go:140), restoration happens on the first `ha_departure_trashed` log. The subsequent rescan encounters the restored app and blocks before finalization. This test would therefore still pass if the new `departureTrashed` recheck at [hadepartures_scan.go:488](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:488) were removed.
+
+ **Failure scenario:** restoration after the rescan, during finalization, has no regression witness. **Fix:** restore through the existing `dr5HookedStore` on the final edges GET, following [hadepartures_dr5_test.go:685](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_dr5_test.go:685). Assert that the hook fires, the gate logs revocation, and the edges record remains. **Fault family:** discharge evidence must remain valid immediately before edges deletion.
+
+- **P3 — Task 2: the “normal departures read nothing” comment is too broad.** [hadepartures_scan.go:410](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:410) assumes every live app has a local route. Live hosts outside this box’s pool do not. `ScanPass` calls `trashed` before checking adoption eligibility, so these hosts now incur a marker GET, memoized per app per pass.
+
+ **Scenario:** the existing DR-5 named-pool hosts on a shared-pool-only box take this path without being trashed. **Fix:** narrow the comment to hosts with a matching local route and document the additional reads for other hosts. **Fault family:** request-cost documentation must match the executed path. Keep this on the follow-up list.
+
+Task assessments:
+
+| Task | Assessment |
+|---|---|
+| 1 — Shared rule | Approve. Matches reconcile’s marker-present/production-clear decision, including nil keys. Fleet drain retains its capable-survivor and movability gates. |
+| 2 — Departure scan | Implementation approved; witness correction above required. Lock identity and expiry checks remain. Matching local routes retain the adoption path. The finalization gate rereads trash state and revokes restored discharges. |
+| 3 — Drain acknowledgement | Approve. A verified deterministic group reference and enrolled departure are required. Enrollment requires termination proof. Fixed, unknown and self references fail closed; atomic lookup handles late controller arming. |
+| 4 — Close-lost | Approve. Listing is journaled before closure; failure leaves the transaction open. Missing validated references retain the previous closure path. No edges deletion is introduced. |
+
+The incident witness uses production departure wiring and preserves the pre-fix stall case. Drain witnesses combine that controller with simulated peer acknowledgements. The restore witness needs the correction above.
+
+Census decisions for the specified tip:
+
+| Unit or envelope | Verdict and evidence |
+|---|---|
+| `Engine.closeLost` | **Approve** — [roll.go:1557](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/grouproll/roll.go:1557), through line 1642: operator-side listing and journal reads; no bucket write. |
+| `runAgent` | **Approve** — [agent.go:1329](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/agent.go:1329): callback wiring only; existing authority disposition retained. |
+| `Controller.unservedRevoked` | **Approve** — [hadepartures_scan.go:479](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:479): restores revoke discharge; failures retain work. |
+| `armHADepartures` | **Approve** — [hadepartures_wiring.go:113](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_wiring.go:113): existing deployment store and reconcile release key. |
+| `Controller.ScanPass` | **Approve** — [hadepartures_scan.go:235](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:235), through line 395: identity, expiry and independent rescan preserved; no lock mutation for trashed hosts. |
+| `Controller.complete` | **Approve** — [hadepartures_scan.go:732](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:732), through line 869: conditional deletion remains behind revalidation; changed count excludes discharged hosts. |
+| New `Controller.trashed` | **Approve**, accepted-legacy — [hadepartures_scan.go:415](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:415): local route lookup and bounded existing app-state reads; errors return false. |
+| `internal/grouproll` envelope | **Approve** — [roll.go:1592](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/grouproll/roll.go:1592), helper through 1642; [text.go:29](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/grouproll/text.go:29). No new root authority. |
+| `internal/host` envelope | **Approve** — units above plus [PeerDeparted:528](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_scan.go:528), [armedPeerDeparted:77](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadepartures_metrics.go:77), and [publishAndAck:582](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/host/hadrain.go:582). Termination proof remains required. |
+| `internal/provision` envelope | **Approve** — [reconcile.go:327](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/provision/reconcile.go:327): equivalent shared-helper substitution. |
+| `internal/release` envelope | **Approve** — [trash.go:102](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-1192/internal/release/trash.go:102), through line 127: existing marker and signed-flag readers; no new filesystem or executable input. |
+
+`git diff --check` passed. Targeted Go tests could not start: the read-only sandbox refused creation of Go’s build directory. Runtime and census-test results remain unverified. No files were changed.
+
+Apply the P2 correction without reopening review, under the brief’s stopping rule.
+
+**READY AFTER FIXES**
\ No newline at end of file
diff --git a/internal/host/hadepartures_scan.go b/internal/host/hadepartures_scan.go
index 76d298ede..69edfbe72 100644
--- a/internal/host/hadepartures_scan.go
+++ b/internal/host/hadepartures_scan.go
@@ -408,10 +408,11 @@ const departureUnserved = "unserved"
const departureTrashed = "trashed"
// trashed reports whether h's app is TrashRetired. It asks only when this
-// box holds no route for the host (a live app's route is always minted
-// here, so normal departures read nothing), and memoizes the answer per
-// app for one pass in memo. Any read failure answers false: the host keeps
-// the departure as before.
+// box holds no route for the host: a host this box serves reads nothing.
+// A matched host outside this box's pools (one DR-5 may find unserved) has
+// no route here either, so it costs the marker read (and, when a marker is
+// present, the flag read), once per app per pass, memoized in memo. Any
+// read failure answers false: the host keeps the departure as before.
func (c *Controller) trashed(ctx context.Context, h provision.DepartureHost, memo map[string]bool) bool {
if c.cfg.TrashRetired == nil || h.Account == "" || h.App == "" {
return false
diff --git a/internal/host/hadepartures_trash_test.go b/internal/host/hadepartures_trash_test.go
index 278b1d655..843616d4d 100644
--- a/internal/host/hadepartures_trash_test.go
+++ b/internal/host/hadepartures_trash_test.go
@@ -155,3 +155,33 @@ func TestDepartureTrashedAppRestoredBeforeDelete(t *testing.T) {
t.Fatal("A's edges file retired after the restore")
}
}
+
+// A restore that lands during the finalize, after the rescan discharged the
+// host and while the edges read is in flight, is caught by the finalization
+// gate (Astra R1 P2): the departure goes back to a walk and A's edges record
+// stays. Removing the gate's trashed recheck fails this test.
+func TestDepartureTrashedAppRestoredAtTheGate(t *testing.T) {
+ x := newDR5Rig(t, dr5Options{})
+ withTrashedHost(t, x)
+ fired := false
+ hooked := &dr5HookedStore{Store: x.store, key: x.edgesKey, hook: func() {
+ if err := release.RestoreApp(t.Context(), x.store, "bab", "g6x"); err != nil {
+ t.Error(err)
+ }
+ fired = true
+ }}
+ x.c.cfg.OpenStore = func(context.Context) (release.Store, error) { return hooked, nil }
+ doneA, _ := x.run(t, 5*time.Minute, nil)
+ if !fired {
+ t.Fatal("the finalize never read A's edges file")
+ }
+ if doneA != 0 || x.gone(t, x.edgesKey) {
+ t.Fatalf("A finished at T+%s although its trashed host was restored before the delete", doneA)
+ }
+ if !slices.ContainsFunc(x.logs, func(l string) bool {
+ return strings.HasPrefix(l, "ha_departure_unserved_revoked ") && strings.Contains(l, "host="+trashedHost)
+ }) {
+ t.Fatalf("the gate did not revoke the trashed host: %q", x.logs)
+ }
+ x.trashedUntouched(t)
+}
diff --git a/internal/provision/testdata/plan14-root-reads-ha-1192.tsv b/internal/provision/testdata/plan14-root-reads-ha-1192.tsv
index 81cd56af4..63d8b2eb0 100644
--- a/internal/provision/testdata/plan14-root-reads-ha-1192.tsv
+++ b/internal/provision/testdata/plan14-root-reads-ha-1192.tsv
@@ -15,6 +15,6 @@ internal/host/hadepartures_scan.go Controller.trashed legacy accepted-legacy acc
internal/host/hadepartures_scan.go Controller.ScanPass legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1b3b-t;basis=B4: Read authoritative pre-filter inventory, exact canonical lock revisions through one page reader, local scan checkpoints and adoption receipts. Persist source identity before the sole AdoptHost importer; validate later successor identity/lifetime/generation and require a fresh full zero-match rescan. Unknown state, unsupported hosts and missing previously matched locks refuse completion. No process launch or tenancy expansion. Preserve checkpoints across walks of identical record bytes; persist the current inventory generation separately and recheck source freshness/completeness before every page and deletion. Placement changes cannot filter the lock census. Fix r1/P15: classify legacy and unrelated locks as zero only before any D match; keep strict successor checks for previously matched hosts and hold malformed HA identities. Compare read start to expiry. Resume authority-complete deletion without rescanning unchanged inventory; persist evidence and scan errors with bounded retry. B4 fix r2: Inventory-only waits request the existing hourly page only after observed evidence is older than ChangeIndexBackstop plus 10 percent. Freshness and completion gates are unchanged; no new read. B5: Route the unchanged AdoptHost callback through measured telemetry; no new authority or lock read.;rev3=census-ruling-region-ha-p3b;basis=Gate and register the existing departure scan with admission before any work. Existing registry/object reads remain, closed members do not import, and shutdown cancels/joins registered work; no new root input.;rev3=census-ruling-region-ha-g2r-fixes;basis=W3: when a departure is blocked only on inventory freshness, signals the bounded early backstop round (global 60 s spacing, three per evidence) instead of waiting for the 30 min backstop. FreshAfter/I3 gates unchanged; no walk inside the step; no new read.;rev3=census-ruling-region-ha-g3-fixes;basis=Track current record revisions across inventory publications; separate lease waits from blockers and persist Cursor as zero for rollback. Drop removed records from coverage while retaining adoption or validated-successor gates for current hosts. Use the bounded lock-prefix listing only after validating every current host prefix; preserve per-host reads for known duties and fall back to the existing 32-host scan when listing evidence is unavailable. Cache listing evidence only in this process under scanMu, invalidate it on blocked work or inventory changes, and permit 128 reads with proven listing coverage. Added reads include departure LastError, host scan state and registry Hosts; the new remote read is a bounded LIST of the configured lock prefix in the existing data bucket.;rev3=census-ruling-region-ha-dr5;basis=BASIS AMENDED by spec 7.5 (DR-5, approved by agent manager 8a3d302 for the region HA standing approval): the B4 completion gate "adoption or validated successor" becomes "adoption, validated successor, or unserved discharge". A host may be discharged unserved only when (1) its lock is a valid release marker naming the departed box or a held lock whose expiry this box read as passed, (2) this box would adopt it but for the pool (placement, HA, lifetime, kind and sidecar rules, not denied), and (3) the complete in-memory departure view shows no in-scope box that serves or may serve the pool, other than group members with a departure enrolled in this box journal (fixed refs never count as gone; unknown served_pools blocks). Every unserved discharge is rechecked at one finalization gate immediately before the conditional edges delete. An unserved host is never imported and its lock is never written, so no lease authority moves; the full zero-match rescan still runs, with unserved hosts the only allowed matches. Inputs: served_pools comes from edges files that only box roles write (already trusted by this scan for identity and by placement); a box agent that lies can at most let a departure finish without import, which it can already cause by deleting edges files with its own role. No new remote read; reads Hosts/Rescan/Result from the local journal. The rescan is due at once.;rev3=census-ruling-ha-1192;basis=records a matched host whose app is TrashRetired, with a released or expired lock, as result "trashed" (no import, lock untouched) instead of adopting it; only reads added are the trash marker and production flag, and only when the local registry has no route for the host registry:Cursor@2032,registry:Cursor@2122,registry:Cursor@9546,registry:Generation@2094,registry:Generation@8811,registry:Hosts@2306,registry:Hosts@2326,registry:Hosts@3357,registry:Hosts@3977,registry:Hosts@4045,registry:Hosts@6053,registry:Hosts@6440,registry:Hosts@7147,registry:Hosts@7259,registry:Hosts@7498,registry:Hosts@8256,registry:InventoryGeneration@1913,registry:LastError@2902,registry:Lifetime@4006,registry:NotBefore@2191,registry:NotBefore@3905,registry:NotBefore@4378,registry:NotBefore@4419,registry:NotBefore@4444,registry:NotBefore@6021,registry:NotBefore@6410,registry:NotBefore@7111,registry:NotBefore@7177,registry:NotBefore@9220,registry:NotBefore@9274,registry:NotBefore@9599,registry:Observed@5592,registry:Observed@5739,registry:Observed@6293,registry:Observed@6327,registry:Phase@1448,registry:Phase@2049,registry:Phase@2384,registry:Phase@5309,registry:Phase@634,registry:Phase@689,registry:Phase@729,registry:RecordDigest@3287,registry:RecordDigest@4340,registry:RecordDigest@6350,registry:Rescan@2137,registry:Rescan@4320,registry:Rescan@5478,registry:Rescan@7678,registry:Rescan@8997,registry:Rescan@9385,registry:Rescan@9438,registry:Result@5991,registry:Result@6385,registry:Result@7226,registry:Result@7464,registry:Result@8222,registry:Unresolved@2156,registry:Unresolved@3811,registry:Unresolved@8280,registry:Unresolved@8868,registry:Unresolved@9113,registry:Unresolved@9396,registry:Unresolved@9562,registry:Version@7954,registry:Visited@2073,registry:Visited@2219,registry:Visited@3262,registry:Visited@3762,registry:Visited@3838,registry:Visited@3932,registry:Visited@8307,registry:Visited@9628,registry:Waiting@2175,registry:Waiting@9128,registry:Waiting@9203,registry:Waiting@9417,registry:Waiting@9582,whole:HADeparture@10014,whole:HADeparture@1111,whole:HADeparture@1230,whole:HADeparture@1415,whole:HADeparture@1704,whole:HADeparture@2517,whole:HADeparture@2714,whole:HADeparture@2870,whole:HADeparture@3005,whole:HADeparture@350,whole:HADeparture@392,whole:HADeparture@5589,whole:HADeparture@6941,whole:HADeparture@7922,whole:HADeparture@8058,whole:HADeparture@8414,whole:HADeparture@914,whole:HADeparture@9845,whole:HADepartureHostScan@2308,whole:HADepartureHostScan@2328,whole:HADepartureHostScan@3359,whole:HADepartureHostScan@3979,whole:HADepartureHostScan@4047,whole:HADepartureHostScan@4081,whole:HADepartureHostScan@6055,whole:HADepartureHostScan@6071,whole:HADepartureHostScan@6112,whole:HADepartureHostScan@6442,whole:HADepartureHostScan@6458,whole:HADepartureHostScan@7149,whole:HADepartureHostScan@7165,whole:HADepartureHostScan@7261,whole:HADepartureHostScan@7277,whole:HADepartureHostScan@7500,whole:HADepartureHostScan@7516,whole:HADepartureHostScan@8258,whole:HADepartureHostScan@8274,whole:HADepartureScan@7859,whole:HADepartureScan@8802,whole:HADepartureScan@9779,whole:HADepartureVisit@2075,whole:HADepartureVisit@2221,whole:HADepartureVisit@3264,whole:HADepartureVisit@3764,whole:HADepartureVisit@3782,whole:HADepartureVisit@3840,whole:HADepartureVisit@3858,whole:HADepartureVisit@3934,whole:HADepartureVisit@3952,whole:HADepartureVisit@8309,whole:HADepartureVisit@8327,whole:HADepartureVisit@9630 d11e9de047f7f5dde6a4dbab412fea5c061b0d8c4fbb018685f1705ab5859693
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.;rev3=census-ruling-region-ha-dr5;basis=DR-5: one finalization gate immediately before the conditional edges delete revalidates unserved discharges (unservedRevoked: local view, policy, journal only); on failure clears DeleteUncertain and resets to a fresh walk before any delete. The completion log counts imported hosts only. No new remote read.;rev3=census-ruling-ha-1192;basis=excludes "trashed" hosts from the recovered count, as it does "unserved" registry:DeleteUncertain@3813,registry:DeleteUncertain@4544,registry:DeleteUncertain@4997,registry:EdgesETag@1894,registry:EdgesETag@2906,registry:Hosts@5848,registry:InventoryGeneration@1846,registry:PermissionAlerted@2426,registry:PermissionAlerted@3559,registry:PermissionAlerted@5141,registry:PermissionAlerted@5545,registry:PermissionAlerted@841,registry:PermissionAlerted@883,registry:Phase@1002,registry:Phase@1042,registry:Phase@1538,registry:Phase@262,registry:Phase@3692,registry:Phase@5259,registry:Phase@680,registry:Phase@950,registry:Phase@967,registry:Rescan@4574,registry:Result@5863,registry:Result@5896,registry:Version@665,registry:Visited@4595,whole:HADeparture@2846,whole:HADeparture@315,whole:HADeparture@442,whole:HADeparture@4423,whole:HADeparture@5671,whole:HADeparture@6057,whole:HADepartureHostScan@5850,whole:HADepartureScan@1718,whole:HADepartureScan@4426,whole:HADepartureScan@643,whole:HADepartureVisit@4597 f33013ac30442297b3e54f41180c4216262080cbeb373f9d1617ab7c47b64a2a
@coverage internal/grouproll e70f2bf825d2c82b12d0fa20caf8188428bfee463663655e6e1f7b2fa1b031ce
-@coverage internal/host 5fe58660833e47e79594f4747bb39c179f24cce1bf45a5ac2ba667ad91eed6b2
+@coverage internal/host aefe5e496e8a72699a4d7b0219c27347a825ba1995bac33f21cc5fad9d4704a6
@coverage internal/provision 1e4a77fec6e7c6484abaf60c76e6b4729615e161b43fae792c9047b201ae87f0
@coverage internal/release 7d86684d77c3db85e2da19596bdd73110b21d4923c280786b6068141d3fa62d3