carlos / platform Public

plan: region HA G5 held requests (draft for review)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 684f80d4e22219228fc7a51ac9166ab717d5a4d8 parent 985c8d4
1 file changed, +87 −0
  • docs/superpowers/plans/2026-11-08-region-ha-held-requests.md +87 −0

CI passed — run details

Intent

Attributed to this commit: 30.3 g CO₂e (3,030,220 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-region-ha-held-requests, 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/plans/2026-11-08-region-ha-held-requests.md b/docs/superpowers/plans/2026-11-08-region-ha-held-requests.md
new file mode 100644
index 000000000..f099fd141
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-08-region-ha-held-requests.md
@@ -0,0 +1,87 @@
+# Region HA G5: held requests during a planned handover
+
+Branch `design-region-ha-held-requests` from origin/main 9622c65a.
+Spec: `docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md` §25 (rev 6.6).
+**Not to be built before Paul approves §25.** Review budget: three Astra rounds for spec and plan together. Stop at the first round with no P1. A family that draws a P1 twice gets cut or becomes an invariant (stopping rule 2).
+
+## Problem
+
+A planned member replacement answers 503 for every awake HA host it held, from SIGTERM until a peer re-reads the lock after the marker and restores the host (§25.1). The edge closes its listeners before any release (`internal/edge/edge.go:4855-4858`). Peers mark the box suspect and answer `Retry-After: 10` (`forwardha.go:376-380`, `hacache.go:27-41`). `errShuttingDown` falls through to a 503 with no `Retry-After` (`activator.go:6603-6611`).
+
+## Global constraints (binding on every task)
+
+- **I1 unchanged.** Only `hafresh.DecideAcquire` (`internal/hafresh/acquire.go:77-115`) authorizes an acquire. No notice, header or hold reaches it as an input.
+- **Unplanned paths unchanged.** A lost lease (`haleaseloss.go`), a suspect holder that is not marked departing, and every refusal that exists today keep their answers byte for byte. A test pins each one.
+- **No replay after possible delivery** (spec I9): hold only on the three triggers in §25.5, and buffer only within the bounds.
+- **No new polling.** The only S3 reads added are the fallback lock reads in §25.5, which are per handover. Tests count store calls.
+- **Census.** Any task that touches a census-pinned site (edge shutdown order, the hop answer path, units) carries a census card and cross-family approval on #280 before merge.
+- **Local verification:** run only the changed packages with `-run` locally. CI runs the full suite.
+
+## Task 0: `errShuttingDown` gets a real answer (independent; can merge first)
+
+- In `serveWakeError` (`activator.go:~6534-6611`), map `errShuttingDown` to the admission "unavailable" 503 with `Retry-After: 10`, and on a forwarded HA hop to `X-Carlos-Holder: none`. Stop logging it as a wake failure.
+- Test: a request waiting on a stopping entry during `Shutdown` gets that answer, not "instance failed to wake".
+
+## Task 1: handover mode on the departing box (§25.3)
+
+Files: `internal/edge/edge.go` (shutdown block), `internal/edge/shutdown.go`, `internal/activator/activator.go` (`Shutdown`, `begin`), new `internal/activator/handover.go`, `internal/host/agent.go` (shutdown order).
+
+1. Move `http.Server.Shutdown` after the activator's handover. The edge keeps accepting until `Service.Handover(ctx)` returns, or until D - 10 s. Then it runs `Shutdown` with what remains of the deadline.
+2. Handover state per host: `inflight-drain` (up to 10 s), then `releasing`, then `released(marker gen | none, successor)`.
+3. The edge answers a verified hop for a host in any handover state with 503 and `X-Carlos-Handover: pending`, before `act.ServeHTTP` and before admission (`admissionRefuses`, `edge.go:2068`). That ordering is the "not delivered" proof, and a test pins it.
+4. Direct requests for such a host are held through Task 3's queue, with this box as first box.
+5. Successor choice: `boxchoice.ChooseRoomiest` over the cached eligible serving set without self, or HRW for always-on workers.
+6. Strip `X-Carlos-Handover` from app responses beside `stripAppHolder`.
+7. Tests: listeners still accept during the release; the pending answer comes before the activator for every route kind; the in-flight bound is 10 s; a host with no marker gets `marker: none`; a deadline that runs out still closes.
+
+## Task 2: HA notices (§25.4)
+
+Files: new `internal/edge/ha_notice.go` (modelled on `burst_notice.go:28-60`), `internal/host/edgesfile.go` (`ha_notices` field), `internal/activator/hacache.go` (departing state, notice-fed entries).
+
+1. `/.carlos/ha-notice`, sealed and signed with the mesh key, answered ahead of routing. Its own rate bound. Batches of up to 200 hosts, at most every 200 ms per peer.
+2. Kinds: departing, released, wake. Validate every ref against view(region) and drop anything else.
+3. Holder cache: a `departing` box state until its deadline. A connect failure to a departing box reports `ForwardHandover`, not `ForwardUnreachable`, and does not raise `OnDepartureSuspect`.
+4. A released notice sets a positive entry for the successor and signals Task 3's queue.
+5. A wake notice on the successor runs the forwarded-wake path (HA acquire, wake, never forward). A test proves it cannot acquire without a marker.
+6. Tests: seal and replay refusal; a notice from a box out of view is dropped; a box without `ha_notices` gets none; a mutation where a notice feeds `DecideAcquire` fails a test.
+
+## Task 3: the first-box hold (§25.5)
+
+Files: new `internal/edge/hahold.go`, `internal/edge/forwardha.go` (tee body, new outcomes), `internal/edge/backhaul_holder.go` (cross-region hold).
+
+1. Body tee for HA forwards: a bounded replay buffer (1 MiB per request, 64 MiB per box). The request is replayable only if the whole body fitted.
+2. Triggers: a pending answer; a connect failure to a departing box; a direct request on the departing box. Nothing else holds. A table test lists every existing 503 and asserts it is not held.
+3. Per-host queue: 64 per host, 1,024 per box, 15 s from the first refusal. Over a bound, today's answer.
+4. Release on a released notice, on the box's own release (departing box), or on the fallback lock read at 2, 4 and 8 s, coalesced through `holderCache.resolve`. A release goes through `forwardHAObserved` once, at most two attempts in all.
+5. Methods: any method with a definite non-delivery and a full buffer; after a post-connect failure, only bodyless GET, HEAD, OPTIONS or an un-switched upgrade (`backhaul_holder.go`'s existing rule).
+6. Held-stream requests (#432): held like a GET, released from memory, never wake.
+7. Cross-region first box: honour pending, one release hop at 4 s to another in-view box of the region.
+8. Metrics and log lines: `ha_hold_started`, `ha_hold_released{by=notice|own|read}`, `ha_hold_expired`, the longest hold per host.
+9. Tests: every bound; a POST with a body replays exactly; a POST after a mid-body reset is not replayed; reads are coalesced; the store call count per handover.
+
+## Task 4: simulation (spec §21.1, §25.10)
+
+Extend `internal/sim/regionha` with planned terminations, notices (lost, delayed, reordered), held requests and the connect-phase failures. Add I9 and I10, plus the five mutations in §25.10. Run one 3,000-seed sweep per revision, serially, at nice 19.
+
+## Task 5: root-runner witness `TestRootHAHandoverHold`
+
+Extends `internal/host/haterminate_rootrunner_linux_test.go`'s apparatus (`~/.cache/region-ha-graceful/witness.py`): two real agents, real `TerminateInstances`, and a client driving GET, POST with body and SSE through both boxes. Pass: 0 non-2xx; holds within bound; acknowledged writes present after; the departing box's listener open until its handover lines. Budget: about 10 live runs.
+
+## Task 6: `region-group-roll.py replace` and roll changes (§25.8)
+
+1. New `replace` transaction: preflight (shape, health, per-member version floor), `TerminateInstanceInAutoScalingGroup` without decrement, watch (handover lines, departure done within §7.5's bound, replacement admitted, locks naming the old ref resolved), journal and report.
+2. Roll: add the floor check to preflight and the handover lines to verify.
+3. Fakes and argv tests in the existing style, plus one live attended call before any window, with the operator's real transport (P3b-2 lesson).
+4. Runbook text in `docs/region-ha-runbook.md` for resize: `instance_type`, apply, re-pin `group_launch_template_version`, then `replace` per member. The text goes through Paul's copy review on its own docs branch.
+
+## Task 7: spec, census and CI
+
+Update §25 with anything the build changes. Census cards for the edge shutdown order and the hop answer path. Run CI on the branch, then the branch review (Opus, cross-family against Astra implementers).
+
+## Dev witnesses (a dated card for 8a3d302 after release; not part of the build)
+
+W0 hard kill control, W1 planned terminate, W2 roll, W3 resize (t4g.small to t4g.medium), each as §25.10 states, on the dev IE group with two HA hosts awake on the member and the probe at about 3 requests a second. DR-4's lock-free rule stays in every card until W1 to W3 pass on a release with §25 on every member.
+
+## Order
+
+Task 0 first (independent). Then 1 and 2, which share the activator handover state. Then 3, then 4 and 5. Task 6 can run beside 3 to 5. Then 7. Release, then the card.