oficina / equipo Public

hostedops: fence records what it fenced; reboot reads the fence

A fence that attached no deny policy journalled FENCED, and controller
reboot then refused for the rest of the run. FENCED now says
attached=yes|no and the hosts it stopped; reboot is refused by a policy
attached now (read directly) or an unreadable attachment, not by the
journal line. Mutations F1-F4 recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 14c0effd72cdb0350275399d1d2fbd7689f7e223 parent ef28439
5 files changed, +121 −10
  • docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md +24 −0
  • internal/hostedops/drill_test.go +78 −0
  • internal/hostedops/singleton.go +7 −3
  • internal/hostedops/t32_test.go +4 −1
  • internal/hostedops/unfence.go +8 −6
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
index 07bf3f86..aad35a54 100644
--- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
+++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md
@@ -3350,3 +3350,27 @@ Mutation checks, each restored and green again:
FAIL `bundle_test.go:69: the controller loads the bundle: 0, ctlcert: certificate files are not valid: ... not an object`.
- **B4** the dev plan's bundle line given `-outt`. `-run TestPlanCertInvocationsParse`: FAIL
`plan_test.go:33: 2026-12-01-hosted-2-dev-live-plan.md: cert bundle ... -outt ...: flag provided but not defined: -outt`.
+
+### Fix 2: a fence records what it fenced; reboot reads the fence
+
+`ops fence` journalled FENCED even when it attached no deny policy (the services stack had none,
+SKIP), and `ops controller reboot` refused on any FENCED line for the rest of the run. Now FENCED
+records what was fenced, `attached=yes|no hosts=<ids>` (`attached=yes` only after the attach read
+back), and reboot is refused by a deny policy attached to the controller role now, read directly
+(`policyAttached`), or by an attachment that does not read; a FENCED line alone does not refuse.
+`unfence` and the report's stopped-controller costing still key on FENCED (the fence ran, the hosts
+stopped). `rebootRig` now models no attached policy (the fake answered "attached" for a nil map);
+`TestControllerReboot`'s fenced case attaches it.
+
+Red: `go test ./internal/hostedops -run 'TestFenceRecordsWhatItFenced|TestRebootRefusalReadsTheFence' -count=1`:
+FAIL `drill_test.go:29: FENCED lines [... Fields:[equipo-hosted-controller ... i-0ctl] ...], want one saying attached=no hosts=i-0ctl`;
+`drill_test.go:72: attached, never journalled: reboot = 0, want 99`, `journalled, since detached: reboot = 99, want 0`,
+`attachment unreadable: reboot = 0, want 99`. Green: the whole package, ok.
+
+Mutation checks, each restored and green again:
+- **F1** `attached` starts as "yes". `-run TestFenceRecordsWhatItFenced`: FAIL `drill_test.go:29: FENCED lines [... attached=yes hosts=i-0ctl ...]`.
+- **F2** the live check off (`false && (err != nil || on)`). `-run TestRebootRefusalReadsTheFence`: FAIL
+ `drill_test.go:72: attachment unreadable: reboot = 0, want 99` and `attached, never journalled: reboot = 0, want 99`.
+- **F3** a read error allowed (`if on`). Same test: FAIL `drill_test.go:72: attachment unreadable: reboot = 0, want 99`.
+- **F4** the old journal refusal put back ahead of the read. `-run 'TestFenceRecordsWhatItFenced|TestRebootRefusalReadsTheFence'`:
+ FAIL `drill_test.go:31: ops controller reboot ... = 99, want 0` and `drill_test.go:72: journalled, since detached: reboot = 99, want 0`.
diff --git a/internal/hostedops/drill_test.go b/internal/hostedops/drill_test.go
new file mode 100644
index 00000000..b5fb8653
--- /dev/null
+++ b/internal/hostedops/drill_test.go
@@ -0,0 +1,78 @@
+package hostedops
+
+import (
+ "errors"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/hostedwire"
+)
+
+// Dev drill run-kit fixes (2026-12-01).
+
+// TestFenceRecordsWhatItFenced (finding 2): a fence that attached no deny
+// policy (the services stack has none yet) still stops the controller
+// host, and its FENCED line says no policy was attached; ops controller
+// reboot then goes ahead, since nothing holds launches off.
+func TestFenceRecordsWhatItFenced(t *testing.T) {
+ r, _ := rebootRig(t, errors.New("connection refused"), hostedwire.StatusResponse{Enabled: true})
+ r.want(0, "fence")
+ if r.cloud.index("StopInstance i-0ctl") < 0 || r.cloud.count("AttachRolePolicy") != 0 {
+ t.Fatalf("fence: %v", r.cloud.log())
+ }
+ var fenced []Entry
+ for _, e := range r.ledger().Entries {
+ if e.Verb == "FENCED" {
+ fenced = append(fenced, e)
+ }
+ }
+ if len(fenced) != 1 || fenced[0].Attr("attached") != "no" || fenced[0].Attr("hosts") != "i-0ctl" {
+ t.Fatalf("FENCED lines %+v, want one saying attached=no hosts=i-0ctl:\n%s", fenced, journalText(r))
+ }
+ r.want(0, "controller", "reboot", "--enabled", "1", "--controller", "https://198.51.100.7")
+ if r.cloud.index("RebootInstance i-0ctl") < 0 || !r.has("REBOOTED", "i-0ctl") {
+ t.Fatalf("a run whose fence attached nothing could not reboot: %v\n%s", r.cloud.log(), journalText(r))
+ }
+
+ // With the policy recorded, the fence attaches it and says so.
+ r, _ = rebootRig(t, hostedwire.StatusResponse{Enabled: true})
+ r.journal(ctlPol)
+ r.want(0, "fence")
+ if !r.has("FENCED", "attached=yes") || !r.attachedNow() {
+ t.Fatalf("an attached fence not recorded:\n%s", journalText(r))
+ }
+ r.want(ExitStop, "controller", "reboot", "--enabled", "1", "--controller", "https://198.51.100.7")
+ if r.cloud.count("RebootInstance") != 0 {
+ t.Fatal("a controller fenced by an attached policy was rebooted")
+ }
+}
+
+// TestRebootRefusalReadsTheFence (finding 2): reboot is refused by a deny
+// policy attached to the controller role now, read directly, or by an
+// attachment that does not read; a FENCED line alone, its policy since
+// detached, does not hold the controller down.
+func TestRebootRefusalReadsTheFence(t *testing.T) {
+ on := hostedwire.StatusResponse{Enabled: true}
+ for name, c := range map[string]struct {
+ attached bool
+ readErr error
+ journal string
+ exit int
+ }{
+ "attached, never journalled": {attached: true, exit: ExitStop},
+ "attachment unreadable": {readErr: errors.New("AccessDenied"), exit: ExitStop},
+ "journalled, since detached": {journal: "FENCED equipo-hosted-controller " + denyPolicy + " i-0ctl attached=yes hosts=i-0ctl", exit: 0},
+ } {
+ r, _ := rebootRig(t, errors.New("connection refused"), on)
+ r.cloud.attached["equipo-hosted-controller "+denyPolicy] = c.attached
+ r.cloud.attachedErr = c.readErr
+ if c.journal != "" {
+ r.journal(c.journal)
+ }
+ if got := r.ops("controller", "reboot", "--enabled", "1", "--controller", "https://198.51.100.7"); got != c.exit {
+ t.Errorf("%s: reboot = %d, want %d:\n%s", name, got, c.exit, r.out.String())
+ }
+ if rebooted := r.cloud.count("RebootInstance") != 0; rebooted != (c.exit == 0) {
+ t.Errorf("%s: rebooted %t", name, rebooted)
+ }
+ }
+}
diff --git a/internal/hostedops/singleton.go b/internal/hostedops/singleton.go
index 959a7087..93121feb 100644
--- a/internal/hostedops/singleton.go
+++ b/internal/hostedops/singleton.go
@@ -253,6 +253,8 @@ func mfaTrue(v json.RawMessage) bool {
// any open controller intent's instance, found by its creation identity. A
// failed attach does not skip the host stop; every problem is reported at
// the end, and a controller whose existence cannot be settled is one.
+// FENCED records what was fenced: attached=yes only when the policy was
+// attached and read back, and the hosts stopped (dev drill finding 2).
func (o *Ops) fence() error {
l, err := o.ledger()
if err != nil {
@@ -260,7 +262,7 @@ func (o *Ops) fence() error {
}
role, policy := o.denyPolicy()
var problems []string
- policyKnown := false
+ policyKnown, attached := false, "no"
for _, r := range l.Recorded("tf") {
if r.Attr("type") == "aws_iam_policy" && strings.HasSuffix(r.Value, ".deny_launches") && !l.Deleted["tf "+r.Value] {
policyKnown = true
@@ -287,6 +289,8 @@ func (o *Ops) fence() error {
_ = o.jw("NOTCREATED", "fence-attach %s not-read-back", role)
} else if err := o.rec("fence-attach", policy, "name="+role); err != nil {
return err
+ } else {
+ attached = "yes"
}
}
ids, found := o.controllerHosts(l, false, "fence", "stopping")
@@ -303,8 +307,8 @@ func (o *Ops) fence() error {
_ = o.jw("ABORT", "fence: %s", strings.Join(problems, "; "))
return stopf("fence incomplete: %s", strings.Join(problems, "; "))
}
- o.out("fenced: %s on %s; controller hosts stopped: %v", policy, role, ids)
- return o.jw("FENCED", "%s %s %s", role, policy, strings.Join(ids, ","))
+ o.out("fenced: %s on %s attached %s; controller hosts stopped: %v", policy, role, attached, ids)
+ return o.jw("FENCED", "%s %s %s attached=%s hosts=%s", role, policy, strings.Join(ids, ","), attached, strings.Join(ids, ","))
}
// controllerHosts are the run's controller hosts: every recorded one not
diff --git a/internal/hostedops/t32_test.go b/internal/hostedops/t32_test.go
index a4881d36..fbb9eada 100644
--- a/internal/hostedops/t32_test.go
+++ b/internal/hostedops/t32_test.go
@@ -332,7 +332,8 @@ func (c *statusCtl) Certs(context.Context) (hostedwire.CertsResponse, error) {
}
// rebootRig is a run with its controller host recorded, the operator and
-// controller keys on disk and the controller answering from answers.
+// controller keys on disk, no deny policy attached and the controller
+// answering from answers.
func rebootRig(t *testing.T, answers ...any) (*rig, *statusCtl) {
r := newRig(t, ctlVM, "REC controller-pin "+strings.Repeat("a", 64))
pub, key, _ := ed25519.GenerateKey(nil)
@@ -340,6 +341,7 @@ func rebootRig(t *testing.T, answers ...any) (*rig, *statusCtl) {
os.WriteFile(filepath.Join(r.dir, "keys", "operator.key"), []byte(base64.StdEncoding.EncodeToString(key.Seed())), 0o600)
os.WriteFile(filepath.Join(r.dir, "keys", "controller.pub"), []byte(base64.StdEncoding.EncodeToString(pub)), 0o600)
ctl := &statusCtl{answers: answers}
+ r.cloud.attached = map[string]bool{}
r.deps.Controller = func(ControllerArgs) (ControllerClient, error) { return ctl, nil }
return r, ctl
}
@@ -358,6 +360,7 @@ func TestControllerReboot(t *testing.T) {
}
r, _ = rebootRig(t, on)
r.journal("FENCED equipo-hosted-controller " + denyPolicy + " i-0ctl")
+ r.cloud.attached["equipo-hosted-controller "+denyPolicy] = true
r.want(ExitStop, "controller", "reboot", "--enabled", "1", "--controller", "https://198.51.100.7")
if r.cloud.count("RebootInstance") != 0 {
t.Fatal("a fenced controller was rebooted")
diff --git a/internal/hostedops/unfence.go b/internal/hostedops/unfence.go
index 13cac702..d4864009 100644
--- a/internal/hostedops/unfence.go
+++ b/internal/hostedops/unfence.go
@@ -177,8 +177,11 @@ 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 fenced run is
-// refused: its controller stays stopped.
+// answers with launches as --enabled says, within --max. 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
+// nothing holds no launches off (dev drill finding 2).
func cmdControllerReboot(o *Ops, args []string) error {
fs := flag.NewFlagSet("controller reboot", flag.ContinueOnError)
enabled := fs.String("enabled", "", "1 or 0: the launch switch controller/env now holds")
@@ -194,10 +197,9 @@ func cmdControllerReboot(o *Ops, args []string) error {
if err != nil {
return err
}
- for _, e := range l.Entries {
- if e.Verb == "FENCED" {
- return stopf("the run fenced its controller; a fenced controller is never restarted")
- }
+ role, policy := o.denyPolicy()
+ if on, err := o.policyAttached(role, policy); err != nil || on {
+ return stopf("the run fenced its controller (%s attached to %s: %t, %v); a fenced controller is never restarted", policy, role, on, err)
}
ids, problems := o.controllerHosts(l, false, "controller reboot", "rebooting")
if len(problems) > 0 || len(ids) != 1 {