carlos / platform Public

console: relabel and drain verify always-on stateless records (R3)

movableVerified judges an always-on binary record against its verified
selected manifest (replicaSelected), so a labelled one-copy stateless
record with no assignment moves off a lost or draining box like any
other. relabelFleet and drainBox call it instead of movable. A manifest
that cannot be verified leaves the record where it is, logged with its
host; drain refuses it, naming the app. planFirstLabelling is unchanged.

TestReplicaLegacyDrainAndDiscoveryAfterDecrease pinned the old stranding
of such a record; it now asserts the drain moves it. The activator pin
TestLabelledStatelessRowStartsOnTheNewBox passes with no activator change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 660d7ee02f49bc4eb4eb3df33b106a6a5f48d341 parent 7615022
5 files changed, +199 −6
  • internal/activator/stateless_test.go +36 −0
  • internal/console/fleetbox.go +17 −0
  • internal/console/fleetrelabel.go +15 −2
  • internal/console/fleetrelabel_test.go +111 −0
  • internal/console/replicaplacement_fix_test.go +20 −4

CI failed — run details

Intent

Human

<task-notification> <task-id>a0c925fb35f246f63</task-id> <tool-use-id>toolu_01PykVdFaDWHWDvdC5PZTby3</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ac77363b-5830-422c-9f38-d7f2540dd398/tasks/a0c925fb35f246f63.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2: R2 proven checkpoint" 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_WITH_CONCERNS - **Commits:** - `29fb2695 lease, activator: a fleet stop releases only after a proven checkpoint (R2)` - `1a32206f lease, activator: R2 review fixes (no release when lost, shutdown abandon)` - `7615022c activator, lease: shutdown abandons an in-flight checkpoint directly (R2)` - **Fix:** when Shutdown's budget ends, it now abandons and names every fleet checkpoint that is still running or still pending, itself and without waiting on the call or its context. It no longer waits for those calls, so the unbounded wait is gone. - **Tests:** the 9 activator and 2 lease R2 tests pass with `-count=3`, including Astra's ordering (`TestShutdownAbandonsACheckpointWhoseOwnBudgetEnded`), and again under `-race`. The related lease and activator runs, the darwin build and vet are clean. The new test fails when Shutdown cannot reach a checkpoint still running. That is a simulated failure, not a rerun of round 1's code. - **Concerns:** 1. A rare race can log the C45 ERROR just after Shutdown returns: the deadline has to land while a lost-lease abandonment is already running. The lease is still never released. 2. Two more test seams: `SetCloseProvenReplicaSyncHookForTest` and `checkpointContext`, both nil in production. 3. `CloseProven` now runs litestream's two sync steps itself, so a litestream upgrade must keep that code matching. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-record-labels/.superpowers/sdd/2026-11-14-fleet-record-labels/task-2-report.md</result> <usage><subagent_tokens>319169</subagent_tokens><tool_uses>9</tool_uses><duration_ms>395432</duration_ms></usage> </task-notification>

Attributed to this commit: 8.77 g CO₂e (976,285 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-record-labels, 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/activator/stateless_test.go b/internal/activator/stateless_test.go
index d6f4f0873..6a32cb68b 100644
--- a/internal/activator/stateless_test.go
+++ b/internal/activator/stateless_test.go
@@ -775,3 +775,39 @@ func TestStatelessObservedUnknownReleaseIsHeld(t *testing.T) {
t.Fatalf("incumbent: %+v %v", g, ok)
}
}
+
+// TestLabelledStatelessRowStartsOnTheNewBox (R3, #1008 option B; a pin):
+// a stateless row the console relabelled onto this box (Assigned set,
+// Moved true) starts its stateless generation with no database work. The
+// moved-row start rule (an empty start refused) guards a database the box
+// never had; a stateless generation has none to guard.
+func TestLabelledStatelessRowStartsOnTheNewBox(t *testing.T) {
+ r := newWakeRelRig(t)
+ store := wireStatelessRig(r)
+ r.b.procs["v2"] = map[string]release.Process{release.ProcessWeb: {Command: []string{"serve"}}}
+ r.rt.Region, r.rt.Assigned, r.rt.Moved = "fleet/pi", "2026-11-14T08:00:00.000000000Z", true
+ r.routes.set(r.rt)
+ // The record as the console's relabel left it: on this box, moved.
+ r.a.Fleet = FleetWake{Mode: FleetWakeCheck, Fleet: "pi", Label: "pi-2", Record: func(_ context.Context, rt registry.Route) (*provision.Record, error) {
+ return &provision.Record{Schema: 1, Host: rt.Host, Account: rt.Account, App: rt.App, Region: rt.Region,
+ Channel: rt.Channel, Environment: rt.Environment, Runtime: rt.Runtime, CreatedAt: time.Unix(1, 0),
+ FleetBox: "pi-2", FleetBoxAt: rt.Assigned, FleetBoxMoved: true, ReplicaDeploy: store.snapshot()}, nil
+ }}
+ if err := waitErr(t, r.wake(r.a)); err != nil {
+ t.Fatalf("a moved stateless row did not start: %v", err)
+ }
+ acquires, restores, _ := r.b.counts()
+ if acquires != 0 || restores != 0 || r.b.seedCount() != 0 {
+ t.Fatalf("a moved stateless start did database work: acquire=%d restore=%d seed=%d", acquires, restores, r.b.seedCount())
+ }
+ if len(r.b.started()) == 0 {
+ t.Fatal("a moved stateless row served without a start")
+ }
+ r.a.mu.Lock()
+ e := r.a.entries[r.rt.Host]
+ ok := e != nil && e.gen.Stateless && e.rep == nil && e.proc != nil
+ r.a.mu.Unlock()
+ if !ok {
+ t.Fatal("the moved row's generation is not stateless, or owns a serving replica")
+ }
+}
diff --git a/internal/console/fleetbox.go b/internal/console/fleetbox.go
index fdd43b284..1b082b363 100644
--- a/internal/console/fleetbox.go
+++ b/internal/console/fleetbox.go
@@ -189,6 +189,23 @@ func movable(rec provision.Record, verified ...*release.Manifest) bool {
return rec.Runtime == provision.RuntimeRootfsV1 || rec.Hibernate == nil || *rec.Hibernate
}
+// 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
+// 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) {
+ if rec.Runtime == "" && rec.Hibernate != nil && !*rec.Hibernate {
+ m, err := s.replicaSelected(ctx, rec)
+ if err != nil {
+ return false, err
+ }
+ return movable(rec, m), nil
+ }
+ return movable(rec), nil
+}
+
// atLabelFloor reports whether a platform release parses at or above
// release.FleetBoxLabelFloor. Missing or unparseable is false.
func atLabelFloor(rel string) bool {
diff --git a/internal/console/fleetrelabel.go b/internal/console/fleetrelabel.go
index dc9a125ca..f764399cb 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -172,7 +172,12 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no
if reason == "" {
continue
}
- if !movable(rec) {
+ ok, 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
+ }
+ if !ok {
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
}
@@ -482,7 +487,15 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
if !fleetLabelsRecord(rec) || (rec.FleetBox != "" && rec.FleetBox != label) {
continue
}
- if rec.FleetBox == "" || !movable(rec) {
+ if rec.FleetBox == "" {
+ strand[rec.App] = true
+ continue
+ }
+ ok, 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)
+ }
+ if !ok {
strand[rec.App] = true
continue
}
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go
index e3cf902f4..b5b028cb4 100644
--- a/internal/console/fleetrelabel_test.go
+++ b/internal/console/fleetrelabel_test.go
@@ -774,3 +774,114 @@ func TestDrainRefusedOnAHostClaimConsole(t *testing.T) {
t.Fatalf("drainBox on a host-claim console = %v", err)
}
}
+
+// R3 (#1008 option B): the relabel worker and the drain verify an
+// always-on stateless binary against its selected manifest, so a labelled
+// 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.
+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")
+ 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)
+ }
+ putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) {
+ r.Channel, r.Hibernate, r.FleetBox = channel, new(bool), "pi-1"
+ })
+ return fx, reg
+}
+
+func TestLostBoxMovesAnAlwaysOnStatelessRecord(t *testing.T) {
+ now := time.Now()
+ fx, _ := statelessShopWorld(t, "code-r3-lost", "edge", now)
+ piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.FleetBoxLabelFloor)
+ if err := fx.srv.RunFleetRelabelPass(context.Background(), now); err != nil {
+ t.Fatal(err)
+ }
+ if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-2" || !r.FleetBoxMoved {
+ t.Fatalf("an always-on stateless record on a lost box: %+v; want moved to pi-2", r)
+ }
+}
+
+func TestDrainMovesAnAlwaysOnStatelessRecord(t *testing.T) {
+ fx, reg := statelessShopWorld(t, "code-r3-drain", "edge", time.Now())
+ 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-2" || !r.FleetBoxMoved {
+ t.Fatalf("an always-on stateless record after the drain: %+v; want moved to pi-2", r)
+ }
+ if b := boxRow(t, reg, "pi-1"); b.DrainingSince == 0 {
+ t.Fatal("the drain did not mark pi-1 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) {
+ now := time.Now()
+ fx, _ := statelessShopWorld(t, "code-r3-onecopy", "edge", now)
+ piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.FleetBoxLabelFloor)
+ rec := *shopRec(t, fx, "a.example.com")
+ if rec.ReplicaAssignment != nil {
+ t.Fatalf("the record has an assignment: %+v", rec.ReplicaAssignment)
+ }
+ v, err := fx.srv.loadFleetViewAt(context.Background(), "pi", now)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if action, err := fx.srv.replicaAction(rec, v, 1); err != nil || action.kind != replicaNone {
+ t.Fatalf("replicaAction(one copy, no assignment) = %+v, %v; want nothing", action, err)
+ }
+ if err := fx.srv.RunFleetRelabelPass(context.Background(), now); err != nil {
+ t.Fatal(err)
+ }
+ if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-2" || !r.FleetBoxMoved || r.ReplicaAssignment != nil {
+ t.Fatalf("one-copy stateless record after the pass: %+v; want relabelled to pi-2, no assignment", r)
+ }
+}
+
+// A manifest that cannot be read (the record's channel has no head) leaves
+// the record where it is, logged with its host; the drain refuses it,
+// naming its app.
+func TestUnverifiableManifestLeavesTheRecord(t *testing.T) {
+ now := time.Now()
+ fx, reg := statelessShopWorld(t, "code-r3-unverifiable", "beta", now)
+ piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.FleetBoxLabelFloor)
+ 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("an unverifiable record moved: %+v", r)
+ }
+ if !strings.Contains(logs.String(), "a.example.com") || !strings.Contains(logs.String(), "manifest") {
+ t.Fatalf("no log line names the host and its manifest:\n%s", logs.String())
+ }
+
+ piBeat(t, fx, "pi-1", true, time.Now(), release.FleetBoxLabelFloor)
+ piBeat(t, fx, "pi-2", true, time.Now(), release.FleetBoxLabelFloor)
+ 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")
+ }
+}
diff --git a/internal/console/replicaplacement_fix_test.go b/internal/console/replicaplacement_fix_test.go
index d9813da98..f4424699f 100644
--- a/internal/console/replicaplacement_fix_test.go
+++ b/internal/console/replicaplacement_fix_test.go
@@ -3,7 +3,6 @@ package console
import (
"context"
"reflect"
- "slices"
"strings"
"testing"
"time"
@@ -148,13 +147,30 @@ func TestReplicaLegacyDrainAndDiscoveryAfterDecrease(t *testing.T) {
t.Fatal("legacy app kept polling config", cs.gets)
}
}
- // Inject the stale SQL state too: classification must depend on the record.
+ // Inject the stale SQL state too: classification must depend on the
+ // record. Each converted record is a labelled one-copy always-on
+ // stateless record with a verified manifest, so the drain moves it
+ // (R3, #1008 option B) rather than skipping it as a replica.
if err := fx.st.markReplicaApp(context.Background(), OpsAccountID, "shop", true); err != nil {
t.Fatal(err)
}
+ var onPi1 []string
+ for _, host := range []string{"a.example.com", "b.example.com"} {
+ if shopRec(t, fx, host).FleetBox == "pi-1" {
+ onPi1 = append(onPi1, host)
+ }
+ }
+ if len(onPi1) == 0 {
+ t.Fatal("no converted record is on pi-1; the drain proves nothing")
+ }
stuck, err := fx.srv.drainBox(context.Background(), "pi", "pi-1")
- if err != nil || !slices.Equal(stuck, []string{"shop"}) {
- t.Fatalf("stranded app was hidden: %v %v", stuck, err)
+ if err != nil || len(stuck) != 0 {
+ t.Fatalf("drainBox = %v, %v; want nothing stranded", stuck, err)
+ }
+ for _, host := range onPi1 {
+ if r := shopRec(t, fx, host); r.FleetBox != "pi-2" || !r.FleetBoxMoved || r.ReplicaAssignment != nil {
+ t.Fatalf("the drain hid %s: %+v", host, r)
+ }
}
}