console: a system unit is never movable (M2 review P1)
movable refuses a unit-backed record whatever its hibernation, manifest or assignment, and movableVerified answers it before reading a manifest. The label door answers unmovable:unit (C31) with no mark and no write; the lost-box pass leaves it and a drain strands its app. D1 keeps its early C42 guard.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+81
−15
internal/console/apiinstances_test.go+2 −5internal/console/fleetbox.go+17 −6internal/console/fleetcreate.go+2 −2internal/console/fleetrelabel_test.go+30 −0internal/console/instancelabel_test.go+26 −0internal/console/replicaplacement_fix_test.go+4 −2
Intent
Human
<task-notification> <task-id>bhaaej0y2</task-id> <tool-use-id>toolu_01PcgN8hGtdhejmER8oFVYw9</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ac77363b-5830-422c-9f38-d7f2540dd398/tasks/bhaaej0y2.output</output-file> <status>completed</status> <summary>Background command "Run M2 whole-branch reviews" completed (exit code 0)</summary> </task-notification>
diff --git a/internal/console/apiinstances_test.go b/internal/console/apiinstances_test.go| index eaa573951..b0012ebf0 100644 |
| --- a/internal/console/apiinstances_test.go |
| +++ b/internal/console/apiinstances_test.go |
| @@ -3376,16 +3376,13 @@ func TestCreateRefusesATamperedManifest(t *testing.T) { |
| } |
| // Fix round 1: a unit-backed record is refused with C42 even with no |
| -// manifest at all (no release shipped yet), though movable alone would |
| -// admit one with default hibernation. |
| +// manifest at all (no release shipped yet). Since M2 review P1 movable |
| +// refuses it too; D1 keeps its own early answer. |
| func TestCreateRefusesAUnitWithNoManifest(t *testing.T) { |
| ctx := context.Background() |
| fx, _, reg := d1World(t, "code-d1-unit-nil", "pi-1", "pi-2") |
| rec := provision.Record{Schema: 1, Host: "a.example.com", Slug: "a", App: "shop", Account: fx.sqid, |
| Region: "fleet/pi", Channel: "edge", CreatedAt: time.Now().UTC(), Unit: "shop.service"} |
| - if !movable(rec) { |
| - t.Fatal("movable alone refuses it; the witness needs the gap") |
| - } |
| v, verr := fx.srv.loadFleetView(ctx, "pi") |
| ref := fx.srv.fleetCreateLabel(ctx, reg, "pi", v, verr, &rec, nil) |
| want := "a.example.com cannot run on a fleet with more than one box: it runs as a system unit" |
diff --git a/internal/console/fleetbox.go b/internal/console/fleetbox.go| index 000ebfa5b..a3cf2ef96 100644 |
| --- a/internal/console/fleetbox.go |
| +++ b/internal/console/fleetbox.go |
| @@ -183,13 +183,13 @@ func fleetLabelsRecord(rec provision.Record) bool { |
| // platform does not manage (Addr, Addrs), and either a rootfs runtime or a |
| // hibernation that is not switched off. An HA record is never movable: HA |
| // hosts are outside 1b's move machinery (controller ruling 3, Task 6), so a |
| -// fleet holding one is never labelled and a drain refuses it. An always-on |
| -// binary additionally needs the caller's verified selected stateless manifest. |
| +// fleet holding one is never labelled and a drain refuses it. A unit-backed |
| +// record is never movable either, whatever its hibernation, manifest or |
| +// assignment: its system unit belongs to the machine it runs on (M2 review |
| +// P1). An always-on binary additionally needs the caller's verified |
| +// selected stateless manifest. |
| func movable(rec provision.Record, verified ...*release.Manifest) bool { |
| - if rec.Demo != nil || rec.Addr != "" || len(rec.Addrs) > 0 || rec.HA { |
| - return false |
| - } |
| - if rec.Unit != "" && (rec.ReplicaAssignment != nil || len(verified) != 0) { |
| + if neverMovable(rec) { |
| return false |
| } |
| if rec.Runtime == "" && rec.Hibernate != nil && !*rec.Hibernate && len(verified) == 1 { |
| @@ -199,6 +199,12 @@ func movable(rec provision.Record, verified ...*release.Manifest) bool { |
| return rec.Runtime == provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate |
| } |
| +// neverMovable is movable's refusal that no manifest changes: a demo, an |
| +// address the platform does not manage, an HA record or a system unit. |
| +func neverMovable(rec provision.Record) bool { |
| + return rec.Demo != nil || rec.Addr != "" || len(rec.Addrs) > 0 || rec.HA || rec.Unit != "" |
| +} |
| + |
| // movableVerified is movable for a record a label is acted on (R3, #1008 |
| // option B): an always-on binary (no runtime, hibernation switched off) is |
| // judged with its verified selected manifest (replicaSelected), so a |
| @@ -209,6 +215,11 @@ func movable(rec provision.Record, verified ...*release.Manifest) bool { |
| // stateless release, so its destination must be at the stateless runtime |
| // floor (chooseMoveDestination). |
| func (s *Server) movableVerified(ctx context.Context, rec provision.Record) (ok, stateless bool, err error) { |
| + if neverMovable(rec) { |
| + // No manifest can make it movable, so none is read: an unreadable |
| + // one would answer an error for a record that is refused anyway. |
| + return false, false, nil |
| + } |
| if rec.Runtime == "" && rec.Hibernate != nil && !*rec.Hibernate { |
| m, err := s.replicaSelected(ctx, rec) |
| if err != nil { |
diff --git a/internal/console/fleetcreate.go b/internal/console/fleetcreate.go| index a8a3edc5c..06c575163 100644 |
| --- a/internal/console/fleetcreate.go |
| +++ b/internal/console/fleetcreate.go |
| @@ -83,8 +83,8 @@ func (s *Server) fleetCreateApplies(v fleetView, verr error, rec provision.Recor |
| func (s *Server) fleetCreateLabel(ctx context.Context, reg consoleRegistry, fleet string, v fleetView, verr error, rec *provision.Record, head *channelHead) *doorRefusal { |
| unavailable := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msgFleetCreateUnavailable(fleet)} |
| tag := fmt.Sprintf("console: api instances create %s/%s/%s: fleet %s", rec.Account, rec.App, rec.Host, fleet) |
| - // A system unit is never placed on one box (movable admits one with |
| - // default hibernation when it is asked without a manifest). |
| + // A system unit is never placed on one box. movable refuses it too |
| + // (M2 review P1); this answers first, before the manifest is read. |
| if rec.Unit != "" { |
| return &doorRefusal{Status: http.StatusConflict, Msg: msgFleetCreateUnplaceable(rec.Host, unmovableReasonText["unit"])} |
| } |
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go| index dee159088..84267bd9d 100644 |
| --- a/internal/console/fleetrelabel_test.go |
| +++ b/internal/console/fleetrelabel_test.go |
| @@ -990,3 +990,33 @@ func TestUnverifiableManifestLeavesTheRecord(t *testing.T) { |
| t.Fatal("a refused drain marked the box draining") |
| } |
| } |
| + |
| +// M2 review P1 (Astra): a labelled unit-backed record stays on its box. The |
| +// lost-box pass leaves it, and a drain strands its app by name, as every |
| +// other record the platform cannot move. |
| +func TestLostBoxAndDrainLeaveAUnitInPlace(t *testing.T) { |
| + unit := func(r *provision.Record) { r.FleetBox, r.Unit = "pi-1", "shop.service" } |
| + t.Run("lost box", func(t *testing.T) { |
| + fx, _, _ := fleetBoxWorld(t, "code-rl-unit-lost", "pi-1", "pi-2") |
| + putFleetRecord(t, fx, "shop", "a.example.com", unit) |
| + piBeat(t, fx, "pi-1", true, time.Now().Add(-21*time.Minute), release.FleetBoxLabelFloor) |
| + relabelPass(t, fx) |
| + if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-1" || r.FleetBoxMoved { |
| + t.Fatalf("a unit on a lost box: %+v; want left on pi-1", r) |
| + } |
| + }) |
| + t.Run("drain", func(t *testing.T) { |
| + fx, _, reg := fleetBoxWorld(t, "code-rl-unit-drain", "pi-1", "pi-2") |
| + putFleetRecord(t, fx, "shop", "a.example.com", unit) |
| + stuck, err := fx.srv.drainBox(context.Background(), "pi", "pi-1") |
| + if err != nil || len(stuck) != 1 || stuck[0] != "shop" { |
| + t.Fatalf("drainBox = %v, %v; want shop stranded", stuck, err) |
| + } |
| + if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-1" || r.FleetBoxMoved { |
| + t.Fatalf("a refused drain moved the unit: %+v", r) |
| + } |
| + if b := boxRow(t, reg, "pi-1"); b.DrainingSince != 0 { |
| + t.Fatal("a refused drain marked the box draining") |
| + } |
| + }) |
| +} |
diff --git a/internal/console/instancelabel_test.go b/internal/console/instancelabel_test.go| index 2b33f19c0..56c7572bb 100644 |
| --- a/internal/console/instancelabel_test.go |
| +++ b/internal/console/instancelabel_test.go |
| @@ -676,3 +676,29 @@ func TestLabelDoorConcurrentLabels(t *testing.T) { |
| t.Fatalf("record %+v; want labelled pi-1", r) |
| } |
| } |
| + |
| +// M2 review P1 (Astra): a unit-backed record is never tied to one box, |
| +// whatever its hibernation: unset, on or off. The door answers |
| +// unmovable:unit (C31) and neither marks the box nor writes the record. |
| +func TestLabelDoorRefusesAUnitWhateverItsHibernation(t *testing.T) { |
| + on, off := true, false |
| + for _, c := range []struct { |
| + name string |
| + hib *bool |
| + }{{"unset", nil}, {"on", &on}, {"off", &off}} { |
| + t.Run(c.name, func(t *testing.T) { |
| + fx, token, reg, created := labelWorld(t, "code-ld-unit-"+c.name, "pi-1", "pi-2") |
| + servingEvidence(t, fx, reg, created, "pi-1") |
| + editShop(t, fx, func(r *provision.Record) { r.Unit = "shop.service"; r.Hibernate = c.hib }) |
| + cs := newCountStore(fx.srv.cfg.Releases) |
| + fx.srv.cfg.Releases = cs |
| + wantRefused(t, fx, labelPost(t, fx, token, "pi-1", false), "unmovable:unit") |
| + if n := cs.recordPuts(); n != 0 { |
| + t.Fatalf("a refused unit made %d record writes", n) |
| + } |
| + if b := boxRow(t, reg, "pi-1"); b.LabelledAt != 0 { |
| + t.Fatal("pi-1 was marked") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/replicaplacement_fix_test.go b/internal/console/replicaplacement_fix_test.go| index f4424699f..d208d20b2 100644 |
| --- a/internal/console/replicaplacement_fix_test.go |
| +++ b/internal/console/replicaplacement_fix_test.go |
| @@ -219,10 +219,12 @@ func TestReplicaLegacyActiveSwapDoesNotCreateSet(t *testing.T) { |
| } |
| } |
| +// M2 review P1: a unit-backed record is never movable, with or without an |
| +// assignment (it was movable with default hibernation before). |
| func TestReplicaLegacyUnitMovability(t *testing.T) { |
| for _, rec := range []provision.Record{{Unit: "example.service"}, {Unit: "example.service", Runtime: provision.RuntimeRootfsV1}} { |
| - if !movable(rec) { |
| - t.Fatal("legacy unit behaviour changed") |
| + if movable(rec) { |
| + t.Fatal("unit accepted") |
| } |
| rec.ReplicaAssignment = &replicas.Assignment{Desired: 2, Boxes: []string{"a", "b"}} |
| if movable(rec) { |