plans: P1b-3b Opus review round 1 (NOT READY)
2 P1 (one I3 family: lock naming / evidence ageing), 7 P2, 7 P3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+87
−0
docs/superpowers/plans/REVIEW-REGION-HA-P1B3B-R1.md+87 −0
diff --git a/docs/superpowers/plans/REVIEW-REGION-HA-P1B3B-R1.md b/docs/superpowers/plans/REVIEW-REGION-HA-P1B3B-R1.md| new file mode 100644 |
| index 000000000..859adc03d |
| --- /dev/null |
| +++ b/docs/superpowers/plans/REVIEW-REGION-HA-P1B3B-R1.md |
| @@ -0,0 +1,87 @@ |
| +# Review: region HA P1b-3b plan (duties, departure scan, SQS consumer), round 1 of 3 |
| + |
| +Reviewer: Claude Opus 5.5, independent. Plan `docs/superpowers/plans/2026-11-03-region-ha-p1b3b-duties.md` rev 1 (bc7eeb04), brief `REVIEW-BRIEF-REGION-HA-P1B3B-R1.md`. Code read at origin/main c6304f2d (worktree 9a064ebe plus the c6304f2d diff to `internal/edge/{homemap,wakeplacement}.go`). Authorities: spec rev 6.1, P1b-3 parent plan (outline + 5B), P3 plan on `origin/region-ha-p3-group` (:27, :285 "Termination-start latch / I3,A1", :288 drain row). |
| + |
| +**Verdict: NOT READY** (2 P1, 7 P2, 7 P3). |
| + |
| +Round history carried: this is round 1 of this plan. Parent P1b-3: R1 NOT READY, R2 READY AFTER FIXES, closed. Both P1s below are in one fault family, **I3: a departed box's duties that depend on lock naming / termination evidence**. If round 2 produces another finding in that family, stopping rule 2 applies (offer refuse / cut / one enforced invariant). The single fix suggested under P1-1 closes both. |
| + |
| +Settled decisions (N-HA9, N-HA11, N-HA12, N-HA14, no duty-file transfer) are not re-argued. Neither P1 asks for an early take or a new poll. |
| + |
| +## Citation check |
| + |
| +Every file:line in the file map was opened at 9a064ebe. All land on the named construct or within two lines of it, with these exceptions: |
| +- `internal/host/agent.go:485`: `confirmer := haOwnerConfirmer()` is at :487 (comment at :485). Harmless. |
| +- `internal/host/runexec.go:109` is `runFinishOurs`, not the picking rule the plan describes. The pick is in `runrelay.go:68`/`runs.go:229`, which the plan also cites. Harmless. |
| +- `internal/edge/homemap.go` gains 5 lines before :165 and 11 in total at c6304f2d, so :265/:420/:519/:1221 shift by +5 to +11 on main. `wakeplacement.go:133` now holds the `placementNull` check (see P3-1). |
| +- `changeIndexAttempts = 4` (`internal/release/changeindex.go:31`) confirms the plan's "four total attempts". |
| +- `Confirmer.Terminated` is at `confirm.go:112`, `FromEvent` at `fence.go:117`, `Enroll` at `boxid/verify.go:102` and `DecideAcquire` at `hafresh/acquire.go:72`. All correct. |
| + |
| +## P1 |
| + |
| +**P1-1 — Imported *held* hosts depend on termination evidence that EC2 forgets within about an hour. Future-due duties become permanently undeliverable (I3; I4 for the host).** |
| +Plan §"Persistence, import and completion" ("For a terminated **held** lock … The later actual duty still acquires normally under N-HA9"), B4 Step 3 and §"Open questions" ("EC2 evidence aged out is an operator fault"). |
| +After the scan imports a host D held, the lock still names D (expired). The adopter takes the host over only when the duty is next due, through `AcquireHAForDuty` → `DecideAcquire` → `Proofs.OwnerTerminated` (`internal/hafresh/acquire.go:112-115`). That calls `Confirmer.Terminated` (`internal/termfence/confirm.go:112`). Its positive cache lives 24 h and only in memory (`confirm.go:16`, `ConfirmPositiveTTL`), and the code itself says "AWS forgets it within about an hour" (`confirm.go:15`). `SameAccountTerminated` refuses `!o.Found` ("absence is not termination", `confirm.go:38-39`). |
| +So the takeover is refused forever in three cases: |
| +- a host with a once-timer or `next_due` more than 24 h out; |
| +- any such host after an agent restart (for example a release roll) more than about 1 h after termination; |
| +- any visitor wake on a box that never confirmed D. |
| + |
| +This is the normal case, not an operator fault. B5's liveness claim ("all durable work must eventually deliver within event/age + expiry + …") covers only work already due, so the witnesses cannot catch it. |
| +*Fix (one place, inside AcquireHA, no early take):* once the scan has imported a held host and its lock has expired, the scanner performs the takeover immediately, while its evidence is fresh, through the existing HA acquire. It then releases at once with an **unclean marker naming itself**, starting nothing. This uses the existing `releaseWithMarker`/`uncleanMarker` path (`internal/lease/ha.go` above :130). From then on, any box may take the host from the marker without EC2 evidence, and I2 holds (an unclean marker allows no local reuse; the restore comes from S3 wake state). Cost: about 1G+2P per held host per departure. Add an I6 witness: a held host with a once-timer due at T+48 h, plus a process restart, delivers without a visitor. At minimum, a journaled positive confirmation must seed `Proofs.OwnerTerminated` durably (terminated is terminal, so this is safe). That alone leaves other boxes' visitor wakes stuck, so the marker conversion is preferred. |
| + |
| +**P1-2 — Adopted-but-not-yet-woken hosts are invisible to the scan of the adopter's own later departure (I3; spec §7.1 vs §7.4).** |
| +The plan's §"Open questions" (last paragraph) defers this: "Repeated failures after completion while adopted hosts still name an earlier dead releaser need a separate explicit coverage witness". |
| +§7.1 makes the adopter the duty owner of an asleep host. The plan's scan, however, matches only lock owner or marker releaser (`MatchesDeparture(view, departure Box, lifetime)`, B5 Interfaces; B4 Step 1). An adopted host's lock still names the earlier dead box E. When the adopter D later dies, no scan matches that host, and its timers exist only in D's registry. They are lost without any error. |
| +This is ordinary G2 group life, not a contrived double fault: replacements are sequential, and on a pair the sole survivor's later replacement meets exactly this. The plan states the gap but still claims I3 coverage in its Self-review ("§7.4/I3 → B2/B4/B5"). That is unsafe to land as T's acceptance. |
| +*Fix:* the P1-1 conversion (after import, take the lock and leave the adopter's unclean marker) makes every adopted host name its current duty owner. The spec's owner/releaser match then becomes complete without a roster. Otherwise, ask Paul for a ruling to cut or refuse this case up front, and remove the I3 coverage claim. |
| + |
| +## P2 |
| + |
| +**P2-1 — T's rule for legacy native sidecars is underspecified, and as written it blocks or misleads completion (I3).** Scope §T and B4 Step 1 (`TestDeparturePoolCoverage … native sidecar is unsupported`). |
| +Sidecars are legacy (`internal/activator/hawake.go:74-79`). A legacy release leaves no marker, so an asleep sidecar's lock cannot name its releaser. The scan therefore cannot tell whether D slept a given sidecar. The plan never states which sidecar records make a departure "unsupported": every sidecar in the region, those in D's pools, or only those with a legacy lock naming D's ref. If it is any of the first two, every departure in a scope holding any hibernating sidecar never completes. Then the edges file stays, and the unacked message redelivers every 120 s for the queue's 14-day retention (`infra/modules/region-host/main.tf:837`), with hourly C3 pages. If it is the third, the plan silently drops asleep sidecars' due wakes. |
| +State the exact predicate. Say what T does with HA instance imports in a departure that also has unsupported sidecars (import them, keep the evidence, alert once). Make the preflight that "establishes the restriction" executable (refuse to start the consumer, or emit C8, when the scope holds hibernating native sidecars), not prose on a card. |
| + |
| +**P2-2 — No data source is named for HRW "compatible serving" pool eligibility for never-woken hosts (I3, never-woken row of §7.1).** §"Duty selection" ("must support sidecar pool eligibility without using public Hosts entries as a roster"). |
| +Edges files publish only `ServesSharedPool`/`AcceptsInbound` (`internal/host/edgesfile.go:327-328`) and no pool list. P1b-3a decides peer eligibility for a host from `f.Hosts[host]` (`internal/edge/wakeplacement.go` ~:160-163 on main). That is exactly the source this plan forbids. If HRW runs over boxes that do not serve the pool, the winner has no route, every other box defers, and a never-woken hapair host's ticks never deliver. |
| +Name the source. Either reuse the per-host `Hosts` home entry, as 3a does (instances only; sidecars are excluded from edges files, `edgesfile.go:481-500`), or add a published served-pools field with its schema/census cost. Add a witness: hapair host, one box outside the pool. |
| + |
| +**P2-3 — "Absent from a complete view → delete as irrelevant" can discard a real departure (I3; brief item 2).** §"Scope, evidence and inventory" ("For a queue iid absent from a **complete** known deployment view, delete as irrelevant"). |
| +Edges files are deleted by operators today: the console tells them to "delete its edges record (control/edges/<label>.json)" for a retired box (`internal/console/apisystemgeoip.go:336`). If D's edges file is gone before its termination event is processed, the message is acked as irrelevant, no scan runs, and the age fallback cannot fire because there is no file. D's released hosts' timers are lost. |
| +Spec §9.1 says a message is irrelevant when the instance "is not a box of this deployment", and box records are immutable (`internal/boxid/record.go:36-52`). Decide irrelevance from a durable local ref↔iid map of verified box records, plus a bounded `control/boxes/` read on an unknown iid, budgeted, rather than from the current edges view. Keep the edges-ETag requirement only for the delete step. |
| + |
| +**P2-4 — There is no completion rule when a receiver does not serve every pool D served (I3 liveness).** B4 Step 3 ("Never call an out-of-pool match complete. Preserve the SQS message and edges for redelivery to an eligible box"). |
| +On fixed boxes each module's rule forwards every termination in the account and region to that box's own queue (`main.tf:835-853`), so every survivor receives its own copy. Take survivor B (shared only) and survivor C (shared+hapair). C completes and deletes the edges file. B stays incomplete forever: it pages C3/C7 hourly and its message redelivers for 14 days. "Known absence alone is never proof" forbids B from using C's deletion. |
| +Define per-receiver completion as: every match in pools this box serves is imported, and every other match is classified as covered by another in-view serving box. Only a box that has itself imported every match deletes the edges file. A box that completed only its own pools acks its own message. Add a two-receiver, two-pool witness. |
| + |
| +**P2-5 — The ordinary-restore "replay protection" could override authoritative S3 wake state under a newly taken lease (I3/I2 boundary).** §"Persistence…" ("Ordinary restore must not replay an older manifest over delivery progress made after adoption; use the same receipt/digest/revision rules"); B2 `TestHAAdoptThenOrdinaryRestore`. |
| +Delivery progress happens only while the box holds the lease, after `ImportWake` at `hawake.go:738`. The progress a box makes without the lease (non-owner 15-minute tick advances) is advisory and must lose. Comparing a local revision with an S3 manifest written by another box under a later lease is not a valid ordering, and it would keep stale local rows over newer registrations made by an interim holder. |
| +Restrict the revision/receipt CAS to adoption imports, which run without a lease. Under a freshly acquired lease, ordinary restore installs the manifest's wake state exactly, as today. Make the transaction atomic, but do not filter it. The witness: an interim holder registers a new once-timer, the adopter later acquires, and the new timer survives. |
| + |
| +**P2-6 — The edges deletion needs `s3:DeleteObject` on the deployment bucket, which the module on main denies when `store_bucket_prefix` is set (B4 completion; brief item 6/"no IAM change").** |
| +`infra/modules/region-host/main.tf:719-728` (`host_store`, count on `store_bucket_prefix`) has an explicit Deny on `s3:DeleteObject` for `${deployment_bucket_arn}/*`. Dev's `host_ie` sets that prefix: dev hit this on 2026-10-29 and it was hand-fixed live, so the live policy has drifted from tofu. A tofu-faithful survivor gets AccessDenied on the conditional edges delete and never completes. Worse, 5B Step 2 plans "a saved whole-root plan" to provision box C, and that apply would restore the Deny on sophie/leo, which also breaks legacy lease releases (the 2026-09-09 outage). |
| +Name the dependency, either the module fix (`region-host-store-deny`) merged and released, or the card proving the plan shows no Deny change. Add a B4 test that an AccessDenied on the delete stays pending, alerts once and never acks. |
| + |
| +**P2-7 — An inventory generation that predates D's last record adoption can certify completion (I3, scan before deletion).** §"Scope, evidence and inventory" (`Snapshot()` "complete … under one reconciled generation"); B4 Step 3. |
| +A host created shortly before D died can be minted and woken on D, with its wake state publishing a once-timer, before the survivors' reconcile has seen its record. Record walks ride the change index and its backstop (`agent.go:931-932`). A scan over that older generation completes, deletes the evidence, and never reads the new host's lock. |
| +Require the completing inventory pass to have *started* after the departure's evidence time (or after D's last edges publication time). That means waiting for one more ordinary pass, with no extra reads. Add a witness. |
| + |
| +## P3 |
| + |
| +- **P3-1 (home scope, c6304f2d):** DepartureView/Scope should reuse main's `placementNull` (`homemap.go` +165-171, `parseEdgesFile` +781-789) so an explicit `"placement": null` is malformed evidence, not the home scope. Add it to `TestDepartureHomeScopeAndPools`. Rebase the homemap line citations. |
| +- **P3-2 (budget):** the first-duty discovery after upgrade costs one lock GET per box per sleeping HA host with due work, a one-time burst of about B×N_due GETs. It is missing from the budget table. |
| +- **P3-3 (budget):** a stale-but-not-terminated peer (stopped or hung, never replaced) is re-described at the 300 s backoff ceiling indefinitely. Add a row (EC2 Describe is free, but give the log/alarm rate). |
| +- **P3-4 (config delivery):** fixed boxes do not read `hostenv.Optional` (`internal/hostenv/hostenv.go:71` is the group SSM allowlist). Name the fixed-box host.env delivery of `CARLOS_TERMINATION_QUEUE_URL` and its restart cost (a bare carlos-edge restart is about 11 s of tenant downtime). Without it, P3a admission on the fixed pair can never see Started. |
| +- **P3-5 (P3 interface):** Started cannot close sooner than the first empty long poll (up to 20 s). Say so for P3's restart-to-admission measurement, so nobody "fixes" it with WaitTimeSeconds=0 loops. |
| +- **P3-6 (future shared queue):** with VisibilityTimeout=120 and a held-lock expiry wait of up to 15 min, a shared group queue redelivers the message to every box, and each runs a full scan. Count that in the "Concurrent scanner" row, or document that receivers journal and ack only after completion, so a redelivered copy is the expected path. |
| +- **P3-7 (scan cost):** the per-host lock read goes through `lease.ReadLock`, which builds a new leaser client per call (`internal/lease/ha.go` ReadLock → `newLeaserClient`). Share one client per scan pass. |
| + |
| +## Brief items |
| + |
| +1. **I3 coverage:** with the fixes, released hosts are covered and duplicates/redelivery are retry-safe (H7). Held hosts with future-due duties fail (P1-1), adopted hosts on a second departure fail (P1-2), cross-pool completion is undefined (P2-4) and the late-record window is open (P2-7). |
| +2. **Evidence before scan / scan before deletion:** an event or a missing file is never treated as termination; the confirmer is required. The converse fault, where a missing file is treated as irrelevance, is P2-3. Deletion ordering is otherwise sound, apart from P2-6 and P2-7. |
| +3. **Start acknowledgment:** provider-neutral (`hadeparture` has no SDK import). It is honest: an empty receive counts, a construction failure is an error, a receive error before the first success leaves Started open. It is independent of drain and is exactly the `TerminationStarted` input P3 :285 asks for. No change needed beyond P3-4/P3-5. |
| +4. **One writer:** AdoptHost reads only the manifest and WakeItem and starts nothing. `AcquireHAForDuty` is a refusal-only callback over `classifyAndTake` (`internal/lease/ha.go:94-114`). No path found outside `lease.AcquireHA`. P1-1's fix must also go through that acquire. |
| +5. **Home placement:** handled explicitly (Global Constraints, `Scope.Placement:""`, `Known` bit, tests with dev-shaped records); P3-1 only. The drill does not change `CARLOS_REGION`. |
| +6. **Budget:** the formulas check out (540 GETs × $0.0004/1k = $0.000216; four index attempts; about 180 receives/h). Additions are in P1-1 (1G+2P per held host), P2-3, P3-2, P3-3 and P3-6. |
| +7. **Testability:** production wiring and root witnesses are well specified. Add I6 witnesses and mutations for P1-1 (future-due held host plus restart, no visitor), P1-2 (two sequential departures) and P2-7. |