carlos / platform Public

docs: runbook for restarting a fixed box; region HA spec points to W6

The region HA runbook gains "Restarting a fixed box": planned stops drain
on their own, how long they take, how to read the drain's journal lines,
what each result, verdict and unverified reason means, the 3-minute exit,
what stays undrained, and the rollout order for a deployment.

The region HA spec points from §10 and §25.2 step 1 to the W6 spec, and
§12.1 and §12.2 gain the target group attributes and the fixed box's
read-only ELB rights.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1e6f138ed6ed5d6b6fe658e5b77e23696ad064ab parent 9d7f103
2 files changed, +100 −4
  • docs/region-ha-runbook.md +96 −1
  • docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md +4 −3

Intent

Human

<task-notification> <task-id>a5dfdf6af1cbeb9c9</task-id> <tool-use-id>toolu_019fpWp8oMqNA466aRvQuH94</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/a5dfdf6af1cbeb9c9.output</output-file> <status>completed</status> <summary>Agent "Implement W6 Task 7 (units)" 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>**Status:** done, with concerns. **Commit:** 9d7f1033, "host: carlos-edge-drain.service runs the ingress drain before tenants stop". The tree is clean. **Tests:** 5 new unit and systemapply tests pass; 3 failed first as expected, the other 2 pin existing install and rollback behaviour. The affected internal/host tests, `go vet` and the darwin and windows builds all pass. **Concerns:** 1. **Group callers not raised.** I left the +150 s off region-group-roll.py, the Go group verb and the SSM document's fixed `900s`. They run only on group members, where spec §4.1 says the drain answers `group_member` at once. I followed the spec over the brief. 2. **Fixed-box timeouts raised.** `carlos-system-update.service` goes from 15min to 17min 30s and `carlos-system-recover.service` from 10min to 12min 30s. Nothing in infra/ was edited. 3. **Enable mechanism.** I added `[Install] WantedBy=carlos-edge.service` so the unit can be enabled, which the spec's unit text doesn't show. It stays out of the start list because `BindsTo=` would start the edge with it. The edge restart after `daemon-reload` starts it. A rollback to an older release disables, stops and removes it. 4. **systemd version.** Fixed boxes default to `debian-13-arm64-*` (systemd 257). The group AMI and any override in the private stacks aren't in the repo, so `systemctl --version` on dev and flagship boxes, fixed and group, is still owed. 5. **Census.** `TestPlan14RootReadCensus` was already failing on the branch; my changed units add to it. That is Task 11's job. 6. **Lock file.** A `packed-refs.lock` from another session was left in the shared .git after my commit landed. I didn't touch it. **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/w6-build/.superpowers/sdd/2026-11-10-fixed-edge-ingress-drain/task-7-report.md</result> <usage><subagent_tokens>197538</subagent_tokens><tool_uses>92</tool_uses><duration_ms>1556662</duration_ms></usage> </task-notification>

Attributed to this commit: 10.8 g CO₂e (1,378,877 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on w6-ingress-drain, 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/region-ha-runbook.md b/docs/region-ha-runbook.md
index 713a9a396..9df34a0ab 100644
--- a/docs/region-ha-runbook.md
+++ b/docs/region-ha-runbook.md
@@ -22,7 +22,7 @@ Named-pool creates need a serving box that reports membership of the requested p
## Settings in host.env
-A fixed box is one you created by hand, not through Auto Scaling. It reads its region HA settings from root-owned `/etc/carlos/host.env`, mode 0600. The region-host module does not write that file. Write the lines, then restart `carlos-edge.service` on one box at a time. A restart costs about 1 to 11 seconds of held or refused requests on that box.
+A fixed box is one you created by hand, not through Auto Scaling. It reads its region HA settings from root-owned `/etc/carlos/host.env`, mode 0600. The region-host module does not write that file. Write the lines, then restart `carlos-edge.service` on one box at a time. A restart costs about 1 to 11 seconds of held or refused requests on that box. On a box attached to a load balancer with its ingress drain set up, a restart takes longer and should cost no failed requests through the load balancer (see [Restarting a fixed box](#restarting-a-fixed-box)).
```
CARLOS_REGION_HA=1
@@ -167,6 +167,101 @@ During a successful roll the restarted member is fenced too, from its restart un
Keep DR-4's lock-free rule in every window card until the dev witnesses for replace, roll, resize and scale-in have passed.
+## Restarting a fixed box
+
+A fixed box that is a target of a region's load balancer takes itself out of the load balancer before its edge stops. This is the ingress drain. Its design is in `docs/superpowers/specs/2026-11-10-fixed-edge-ingress-drain-design.md`. Group members do not use it; `carlos system group` takes them out through Standby instead.
+
+### What the drain does
+
+1. The box fails its load balancer health check on purpose, and keeps serving every request normally.
+2. Every 2 seconds it reads its target groups until each one reports it `unhealthy` (or `unhealthy.draining`) and at least one other target `healthy`. That must hold for another 10 seconds. It waits at most 90 seconds.
+3. It closes its public listeners gracefully: it stops accepting connections, lets requests already under way finish for up to 30 seconds, and then cuts anything still open.
+4. systemd then stops the tenants and the edge as before.
+
+### You do not need to do anything
+
+Every planned stop of the edge drains on its own:
+
+- `carlos system apply` and `carlos system rollback` ask for the drain after their own checks pass and before they change anything. An apply of the release already installed, or a refusal, restarts nothing and asks for no drain.
+- `systemctl restart carlos-edge`, `systemctl stop carlos-edge`, a reboot and a poweroff run the drain through `carlos-edge-drain.service`. That unit is started with the edge, and its stop runs the drain before any tenant or the edge stops.
+
+Expect a planned stop to take 30 to 60 seconds longer than before, and up to about 2 minutes at worst. The box's own hosts (fixed, non-HA hosts it serves) are unreachable for that extra time. After the restart, the load balancer sends the box new traffic only after two passing health checks, about 20 seconds after tenant admission opens. The other targets carry the traffic in the meantime.
+
+These stops are **not** drained, and behave as before:
+
+- The first roll onto a release with the drain. The agent being stopped is the old one, which has no drain. The verb logs that the agent has no ingress drain and carries on. So does any automatic rollback during that first roll.
+- Recovery of an interrupted or failed self-update (`carlos-system-recover.service`). It does not ask for the drain, because the edge has usually already stopped by then. Treat it as undrained.
+- Crashes, `systemctl kill`, and an instance that dies. The load balancer notices only after two failed health checks, about 20 seconds.
+
+### Reading the result
+
+The drain unit writes two lines to the journal. Read them with:
+
+```sh
+journalctl -u carlos-edge-drain
+```
+
+`carlos system apply` and `rollback` print the same two lines, after `system apply: `.
+
+The first line is the summary:
+
+```text
+ingress drain: result done, verdict withdrawn
+```
+
+The second line is the whole report as one line of JSON, after `ingress drain report: `. It has the time each step ended (`started_at`, `health_failed_at`, `wait_ended_at`, `listeners_closed_at`, `finished_at`), the target groups' states over time (`polls`), and from step 3 the requests that finished (`finished`), the requests cut at the 30-second limit (`closed`) and the edge-held event streams closed (`held_closed`).
+
+The agent also logs one line in `journalctl -u carlos-edge`, starting `agent: ingress drain done:`, with the same verdict and counts.
+
+The `result` can be:
+
+- `done`: the drain ran. Read the verdict.
+- `not_armed`: this box has no drain, and the stop went ahead as before. The reason says why: region HA is off, `CARLOS_INGRESS_TARGET_GROUPS` is not set, or a target group it names is not in the box's own account and region.
+- `group_member`: the box is a group member. Expected; members leave through `carlos system group`.
+- `refused`: the drain did not start, usually because a region HA connection drain was already running. The stop went ahead as before.
+
+Other summary lines, with no report, mean nothing was drained: `the agent's drain socket is not answering` (the edge had already stopped), and `the agent has no ingress drain (an older release)`.
+
+### The verdict
+
+`withdrawn` is the good case. Every target group stopped sending the box new connections, another target was healthy, and that held for 10 seconds before the listeners closed. Expect no failed requests through the load balancer, apart from requests for the box's own fixed hosts.
+
+`unverified` means the drain could not confirm that. It still closed the listeners and let the stop go ahead, because a stop is never held up. Clients may see a few errors, as before the drain existed. The reasons after the colon in the summary line say why:
+
+- `target group retention: ...`: a target group resets connections when a target turns unhealthy, or keeps them for less than 180 seconds. The target group attributes are not applied yet. Apply them (next section).
+- `not healthy at start: target group <arn> reports <state>`: the box was already not healthy when the drain began, so the drain cannot tell how long it has been that way.
+- `target group <arn> reports healthy` (or `initial`): after 90 seconds the target group still had not marked the box unhealthy.
+- `no other healthy target: target group <arn>`: the box was the last healthy target. When every target is unhealthy the load balancer fails open and keeps sending traffic to all of them, so draining this box protected nobody. Bring another target into service before you restart this one.
+- `read failed: ...`: the box could not read its target groups (for example, the role lacks the read rights). The error is in the line.
+- `the target groups withdrew the box only after the cap`: the target groups marked it unhealthy, but only after 90 seconds.
+
+### If the edge does not stop
+
+After the listeners close, the box serves nothing on its public ports. If the agent is still running 3 minutes later (someone stopped only `carlos-edge-drain`, or a verb failed after the drain and never restarted the edge), it logs `ingress drain ended without a stop; exiting` and exits. systemd restarts it, and the box comes back into the load balancer after tenant admission opens and two health checks pass. You do not need to step in.
+
+### Setting it up on a deployment
+
+Do these steps in this order, on the deployment's card. Until step 3, the drain answers `not_armed` and every stop behaves as before.
+
+1. Apply the region-host module with the target group attributes (unhealthy connection termination off, a 180-second draining interval) and, for the fixed box, `ingress_target_group_arns` set to the target groups it is attached to. This gives the box's role the read-only `elasticloadbalancing:DescribeTargetHealth` and `DescribeTargetGroupAttributes`. No target is re-registered.
+2. Check every target group:
+
+ ```sh
+ aws elbv2 describe-target-group-attributes --target-group-arn <arn>
+ ```
+
+ `target_health_state.unhealthy.connection_termination.enabled` must be `false`, and `target_health_state.unhealthy.draining_interval_seconds` must be `180`.
+3. Take the module's `ingress_target_groups` output and write it into the fixed box's host.env as `CARLOS_INGRESS_TARGET_GROUPS`, through the stack that owns the box's host-env parameters. The module does not write it. For example:
+
+ ```
+ CARLOS_INGRESS_TARGET_GROUPS=arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/example-80/0123456789abcdef,arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/example-443/fedcba9876543210
+ ```
+
+ `carlos system host-env write` and `seed` refuse a malformed value. A value naming another account or region is caught when the drain is asked for, and the drain answers `not_armed`.
+4. Restart `carlos-edge.service` on the box. The agent logs `agent: ingress drain armed for 2 target group(s)`. The next planned stop drains.
+
+If the key arrives before the attributes anyway, the drain reports `unverified: target group retention`, never `withdrawn`.
+
## A fixed box has been terminated: remove its edges file
When a fixed box is terminated, a surviving box recovers its duties. It takes over the box's hosts, timers and due wakes. It does not delete the departed box's edges file (`control/edges/<box>.json`) because the platform cannot prove which instance of a fixed box an edges file belongs to.
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
index b38b1f889..5df1643b4 100644
--- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
+++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md
@@ -583,6 +583,7 @@ Keep `internal/lbhealth`, with its six conditions (`internal/lbhealth/lbhealth.g
- the hook's timeout is the measured boot time plus a margin, starting at 15 minutes, and abandons a box that never completes it;
- the health-check grace is 60 s, which covers the target group's first two checks.
- **Not added:** S3 reachability (S2 §6).
+- **Fixed boxes leaving on purpose:** a seventh condition, `ingress-drain`, fails the answer while a fixed box drains itself out of its target groups before a planned stop. See the W6 spec, `docs/superpowers/specs/2026-11-10-fixed-edge-ingress-drain-design.md`.
## 11. Placement inputs, capacity and create refusals
@@ -604,7 +605,7 @@ Today the module makes one `aws_instance` and one `aws_eip` (`main.tf:536-587`).
- **A Network Load Balancer, with its own security group** (astra-2.6), admitting 80 and 443 from anywhere.
- One subnet mapping per group zone. Zone A carries the region's existing EIP, as a standalone `aws_eip` with `prevent_destroy`; other zones get new, unpublished EIPs.
- Cross-zone on; TCP 80 and 443; instance targets, so the client IP is kept.
- - Deregistration delay 30 s. Health checks are HTTP on 80 at `/.carlos/lb-health`, every 10 s, 2 healthy and 2 unhealthy.
+ - Deregistration delay 30 s. Health checks are HTTP on 80 at `/.carlos/lb-health`, every 10 s, 2 healthy and 2 unhealthy. Unhealthy targets keep their open connections: `target_health_state` has `enable_unhealthy_connection_termination = false` and `unhealthy_draining_interval = 180` (W6 spec §8).
- **The target security group** admits:
- 80 and 443 from the NLB's security group, for both traffic and health checks;
- 443 from anywhere, as today (`main.tf:97-107`), because cross-region backhaul dials each box's public address on 443 (`internal/edge/edge.go:3056`) from changing addresses. That path is hop-signed;
@@ -617,7 +618,7 @@ Today the module makes one `aws_instance` and one `aws_eip` (`main.tf:536-587`).
### 12.2 IAM
-- **Box role:** SSM reads on `/carlos/<deployment>/<region>/*` and `/shared/*`, with `kms:Decrypt` under the `ViaService` and `PARAMETER_ARN` conditions; the existing SSM Deny; an explicit HA statement for `ec2:DescribeInstances`; and `autoscaling:CompleteLifecycleAction` on its own group's ARN only. No other Auto Scaling, ELB or EC2 write right.
+- **Box role:** SSM reads on `/carlos/<deployment>/<region>/*` and `/shared/*`, with `kms:Decrypt` under the `ViaService` and `PARAMETER_ARN` conditions; the existing SSM Deny; an explicit HA statement for `ec2:DescribeInstances`; and `autoscaling:CompleteLifecycleAction` on its own group's ARN only. A fixed box attached to target groups (`ingress_target_group_arns` set) also gets the read-only `elasticloadbalancing:DescribeTargetHealth` and `elasticloadbalancing:DescribeTargetGroupAttributes` on `*` for its ingress drain (W6 spec §8). No other Auto Scaling, ELB or EC2 write right.
- **Console:** nothing new. **Operator seeding:** `ssm:PutParameter` and the KMS actions (S2 §5 step 2).
### 12.3 Boot
@@ -1070,7 +1071,7 @@ Nothing on main drains a member: role `drain` is a value that group boxes treat
### 25.2 The model
A planned replacement of member A is one operator transaction, in this order:
-1. **Out of the load balancer.** A enters Standby, so the NLB sends it no new client flows (§25.6).
+1. **Out of the load balancer.** A enters Standby, so the NLB sends it no new client flows (§25.6). A fixed box cannot enter Standby; its counterpart is the W6 ingress drain (`docs/superpowers/specs/2026-11-10-fixed-edge-ingress-drain-design.md`).
2. **Withdraw and quiesce.** A stops being a placement choice, every live box acknowledges that, and A settles every acquire already under way (§25.4 steps 1-2).
3. **Move the leases.** A moves each awake host to a successor, and holds the requests that reach it for that host while it moves (§25.4 step 3, §25.5).
4. **Drain the connections.** A finishes the requests it is still forwarding, and closes keep-alive connections and long streams in an orderly way (§25.4 step 4).