oficina / equipo Public

hostedops: controller reboot waits for the host to go away

Before a reboot the controller may already answer with the wanted
launch switch, so the first such answer proved nothing. A read counts
only after a failed read or one with the other switch; the --max bound
is unchanged. Mutations R1-R2 recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8452ba7a04fc904d73a7e991fc841a35a380fcb8 parent 03ce8ee
3 files changed, +57 −4
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +16 −0
  • internal/hostedops/drill_test.go +31 −0
  • internal/hostedops/unfence.go +10 −4
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
index fac9fa27..50eb2c47 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -3389,3 +3389,19 @@ production's release is built from main after the drill's recorded pass (0.1 che
the runner embeds its commit, so the digest differs. 4.1 now says so, and that production certifies
that image itself in 6.2 to 6.4. Plan text only: the plan-parse tests (`TestPlan*` in hostedops,
equipo-hosted-certify and equipo-hosted-image) pass; no mutation.
+
+### Fix 5: controller reboot waits for the host to go away (Fable 34, section 0)
+
+`ops controller reboot` accepted the first status read with `enabled == want`, which is already true
+before a 7.1 reboot, so it returned before the host went down and the next `ops assert status` read
+into the outage. Now a read counts only after the host was seen to go away: a failed read, or one
+with the other switch. The bound (`--max`, 15 s reads) is unchanged; a controller that only ever
+answers as wanted runs into it and is a hard stop, never REBOOTED.
+
+Red: `go test ./internal/hostedops -run TestRebootWaitsForTheHostToGo -count=1`: FAIL
+`drill_test.go:100: up all along: reboot = 0, want 99`, `:106: up all along: journalled REBOOTED though the host never went away`,
+`:103: down, then back: REBOOTED true after 1 reads, want 4`. Green: the whole package, ok.
+
+Mutation checks, each restored and green again:
+- **R1** `away` starts true. `-run TestRebootWaitsForTheHostToGo`: FAIL as the red run (`up all along: reboot = 0, want 99`).
+- **R2** only a failed read counts as away. Same test: FAIL `drill_test.go:100: old switch, then new: reboot = 99, want 0`.
diff --git a/internal/hostedops/drill_test.go b/internal/hostedops/drill_test.go
index b5fb8653..7dd59095 100644
--- a/internal/hostedops/drill_test.go
+++ b/internal/hostedops/drill_test.go
@@ -76,3 +76,34 @@ func TestRebootRefusalReadsTheFence(t *testing.T) {
}
}
}
+
+// TestRebootWaitsForTheHostToGo (Fable 34, section 0): before the reboot
+// the controller already answers with the launch switch it will have
+// after it, so that answer proves nothing. Reboot accepts an answer only
+// after a failed read or a read with the other switch (the old process,
+// or none, answered); a controller that only ever answers as wanted runs
+// into --max and is a hard stop, never REBOOTED.
+func TestRebootWaitsForTheHostToGo(t *testing.T) {
+ on, off := hostedwire.StatusResponse{Enabled: true}, hostedwire.StatusResponse{Enabled: false}
+ down := errors.New("connection refused")
+ for name, c := range map[string]struct {
+ answers []any
+ exit int
+ reads int // status reads by the end, when it succeeds
+ }{
+ "up all along": {[]any{on}, ExitStop, 0},
+ "down, then back": {[]any{on, on, down, on}, 0, 4},
+ "old switch, then new": {[]any{off, on}, 0, 2},
+ } {
+ r, ctl := rebootRig(t, c.answers...)
+ if got := r.ops("controller", "reboot", "--enabled", "1", "--controller", "https://198.51.100.7", "--max", "2m"); got != c.exit {
+ t.Errorf("%s: reboot = %d, want %d:\n%s", name, got, c.exit, r.out.String())
+ }
+ if c.exit == 0 && (!r.has("REBOOTED", "i-0ctl enabled=true") || ctl.n != c.reads) {
+ t.Errorf("%s: REBOOTED %t after %d reads, want %d:\n%s", name, r.has("REBOOTED", ""), ctl.n, c.reads, journalText(r))
+ }
+ if c.exit != 0 && r.has("REBOOTED", "") {
+ t.Errorf("%s: journalled REBOOTED though the host never went away", name)
+ }
+ }
+}
diff --git a/internal/hostedops/unfence.go b/internal/hostedops/unfence.go
index d4864009..c016ef39 100644
--- a/internal/hostedops/unfence.go
+++ b/internal/hostedops/unfence.go
@@ -177,7 +177,10 @@ func (o *Ops) terminateHost(id string) error {
// unit is enabled, so it starts at boot and fetches every controller/
// object again; the TLS key stays on the host, so the pin does not
// change), then reads GET /v1/status through the pin until the controller
-// answers with launches as --enabled says, within --max. A run whose
+// answers with launches as --enabled says, within --max. Before the
+// reboot the controller may already answer that way, so an answer counts
+// only after the host was seen to go away: a failed read, or one with the
+// other switch (Fable 34, section 0). A run whose
// deny policy is attached to the controller role now (read directly), or
// whose attachment does not read, is refused: a fenced controller stays
// stopped. A FENCED line alone does not refuse: a fence that attached
@@ -217,15 +220,18 @@ func cmdControllerReboot(o *Ops, args []string) error {
}
want := *enabled == "1"
end := o.Clock.Now().Add(*maxD)
+ away := false
for {
st, err := cl.Status(o.ctx)
- if err == nil && st.Enabled == want {
+ if err != nil || st.Enabled != want {
+ away = true
+ } else if away {
o.out("controller %s answers again, launches enabled %t", ids[0], st.Enabled)
return o.jw("REBOOTED", "%s enabled=%t", ids[0], st.Enabled)
}
if !o.Clock.Now().Add(15 * time.Second).Before(end) {
- _ = o.jw("ABORT", "controller reboot: %s did not answer with enabled %t within %s (%v)", ids[0], want, *maxD, err)
- return stopf("the controller did not answer with launches enabled %t within %s after its reboot (%v)", want, *maxD, err)
+ _ = o.jw("ABORT", "controller reboot: %s did not go away and answer with enabled %t within %s (went away %t, %v)", ids[0], want, *maxD, away, err)
+ return stopf("the controller did not go away and answer with launches enabled %t within %s after its reboot (went away %t, %v)", want, *maxD, away, err)
}
if err := o.Clock.Sleep(o.ctx, 15*time.Second); err != nil {
return stopf("interrupted: %v", err)