carlos / platform Public

plan: held requests r3 (H1-H5)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev acfd5253582a20e41e7a53ae14152ed377f1787d parent 61e0b74
1 file changed, +42 −46
  • docs/superpowers/plans/2026-11-08-region-ha-held-requests.md +42 −46

CI passed — run details

Intent

Attributed to this commit: 35.8 g CO₂e (3,612,591 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
index 9b7044329..7fb7e59c9 100644
--- a/docs/superpowers/plans/2026-11-08-region-ha-held-requests.md
+++ b/docs/superpowers/plans/2026-11-08-region-ha-held-requests.md
@@ -1,8 +1,8 @@
# 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, section r2 after Astra round 1).
-**Not to be built before Paul approves §25.** Review budget: three Astra rounds for spec and plan together; round 1 is spent (NOT READY, 11 P1, all dispositioned in §25.12). Stop at the first round with no P1. A family that draws a P1 twice gets cut or becomes an invariant.
+Spec: `docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md` §25 (rev 6.6, section r3 after Astra rounds 1 and 2).
+**Not to be built before Paul approves §25.** Review budget: three Astra rounds for spec and plan together; rounds 1 and 2 are spent (NOT READY, 11 then 8 P1, all dispositioned in §25.12; four families repeated and are now invariants H1-H5 or refusals). Round 3 is final: a P1 there goes to Paul as options, with no round 4. Stop at the first round with no P1. A family that draws a P1 twice gets cut or becomes an invariant.
## Problem
@@ -12,83 +12,79 @@ A planned member replacement answers 503 for every awake HA host it held. system
- **I1 unchanged.** Only `hafresh.DecideAcquire` authorizes an acquire. A take request and an `X-Carlos-Handover` answer are never inputs to it.
- **Unplanned paths unchanged.** A lost lease, a suspect holder, a hard kill and every refusal that exists today keep their answers byte for byte. A table test pins each one.
-- **No unsafe replay (I9).** Replay only after an `X-Carlos-Handover` answer, or under §6.5's existing rule.
-- **No new polling.** The S3 work added is per drain (§25.9). Tests count store calls.
-- **Census.** Tasks that touch census-pinned sites (the hop answer path, `begin`, the roll tool, root verbs) carry a census card and cross-family approval on #280 before merge.
+- **No unsafe replay (I9, H2).** Replay only from a whole copy (at most 64 KiB, read before the first send) after an `X-Carlos-Handover` answer on a first attempt, or under §6.5's existing rule.
+- **No new polling.** The S3 work added is per drain (§25.10). Tests count store calls.
+- **Census.** Tasks that touch census-pinned sites (the front door in `ServeHTTP`, the hop answer path, the roll tool, root verbs) carry a census card and cross-family approval on #280 before merge.
- **Local verification:** changed packages only, with `-run`. 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`, plus `X-Carlos-Holder: none` on a forwarded HA hop. Stop logging it as a wake failure. Test: a request waiting on a stopping entry during `Shutdown` gets that answer.
-## Task 1: drain state and placement exclusion (§25.3 step 1, step 3)
+## Task 1: drain state, acknowledged withdrawal (§25.4 steps 1 and 4)
-Files: `internal/host/edgesfile.go`, `internal/host/group_admission.go`, `internal/edge/wakeplacement.go`, `internal/activator/haplacement.go`, `internal/activator/hacache.go`.
+Files: `internal/host/edgesfile.go`, `internal/edge/wakeplacement.go`, `internal/activator/haplacement.go`, `internal/activator/hacache.go`, new `internal/edge/hadrain.go`.
-1. A box-level drain state and `drained`, published in the edges file. Pick the field (existing `Draining`/`Drained` or a new one) after checking every reader of `control/edges` (spec §24's rule for a new reader). The existing per-entry `draining` used by db reads keeps its meaning.
-2. While draining, the box never acquires an HA lease, keeps tenant admission open, and routes as a first box.
-3. Placement on every box treats a draining box as local-denied, including §6.3 rule 1 (releaser reuse). Test: a clean marker naming a draining box sends the wake elsewhere.
-4. `drained` drops holder-cache entries naming the box.
-5. A draining box is never made suspect by `ForwardSilent`.
-6. Tests: an asleep host, a remote-held host, a waking host and an alias or metadata-only route on a draining box; the same on a fixed forwarder.
+1. A box-level drain state and `drained` in the edges file. Choose the field after a §24 reader table: it withdraws placement only, and name authority, admission and holder reachability are unchanged. The per-entry `draining` that db reads use keeps its meaning.
+2. Placement on every box treats it as local-denied, including §6.3 rule 1. `drained` drops holder-cache entries naming the box. A draining box is never made suspect by `ForwardSilent`.
+3. `/.carlos/ha-drain`: a signed hop. The receiver refreshes its fold of the asker's edges file and answers what it sees.
+4. Tests: a clean marker naming a draining box sends the wake elsewhere; a failed fold refresh answers "not seen"; fixed and cross-region receivers.
-## Task 2: holds on the draining box (§25.4)
+## Task 2: `MoveState`, the one front-door decision (H1, §25.5)
-Files: `internal/activator/activator.go` (`begin`), new `internal/activator/handover.go`, `internal/edge/forwardha.go`.
+Files: `internal/edge/edge.go` (`ServeHTTP`), new `internal/activator/handover.go`, `internal/edge/forwardha.go`.
-1. Per-host move state: `holding` → `releasing` → `taken(holder)` | `left(reason)`. It sits under the activator lock and is checked after the loss latch. F-A wins in every state and answers held requests at once.
-2. Hold queue: 64 per host, 1,024 per box; 30 s for client requests, 25 s for hops. The body is unread.
-3. Release: a client request is forwarded once to the confirmed holder, streaming its body. A hop gets 503 `X-Carlos-Handover: holder=<ref>`. After the move, an `H → holder` memory answers stale hops the same way.
-4. Strip `X-Carlos-Handover` from app responses beside `stripAppHolder`.
-5. Held SSE streams on H close at an event boundary once the take is confirmed.
-6. Tests: the hold comes before app contact for every route kind; F-A at each phase; every bound; a stale hop after the move.
+1. `MoveState(route)` is memory-only and runs under the activator lock: loss latch first, then `holding` | `releasing` | `taken(holder, gen)` | none. One call site, right after route lookup and before `frontForwardHA`, admission, the gate, rate limits, recording and the held-stream branch.
+2. Hold queue: 64 per host, 1,024 per box; 30 s for a client request, 25 s for a hop. The body is unread.
+3. Release: a client request takes the ordinary front forward to the confirmed holder. A replayable first-attempt hop gets a full-duplex 503 `X-Carlos-Handover`. Any other hop gets today's answer.
+4. Strip `X-Carlos-Handover` from app responses, and `X-Carlos-Replayable` from inbound client requests.
+5. Tests: every route kind, gated routes with a gate cookie, marked streams, F-A at each phase, once-only accounting, every bound.
-## Task 3: replay on the first box (§25.4 replay, cross-region)
+## Task 3: whole-copy replay and the attempt counter (H2, H3)
-Files: `internal/edge/forwardha.go`, `internal/edge/backhaul_holder.go`, new `internal/edge/replaybody.go`.
+Files: `internal/edge/forwardha.go`, `internal/edge/backhaul_holder.go`, `internal/edge/backhaul_retry.go`.
-1. A body wrapper for HA forwards and HA backhaul: it keeps the sent bytes up to 1 MiB and stops the transport from closing the client's body. The replay is the kept bytes plus the rest, with the same framing and trailers.
-2. On `X-Carlos-Handover`, validate the ref against view(region) and name authority, then make the second and last attempt. Serve locally if the ref is this box.
-3. The held-stream path (#432) follows the answer from memory, with no lock read.
-4. Tests: a hop POST, chunked with trailers, `Expect: 100-continue`; over 1 MiB sent is not replayable; no replay after a reset or any other answer; a cross-region POST through backhaul; an alias request.
+1. HA forwards and HA backhaul read a body of at most 64 KiB whole before the first send, and set `X-Carlos-Replayable: 1`. Larger or unknown-length bodies stream as today and are never replayed.
+2. One attempt counter is shared by the forward, backhaul and retry paths. A handover answer is followed only on attempt 1, after validating the ref against view and name authority. A ref naming this box serves locally.
+3. Tests: a POST up to 64 KiB, and over it; chunked with trailers; `Expect: 100-continue`; no replay after a reset; a second-attempt handover answer gets today's answer; cross-region and alias requests.
-## Task 4: the take endpoint (§25.5)
+## Task 4: the take endpoint (§25.7)
Files: new `internal/edge/hatake.go`, `internal/activator/hatake.go`, `internal/host/edgesfile.go` (`ha_take`).
-1. `/.carlos/ha-take`, hop-signed, with host and marker generation. Refusals as §25.5 lists them. It runs the HA acquire, never forwards, wakes within the wake bound, and answers the owner from `lock.json`.
-2. Tests: no marker, so the acquire table decides; another generation; a third box wins the race; the refusals; a mutation where take bypasses `DecideAcquire` fails a test.
+`/.carlos/ha-take` is hop-signed and carries the host, its lifetime and the marker generation. Its refusals are those §25.7 lists. It runs the HA acquire, never forwards, wakes H within the wake bound, and answers the owner from `lock.json`. Tests: no marker; another generation; a third box winning the race; each refusal. A mutation in which take bypasses `DecideAcquire` must fail a test.
-## Task 5: the drain driver and verb (§25.3)
+## Task 5: the drain driver and verb (§25.4, H5)
-Files: `internal/host/group_maintenance_verbs.go` (`drain`), `internal/host/hadrain.go` (new), activator hooks.
+Files: `internal/host/group_maintenance_verbs.go` (`drain`, `drain --cancel`), new `internal/host/hadrain.go`, activator hooks.
-1. The verb asks the agent to drain and waits. It prints the result as JSON: hosts moved, holder per host, longest hold, holds that got today's answer, hosts `left` with reasons.
-2. The driver: publish the drain state; wait one fold period; refuse if no eligible `ha_take` box exists; move hosts up to 4 at a time, busiest first; drain in-flight work for 10 s; stop with a drain reason; take; release the holds; publish `drained`; keep forwarding for one fold period; report. It has a deadline (§25.3).
-3. Tests: the full driver against two in-process boxes and MinIO; the deadline; a take that fails; S3 down during the release.
+1. Steps 1 to 5 of §25.4: withdrawal acknowledged by every live box that views the region; quiescence of starts, wakes, acquires, recovery workers, stops and marker obligations; moves up to 4 at a time; the connection drain; the report with the agent's incarnation.
+2. The failures of §25.4: unclean releases, missing acknowledgements and the deadline. A failed drain keeps the drain state until `--cancel`, and release work keeps its owner.
+3. Tests: the whole driver against two in-process boxes and MinIO; a wake restoring when the drain starts; an acquire paused before its PUT; a renewing unproven stop; Finish failing while the marker succeeds; files Final incomplete; an agent restart between report and action.
-## Task 6: roll tool transactions (§25.6, §25.7)
+## Task 6: roll tool transactions (§25.6, §25.9, H4)
Files: `scripts/region-group-roll.py` and its tests.
-1. `replace` and `remove`, under the existing lock and journal. Steps: preflight, floor (§25.7), `drain`, lock re-read, the provider call, watch, report. `remove` checks pools and the 2-member minimum.
-2. Roll: `drain` before `apply`, and the floor check.
-3. First install: with the floor absent, refuse a drain and say that DR-4's lock-free rule applies.
-4. Fakes and argv tests in the existing style, plus one attended live call on dev with the operator's real transport before any window (P3b-2 lesson).
-5. Runbook text for resize and scale-in in `docs/region-ha-runbook.md`, on its own docs branch with Paul's copy review.
+1. `replace`, `remove` and the changed `roll` share one shape: preflight and floor, lower minimum, `EnterStandby` with decrement, verify deregistration, `drain`, lock re-read and incarnation check, the action, restore, watch, report.
+2. H4: the provider adapter refuses any call that lowers desired other than A's `EnterStandby`. Test it with a fake provider that terminates a different instance whenever desired is lowered any other way. Confirm against the AWS docs that terminating a Standby instance without decrement leaves desired unchanged.
+3. Floor: `ha_take` on every live box that views the region, and on the pinned template's release. First install falls back to DR-4 and says so.
+4. `remove`: refuse it when a pool would be left unserved or fewer than 2 members would remain.
+5. Fakes and argv tests in the existing style. One attended live call on dev, with the real transport, before any window.
+6. Runbook text for resize and scale-in in `docs/region-ha-runbook.md`, on its own docs branch, with Paul's copy review.
-## Task 7: simulation (§21.1, §25.10)
+## Task 7: simulation (§25.10)
-Add drains, take races, holds, replay, connect-phase failures, lease loss mid-move and stale caches. Add I9 and I10 and the mutations in §25.10. Run one 3,000-seed sweep per revision, serially, at nice 19.
+Add the §25.10 actions, the invariants I9 to I11 and the mutations. Run one 3,000-seed sweep per revision, serially, at nice 19.
## Task 8: integration witness, spec, census and CI
-Write the in-process integration test of §25.10 against MinIO with two real activators and edges. Update §25 with anything the build changes, write the census cards and run CI. Then the branch review: Opus, cross-family when Astra implements.
+The integration test of §25.10. Update §25 with anything the build changes. Census cards, CI, then the branch review (Opus, cross-family against Astra implementers).
## Dev witnesses (a dated card for 8a3d302 after a release; not part of the build)
-W0 to W4 and the cross-region request, as §25.10 states, on the dev IE group. DR-4's lock-free rule stays in every card until W1 to W4 pass on a release at the floor.
+W0 to W5 as §25.10 states, on the dev IE group. DR-4's lock-free rule stays in every card until W1 to W4 pass on a release at the floor.
## Order
-Task 0 first (independent). Then 1, then 2, 3 and 4 in parallel (2 and 4 share activator state; one implementer for both), then 5, then 6 and 7, then 8. Release, then the card.
+Task 0 first (independent). Then 1; then 2, 3 and 4 in parallel (one implementer for 2 and 4, which share activator state); then 5; then 6 and 7; then 8. Release, then the card.