carlos / platform Public

console: stateless moves need the runtime floor (M1 review P1)

movableVerified now reports whether the verified selected release is
stateless, and the relabel worker and the drain choose with
chooseMoveDestination, which also requires release.StatelessRuntimeFloor
for such a record, as one-copy placement does. With no eligible box the
relabel logs and leaves the record and the drain strands its app. The
stateless world fixture now beats its destinations at v0.34.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a0de4b155a0444961d8acf6c6672a710a423115b parent 534312d
3 files changed, +112 −19
  • internal/console/fleetbox.go +19 −6
  • internal/console/fleetrelabel.go +8 −7
  • internal/console/fleetrelabel_test.go +85 −6
diff --git a/internal/console/fleetbox.go b/internal/console/fleetbox.go
index 1b082b363..000ebfa5b 100644
--- a/internal/console/fleetbox.go
+++ b/internal/console/fleetbox.go
@@ -146,9 +146,19 @@ func (v fleetView) labelActive() bool {
// ties broken by label. "" when there is none. It asks nothing of the other
// boxes, so a survivor is chosen whatever state its siblings are in.
func (v fleetView) chooseDestination(rootfs bool, exclude string) string {
+ return v.chooseMoveDestination(rootfs, false, exclude)
+}
+
+// chooseMoveDestination is chooseDestination for a record a label is acted
+// on (the relabel worker and the drain). A record whose verified selected
+// release is stateless (movableVerified) also needs a box at the stateless
+// runtime floor (release.StatelessRuntimeFloor), above the label floor, as
+// one-copy placement asks (replicaCandidates): a box below it cannot run
+// the release (M1 review Astra P1-1).
+func (v fleetView) chooseMoveDestination(rootfs, stateless bool, exclude string) string {
best, bestLoad := "", 0
for _, b := range v.Boxes {
- if b.Label == exclude || !b.destinationFor(rootfs) {
+ if b.Label == exclude || !b.destinationFor(rootfs) || (stateless && !atStatelessRuntimeFloor(b.Release)) {
continue
}
load := v.Load[b.Label]
@@ -194,16 +204,19 @@ func movable(rec provision.Record, verified ...*release.Manifest) bool {
// judged with its verified selected manifest (replicaSelected), so a
// labelled one-copy stateless record moves like any other. Every other
// record is movable(rec). A manifest that cannot be read or verified is
-// (false, err): the caller logs it and leaves the record where it is.
-func (s *Server) movableVerified(ctx context.Context, rec provision.Record) (bool, error) {
+// (false, false, err): the caller logs it and leaves the record where it
+// is. stateless reports that the verified selected manifest declares a
+// 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 rec.Runtime == "" && rec.Hibernate != nil && !*rec.Hibernate {
m, err := s.replicaSelected(ctx, rec)
if err != nil {
- return false, err
+ return false, false, err
}
- return movable(rec, m), nil
+ return movable(rec, m), m != nil && m.Stateless, nil
}
- return movable(rec), nil
+ return movable(rec), false, nil
}
// atLabelFloor reports whether a platform release parses at or above
diff --git a/internal/console/fleetrelabel.go b/internal/console/fleetrelabel.go
index 36adf70d1..740f0865a 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -29,9 +29,10 @@ import (
// same test, labelsPausedBy.
// - Otherwise, when the view was read whole: a record labelled to a box
// that is draining, lost (no heartbeat for fleetBoxLostAfter) or no
-// longer an active box of the fleet moves to chooseDestination(rootfs,
-// its box) (rules 4 and 5). Moving needs no open activation gate
-// (controller ruling 1).
+// longer an active box of the fleet moves to chooseMoveDestination
+// (rootfs, stateless, its box) (rules 4 and 5); a stateless release
+// moves only to a box at the stateless runtime floor. Moving needs no
+// open activation gate (controller ruling 1).
// - The worker never writes a first label (fleet record labels spec §6
// D2): an unlabelled record stays unlabelled, whatever its binding
// says. A first label is written at create, never by this worker,
@@ -163,7 +164,7 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no
if reason == "" {
continue
}
- ok, err := s.movableVerified(ctx, rec)
+ ok, stateless, err := s.movableVerified(ctx, rec)
if err != nil {
log.Printf("console: fleet relabel %s: %s on %s (%s): its manifest cannot be verified: %v; left", fleet, rec.Host, rec.FleetBox, reason, err)
continue
@@ -172,7 +173,7 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no
log.Printf("console: fleet relabel %s: %s on %s (%s) is not a record the platform can move; left", fleet, rec.Host, rec.FleetBox, reason)
continue
}
- to := v.chooseDestination(rec.Runtime == provision.RuntimeRootfsV1, rec.FleetBox)
+ to := v.chooseMoveDestination(rec.Runtime == provision.RuntimeRootfsV1, stateless, rec.FleetBox)
if to == "" {
log.Printf("console: fleet relabel %s: %s on %s (%s) has no box to move to; left", fleet, rec.Host, rec.FleetBox, reason)
continue
@@ -456,7 +457,7 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
strand[rec.App] = true
continue
}
- ok, err := s.movableVerified(ctx, rec)
+ ok, stateless, err := s.movableVerified(ctx, rec)
if err != nil {
log.Printf("console: fleet drain %s/%s: %s: its manifest cannot be verified: %v; left", fleet, label, rec.Host, err)
}
@@ -464,7 +465,7 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
strand[rec.App] = true
continue
}
- to := v.chooseDestination(rec.Runtime == provision.RuntimeRootfsV1, label)
+ to := v.chooseMoveDestination(rec.Runtime == provision.RuntimeRootfsV1, stateless, label)
if to == "" {
strand[rec.App] = true
continue
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go
index 4a67b0431..dee159088 100644
--- a/internal/console/fleetrelabel_test.go
+++ b/internal/console/fleetrelabel_test.go
@@ -5,8 +5,10 @@ import (
"context"
"encoding/json"
"errors"
+ "maps"
"net/http"
"net/url"
+ "slices"
"strings"
"testing"
"time"
@@ -806,18 +808,27 @@ func TestDrainRefusedOnAHostClaimConsole(t *testing.T) {
// one-copy stateless record moves off a lost or draining box like any
// other. shop's edge channel heads a stateless binary release, v1.
-// statelessShopWorld is fleetBoxWorld with pi-1 and pi-2 beating at now,
-// shop's edge head a stateless binary v1, and an always-on binary record
-// of shop at a.example.com labelled pi-1, on channel.
+// statelessShopWorld is fleetBoxWorld with pi-1 and pi-2 beating at now
+// at the stateless runtime floor, shop's edge head a stateless binary v1,
+// and an always-on binary record of shop at a.example.com labelled pi-1,
+// on channel.
func statelessShopWorld(t *testing.T, code, channel string, now time.Time) (*consoleFixture, *registry.Registry) {
t.Helper()
- fx, _, reg := fleetBoxWorld(t, code, "pi-1", "pi-2")
+ return statelessShopWorldOn(t, code, channel, now, map[string]string{"pi-1": release.StatelessRuntimeFloor, "pi-2": release.StatelessRuntimeFloor})
+}
+
+// statelessShopWorldOn is statelessShopWorld whose boxes (pi-1 among them)
+// beat at now at the releases in beats.
+func statelessShopWorldOn(t *testing.T, code, channel string, now time.Time, beats map[string]string) (*consoleFixture, *registry.Registry) {
+ t.Helper()
+ labels := slices.Sorted(maps.Keys(beats))
+ fx, _, reg := fleetBoxWorld(t, code, labels...)
shipStatelessFloorRelease(t, fx, "shop", "v1")
if err := release.Promote(context.Background(), fx.rel, fx.priv, fx.sqid, "shop", "edge", "v1"); err != nil {
t.Fatal(err)
}
- for _, b := range []string{"pi-1", "pi-2"} {
- piBeat(t, fx, b, true, now, release.FleetBoxLabelFloor)
+ for _, b := range labels {
+ piBeat(t, fx, b, true, now, beats[b])
}
putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) {
r.Channel, r.Hibernate, r.FleetBox = channel, new(bool), "pi-1"
@@ -851,6 +862,74 @@ func TestDrainMovesAnAlwaysOnStatelessRecord(t *testing.T) {
}
}
+// A stateless release needs a box at the stateless runtime floor
+// (release.StatelessRuntimeFloor), above the label floor. A lost or
+// drained always-on stateless record moves only to such a box: pi-2 is at
+// the label floor alone and would win the tie on its label, so the record
+// goes to pi-3 (M1 review Astra P1-1).
+func TestStatelessMoveSkipsABoxBelowTheRuntimeFloor(t *testing.T) {
+ beats := map[string]string{"pi-1": release.StatelessRuntimeFloor, "pi-2": release.FleetBoxLabelFloor, "pi-3": release.StatelessRuntimeFloor}
+ t.Run("lost box", func(t *testing.T) {
+ now := time.Now()
+ fx, _ := statelessShopWorldOn(t, "code-r3-floor-lost", "edge", now, beats)
+ piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.StatelessRuntimeFloor)
+ if err := fx.srv.RunFleetRelabelPass(context.Background(), now); err != nil {
+ t.Fatal(err)
+ }
+ if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-3" || !r.FleetBoxMoved {
+ t.Fatalf("a stateless record on a lost box: %+v; want moved to pi-3", r)
+ }
+ })
+ t.Run("drain", func(t *testing.T) {
+ fx, _ := statelessShopWorldOn(t, "code-r3-floor-drain", "edge", time.Now(), beats)
+ stuck, err := fx.srv.drainBox(context.Background(), "pi", "pi-1")
+ if err != nil || len(stuck) != 0 {
+ t.Fatalf("drainBox = %v, %v; want nothing stranded", stuck, err)
+ }
+ if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-3" || !r.FleetBoxMoved {
+ t.Fatalf("a stateless record after the drain: %+v; want moved to pi-3", r)
+ }
+ })
+}
+
+// With no other box at the stateless runtime floor, the record is left:
+// the relabel worker logs it, and the drain strands it, naming its app.
+func TestStatelessMoveWithNoBoxAtTheRuntimeFloor(t *testing.T) {
+ beats := map[string]string{"pi-1": release.StatelessRuntimeFloor, "pi-2": release.FleetBoxLabelFloor}
+ t.Run("lost box", func(t *testing.T) {
+ now := time.Now()
+ fx, _ := statelessShopWorldOn(t, "code-r3-nofloor-lost", "edge", now, beats)
+ piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.StatelessRuntimeFloor)
+ before := *shopRec(t, fx, "a.example.com")
+ var logs bytes.Buffer
+ restore := captureLogTo(&logs)
+ err := fx.srv.RunFleetRelabelPass(context.Background(), now)
+ restore()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-1" || r.FleetBoxMoved || r.FleetBoxAt != before.FleetBoxAt {
+ t.Fatalf("a stateless record moved below the runtime floor: %+v", r)
+ }
+ if !strings.Contains(logs.String(), "a.example.com") || !strings.Contains(logs.String(), "no box to move to") {
+ t.Fatalf("no log line names the host left without a box:\n%s", logs.String())
+ }
+ })
+ t.Run("drain", func(t *testing.T) {
+ fx, reg := statelessShopWorldOn(t, "code-r3-nofloor-drain", "edge", time.Now(), beats)
+ 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" {
+ t.Fatalf("a refused drain moved a to %q", r.FleetBox)
+ }
+ if b := boxRow(t, reg, "pi-1"); b.DrainingSince != 0 {
+ t.Fatal("a refused drain marked the box draining")
+ }
+ })
+}
+
// One copy and no assignment: replica placement does nothing with the
// record, so the relabel is what moves it.
func TestOneCopyStatelessFailsOverWithoutAssignment(t *testing.T) {