host: dry-check the guard before the drain ask only on an armed box
The F3 dry check moved the activation guard's refusals ahead of the quiesce on every box, which changed the refusal path that TestActivationIsCheckedAgainAtTheRename and TestRefusedInstallWhoseRearmFailsSaysSoAndRetries pin: the guard's own recheck at the rename, with the quiesced passes re-armed. The dry check now runs only when host.env sets the box up for the ingress drain (region HA on, target groups named); other boxes keep their refusals at the rename. The F3 armed-box case sets that explicitly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/host/systemapply.go+26 −8internal/host/systemapply_ingress_test.go+1 −0
Intent
<task-notification> <task-id>a14f56a7ddada51be</task-id> <tool-use-id>toolu_012pdgWH2F1LDjojWnX1T6QG</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a373aecd-faa9-4b83-8736-ff726fb2d3af/tasks/a14f56a7ddada51be.output</output-file> <status>completed</status> <summary>Agent "Implement W6 Task 9 (root runner)" 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. The automatic-restart test no longer requires the tenant to serve after the kill; it checks the box instead. Commits: 4c08d4f0 "host: ingress drain auto-restart witness checks the box, not the HA tenant", on top of the merge 02dce472. It contains only the fixture test file; another agent's uncommitted changes to `systemapply.go` and `systemapply_ingress_test.go` appeared in the worktree, and I left them out. Build/vet: `go vet -tags rootrunner` is clean on linux/arm64 and the host. The linux/arm64 rootrunner test binary builds (deleted after). `TestIngressRootLoopClassify`, `TestIngressRootDepartureSeam` and `TestIngressRootEdgeStep1ConnectionClose` all pass. The last one now passes its gzip case too, so the edge fix for the lost Connection: close is in. Change: - After the kill and the edge's own restart, `TestRootIngressDrainOrderAutoRestart` now checks three things: - the new agent is listening; - its fixed admission opens, read from the journal since the kill; - the drain unit is active again. - The kill checks are unchanged: - the drain unit's stop takes under 1 s, finds the agent gone and runs no drain; - tenants stop after it; - the edge comes back by itself. - I did not check the edge's load-balancer health answer separately; admission opening stands in for it. Other tests: - `TestRootIngressDrainOrderVerbAsk` stops the edge cleanly with `systemctl restart`, so the tenant releases its lock properly and the serving check stays correct (Restart, which does the same, passed in run 5). - The reboot pair asks nothing to serve after the reboot; phase 2 only reads the previous boot's journal and the saved request loop. Concerns: none new. All four tests are ready for the next runner pass. Report (round 5 section appended): /home/paulca/amadan.net/carlos/platform/.claude/worktrees/w6-build/.superpowers/sdd/2026-11-10-fixed-edge-ingress-drain/task-9-report.md</result> <usage><subagent_tokens>378584</subagent_tokens><tool_uses>5</tool_uses><duration_ms>189038</duration_ms></usage> </task-notification>
Attributed to this commit: 13.3 g CO₂e (1,744,998 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/internal/host/systemapply.go b/internal/host/systemapply.go| index c1a8c08f4..a3db9bb0e 100644 |
| --- a/internal/host/systemapply.go |
| +++ b/internal/host/systemapply.go |
| @@ -146,6 +146,7 @@ func productionSystemApplier(channel string) *systemApplier { |
| platform: runtime.GOOS + "-" + runtime.GOARCH, soak: systemGateSoak, |
| handRun: systemApplyHandRun(os.Getenv), |
| askIngressDrain: execIngressDrain, |
| + ingressArmed: func() bool { return ingressDrainConfigured(os.Getenv) }, |
| } |
| a.readEnvironment(os.Getenv) |
| a.floorHook = installFloorHook // decided under the apply lock, in Run |
| @@ -298,6 +299,18 @@ type systemApplier struct { |
| // drain (W6 spec §5.3) through the drain-call child: execIngressDrain |
| // in production. Nil asks nothing, as a binary from before W6. |
| askIngressDrain func(ctx context.Context) (drainCallResult, error) |
| + // ingressArmed is whether host.env sets this box up for the ingress |
| + // drain (region HA on, target groups named): only then does the verb |
| + // dry-check the guard before its ask (refusalsBeforeDrain). Nil is a |
| + // box with no drain, whose refusals stay where they were. |
| + ingressArmed func() bool |
| +} |
| + |
| +// ingressDrainConfigured is host.env's half of the drain's arming (spec |
| +// §4.1), as the root verb can read it: region HA on and target groups |
| +// named. The agent decides the rest when asked. |
| +func ingressDrainConfigured(getenv func(string) string) bool { |
| + return regionHAEnabled(getenv) && strings.TrimSpace(getenv(ingressTargetGroupsKey)) != "" |
| } |
| // ingressDrainBeforeSwap is apply's and rollback's ask for the ingress |
| @@ -716,10 +729,13 @@ func (a *systemApplier) install(ctx context.Context, req systemRequest, p *relea |
| // The release on disk, for the activation guard at the rename: read now, |
| // because reading it runs the binary and the guard holds locks. |
| running := a.onDiskBuild(ctx) |
| - // The activation guard's refusals, as a dry check, so the drain below |
| - // never precedes one of them (W6 spec §5.3). |
| - if err := a.refusalsBeforeDrain(target, running, staged); err != nil { |
| - return a.record(req, fmt.Errorf("%w: %v", errSystemRefused, err)) |
| + // On a box set up for the drain, the activation guard's refusals as a |
| + // dry check, so the drain below does not precede one of them (W6 spec |
| + // §5.3). A box without it keeps its refusals at the rename. |
| + if a.ingressArmed != nil && a.ingressArmed() { |
| + if err := a.refusalsBeforeDrain(target, running, staged); err != nil { |
| + return a.record(req, fmt.Errorf("%w: %v", errSystemRefused, err)) |
| + } |
| } |
| // Every refusal is behind us and this install restarts the edge: out of |
| // the load balancer first (W6 spec §5.3). Before the journal, so an |
| @@ -2139,10 +2155,12 @@ func (a *systemApplier) restoreFiles(ctx context.Context, j *systemJournal, drai |
| return bootstrapPlan{}, err |
| } |
| if drain { |
| - // The guard's binary check and the quiesce's refusal too, before |
| - // the ask: a refusal never follows a drain (W6 spec §5.3). |
| - if err := a.refusalsBeforeDrain(prevVersion, running, prev); err != nil { |
| - return bootstrapPlan{}, err |
| + // On a box set up for the drain, the guard's binary check and the |
| + // quiesce's refusal too, before the ask (W6 spec §5.3). |
| + if a.ingressArmed != nil && a.ingressArmed() { |
| + if err := a.refusalsBeforeDrain(prevVersion, running, prev); err != nil { |
| + return bootstrapPlan{}, err |
| + } |
| } |
| a.ingressDrainBeforeSwap(ctx) |
| } |
diff --git a/internal/host/systemapply_ingress_test.go b/internal/host/systemapply_ingress_test.go| index 00ea9bfea..0dcb59331 100644 |
| --- a/internal/host/systemapply_ingress_test.go |
| +++ b/internal/host/systemapply_ingress_test.go |
| @@ -137,6 +137,7 @@ func TestApplyAsksNoIngressDrainWhenItWillNotRestartTheEdge(t *testing.T) { |
| // review F3). |
| "activation guard refuses on an armed box": func(t *testing.T) *applyFixture { |
| f, _ := floorFixture(t, "v0.31.0", "v0.32.0") |
| + f.a.ingressArmed = func() bool { return true } |
| f.duringStaging(func() { |
| if err := writeLocalFloor(f.a.dataDir, moves.Floor{Min: 1, MinRelease: "v0.33.0"}); err != nil { |
| t.Error(err) |