carlos / platform Public

console: a trashed record's survivor must run its stateless release

Review fix round 2 (P1): the survivor check passed stateless=false, so a
trashed always-on stateless record was excused when the only other box
was below the stateless runtime floor; a restore after the drained box
is terminated would leave no box able to run it.

The excuse now asks movableVerified of the record, as the labelled path
does, and passes its stateless answer to chooseMoveDestination. Its ok
plays no part (the record is left, not moved); a manifest that cannot
be verified strands the drain. The excuse is logged only once the
record is actually excused.

Witness: a mixed-version fleet (drained box at the stateless floor, the
survivor only at the label floor) refuses the drain, naming the app.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 234f819bc60e73505bd2a8ff990b72a7bdfcd428 parent 800aec3
2 files changed, +75 −9
  • internal/console/fleetrelabel.go +31 −7
  • internal/console/fleetrelabel_test.go +44 −2

Intent

Human

<task-notification> <task-id>ac6d0304ce4186349</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/24f2e8d0-8e47-4773-a96b-f7e9260c860f/tasks/ac6d0304ce4186349.output</output-file> <status>completed</status> <summary>Agent "Implement Task 1: trashed app drain" 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: 21f33841 console: a trashed app's unlabelled record no longer holds a drain; 800aec35 console: excuse a trashed record only when another box can carry it Tests: the 5 trash-drain tests pass (3 s) and the step-6 pattern passes (284 s); gofmt and vet are clean. The new one-box test failed with the survivor check disabled (`drainBox = []`) and passes with it. Fix: a trashed app's unlabelled record is excused only if `v.chooseMoveDestination(rootfs, false, label)` finds another box. Otherwise it strands the drain as before and the trash marker is not read. Race witness: I wrote the restore-mid-drain test the reviewer asked for, not the fallback. There is no seam in the production code, but a test store wrapper can restore the app right after the drain reads the marker. The test checks that the record was not written, stays unlabelled on fleet/pi, and that pi-2 can carry it. It passes with or without the fix, so it pins why the race is safe rather than proving the fix. Concerns: - The survivor check passes stateless=false because the manifest isn't verified on this path; a reviewer may want true for always-on records. - The console without the release public key strands the drain when a production flag exists; the box would treat the flag as clear. This is the safe direction. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/fleet-drain-followups/.superpowers/sdd/2026-11-15-fleet-drain-followups/task-1-report.md (fix report appended)</result> <usage><subagent_tokens>99700</subagent_tokens><tool_uses>13</tool_uses><duration_ms>452681</duration_ms></usage> </task-notification>

Attributed to this commit: 5.35 g CO₂e (593,638 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on fleet-drain-followups, 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/console/fleetrelabel.go b/internal/console/fleetrelabel.go
index 198a5925b..1513a1da3 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -379,7 +379,8 @@ func (e *fleetPausedError) Error() string { return msgLabelsPaused(e.fleet, e.bo
// nothing written. A record cannot move when it is unlabelled (every box
// runs it), unless its app is in the Trash and the boxes have retired its
// routes (trashRetired) and another box of the fleet could carry it
-// (chooseMoveDestination, excluding this one): such a record is not
+// (chooseMoveDestination, excluding this one, with the stateless answer of
+// movableVerified, whose error strands the drain): such a record is not
// served, every remaining box still carries it, and a restore mints it
// again from the record, so it does not hold the drain and is left
// unlabelled. On the fleet's last box it still holds the drain: a restore
@@ -460,6 +461,7 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
// one flag read per app per drain, only for apps with an unlabelled
// record here.
retired := map[AppRef]bool{}
+ excused := map[AppRef]bool{} // apps whose excuse was logged
var plan []relabel
for _, rec := range recs {
if rec.ReplicaAssignment != nil {
@@ -473,8 +475,11 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
// the fleet that could carry the record (chooseMoveDestination,
// excluding this one). On the fleet's last box a restore racing
// the drain would leave the instance with no box at all, so
- // there the record strands the drain as before.
- if v.chooseMoveDestination(rec.Runtime == provision.RuntimeRootfsV1, false, label) == "" {
+ // there the record strands the drain as before. This first
+ // test reads nothing; the stateless one below needs the
+ // manifest and is asked only of a trashed app's record.
+ rootfs := rec.Runtime == provision.RuntimeRootfsV1
+ if v.chooseMoveDestination(rootfs, false, label) == "" {
strand[rec.App] = true
continue
}
@@ -483,17 +488,36 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
if !seen {
var err error
gone, err = s.trashRetired(ctx, rec.Account, rec.App)
- switch {
- case err != nil:
+ if err != nil {
log.Printf("console: fleet drain %s/%s: %s/%s: trash state unreadable: %v; treated as served", fleet, label, rec.Account, rec.App, err)
gone = false
- case gone:
- log.Printf("console: fleet drain %s/%s: %s/%s is in the trash and its routes are retired; its unlabelled records stay as they are and do not hold the drain", fleet, label, rec.Account, rec.App)
}
retired[ref] = gone
}
if !gone {
strand[rec.App] = true
+ continue
+ }
+ // The survivor must also run the release a restore would bring
+ // back: an always-on stateless one needs a box at the stateless
+ // runtime floor, the same test the labelled path asks below.
+ // movableVerified's ok plays no part: an unlabelled record is
+ // not moved, only left, so only its stateless answer counts.
+ // A manifest that cannot be verified strands the drain.
+ _, 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)
+ jobFailed(ctx, err)
+ strand[rec.App] = true
+ continue
+ }
+ if v.chooseMoveDestination(rootfs, stateless, label) == "" {
+ strand[rec.App] = true
+ continue
+ }
+ if !excused[ref] {
+ excused[ref] = true
+ log.Printf("console: fleet drain %s/%s: %s/%s is in the trash and its routes are retired; its unlabelled records stay as they are and do not hold the drain", fleet, label, rec.Account, rec.App)
}
continue
}
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go
index 787ee2592..37afebe35 100644
--- a/internal/console/fleetrelabel_test.go
+++ b/internal/console/fleetrelabel_test.go
@@ -652,8 +652,50 @@ func TestDrainRacingARestoreLeavesTheInstanceOnTheSurvivor(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if !v.validDestination("pi-2", r.Runtime == provision.RuntimeRootfsV1) {
- t.Fatalf("pi-2 cannot carry the restored instance: %+v", v.Boxes)
+ _, stateless, err := fx.srv.movableVerified(ctx, *r)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if to := v.chooseMoveDestination(r.Runtime == provision.RuntimeRootfsV1, stateless, "pi-1"); to != "pi-2" {
+ t.Fatalf("the restored instance's survivor = %q; want pi-2, able to run it (stateless %v): %+v", to, stateless, v.Boxes)
+ }
+}
+
+// Fix round 2 (review P1): the survivor must be able to run the release a
+// restore brings back. shop's trashed always-on stateless record is
+// unlabelled; pi-1 is at the stateless runtime floor, pi-2 only at the
+// label floor. Draining pi-1 would leave a restored shop on a box that
+// cannot run it, so the drain refuses, naming shop, and writes nothing.
+func TestDrainRefusesATrashedStatelessRecordWithNoCapableSurvivor(t *testing.T) {
+ ctx := context.Background()
+ now := time.Now()
+ fx, _, reg := fleetBoxWorld(t, "code-rl-trash-stateless", "pi-1", "pi-2")
+ shipStatelessFloorRelease(t, fx, "shop", "v1")
+ if err := release.Promote(ctx, fx.rel, fx.priv, fx.sqid, "shop", "edge", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ piBeat(t, fx, "pi-1", true, now, release.StatelessRuntimeFloor)
+ piBeat(t, fx, "pi-2", true, now, release.FleetBoxLabelFloor)
+ putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) {
+ r.Channel, r.Hibernate = "edge", new(bool) // always-on, unlabelled
+ })
+ if err := release.TrashApp(ctx, fx.rel, fx.sqid, "shop", "paul@keymail.dev", now); err != nil {
+ t.Fatal(err)
+ }
+ if _, stateless, err := fx.srv.movableVerified(ctx, *shopRec(t, fx, "a.example.com")); err != nil || !stateless {
+ t.Fatalf("movableVerified: stateless %v, %v; the witness needs a stateless release", stateless, err)
+ }
+ cs := newCountStore(fx.rel)
+ fx.srv.cfg.Releases = cs
+ stuck, err := fx.srv.drainBox(ctx, "pi", "pi-1")
+ if err != nil || !slices.Equal(stuck, []string{"shop"}) {
+ t.Fatalf("drainBox = %v, %v; want shop stranded", stuck, err)
+ }
+ if n := cs.recordPuts(); n != 0 {
+ t.Fatalf("a refused drain wrote %d records", n)
+ }
+ if b := boxRow(t, reg, "pi-1"); b.DrainingSince != 0 {
+ t.Fatal("a refused drain marked the box draining")
}
}