carlos / platform Public

console: refuse unmovable trashed records; bump serial on relabels

F1: a trashed app's unlabelled record is excused from a drain only when
movableVerified says it could move and another box could carry it. A
unit or unmanaged-address record now strands the drain as before.

F2: writeRelabels bumps the serial once when any record moved, as the
label door does, so a running survivor takes the routes at once. The
bump is detached from the caller's context, so moves that land before a
detach timeout are still announced.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev bfdfa287b3314f51f357969c54ad27c2fab48db1 parent 3cb58d8
2 files changed, +154 −9
  • internal/console/fleetrelabel.go +20 −9
  • internal/console/fleetrelabel_test.go +134 −0

CI failed — run details

Intent

Attributed to this commit: 15.6 g CO₂e (1,862,170 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 2a084c5d6..9abb17189 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -256,7 +256,8 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no
}
// writeRelabels makes plan's writes, each marking its box labelled first,
-// and answers how many records were written.
+// announces them with one serial bump when any landed, and answers how
+// many records were written.
func (s *Server) writeRelabels(ctx context.Context, fleet string, plan []relabel, now time.Time) int {
if len(plan) == 0 {
return 0
@@ -294,6 +295,14 @@ func (s *Server) writeRelabels(ctx context.Context, fleet string, plan []relabel
log.Printf("console: fleet relabel %s: %s from %s to %s (%s)", fleet, p.rec.Host, boxOrNone(p.rec.FleetBox), p.to, p.reason)
}
}
+ if moved > 0 {
+ // A box-consumed write, announced once for the pass as the label
+ // door announces its own: a running box drops or takes the routes
+ // now rather than at its next instance pass. bumpSerial is
+ // detached from ctx, so moves that landed before a caller's
+ // timeout (a detach door's) are still announced.
+ s.bumpSerial(ctx)
+ }
return moved
}
@@ -564,20 +573,22 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
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)
+ // The survivor must also be able to run what a restore would
+ // bring back, the same test the labelled path asks below. The
+ // record must be movable (movableVerified's ok): one that never
+ // is (a system unit, which belongs to this machine; an
+ // unmanaged address) would come back unlabelled to a survivor
+ // that lacks it, and no pass labels it. An always-on stateless
+ // one needs a box at the stateless runtime floor. A manifest
+ // that cannot be verified strands the drain.
+ 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)
jobFailed(ctx, err)
strand[rec.App] = true
continue
}
- if v.chooseMoveDestination(rootfs, stateless, label) == "" {
+ if !ok || v.chooseMoveDestination(rootfs, stateless, label) == "" {
strand[rec.App] = true
continue
}
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go
index 09fb2343f..a63a67e46 100644
--- a/internal/console/fleetrelabel_test.go
+++ b/internal/console/fleetrelabel_test.go
@@ -1581,3 +1581,137 @@ func TestGoneLabelledBox(t *testing.T) {
})
}
}
+
+// Final review F1: a trashed app's unlabelled record is excused only when
+// it could move (movableVerified ok) and another box could carry it. One
+// that can never move (a system unit, which belongs to the machine; an
+// unmanaged upstream address) would be lost with the drained machine: a
+// restore brings it back unlabelled to a survivor that lacks it, and no
+// pass labels it. It strands the drain, with nothing written.
+func TestDrainRefusesATrashedAppsUnmovableUnlabelledRecord(t *testing.T) {
+ cases := map[string]func(*provision.Record){
+ "unit": func(r *provision.Record) { r.Unit = "blog.service" },
+ "addr": func(r *provision.Record) { r.Addr = "127.0.0.1:9000" },
+ }
+ for name, mut := range cases {
+ t.Run(name, func(t *testing.T) {
+ ctx := context.Background()
+ fx, _, reg := fleetBoxWorld(t, "code-rl-trash-unmovable-"+name, "pi-1", "pi-2")
+ placeBlog(t, fx)
+ putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) { r.FleetBox = "pi-1" })
+ putFleetRecord(t, fx, "blog", "x.example.com", mut) // unlabelled, never movable
+ if err := release.TrashApp(ctx, fx.rel, fx.sqid, "blog", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if ok, _, err := fx.srv.movableVerified(ctx, *mustRecord(t, fx, "blog", "x.example.com")); ok || err != nil {
+ t.Fatalf("movableVerified = %v, %v; the witness needs a record that cannot move", ok, 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{"blog"}) {
+ t.Fatalf("drainBox = %v, %v; want blog 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")
+ }
+ })
+ }
+}
+
+// mustRecord reads app's record of h.
+func mustRecord(t *testing.T, fx *consoleFixture, app, h string) *provision.Record {
+ t.Helper()
+ rec, err := provision.GetRecord(context.Background(), fx.rel, fx.sqid, app, h)
+ if err != nil {
+ t.Fatalf("read %s/%s: %v", app, h, err)
+ }
+ return rec
+}
+
+// serialOf reads the bucket's serial.
+func serialOf(t *testing.T, fx *consoleFixture) int64 {
+ t.Helper()
+ doc, _, err := release.ReadSerial(context.Background(), fx.rel)
+ if err != nil {
+ t.Fatalf("read serial: %v", err)
+ }
+ return doc.Serial
+}
+
+// Final review F2: a label move is a write the boxes consume, so it is
+// announced (the serial is bumped) once the writes land, as the label
+// door does; a survivor that is already running then drops or takes the
+// routes at once rather than at its next instance pass. A pass that moves
+// nothing does not bump. Each door that moves records: the worker, the
+// drain and the detach doors.
+func TestRelabelMovesBumpTheSerial(t *testing.T) {
+ t.Run("worker", func(t *testing.T) {
+ ctx := context.Background()
+ now := time.Now()
+ fx, _, _ := fleetBoxWorld(t, "code-rl-serial-worker", "pi-1", "pi-2")
+ putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) { r.FleetBox = "pi-1" })
+ piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.FleetBoxLabelFloor)
+ before := serialOf(t, fx)
+ if err := fx.srv.fleetRelabelPass(ctx, now); err != nil {
+ t.Fatal(err)
+ }
+ wantMovedTo(t, shopRec(t, fx, "a.example.com"), "pi-2")
+ moved := serialOf(t, fx)
+ if moved <= before {
+ t.Fatalf("a pass that moved a record left the serial at %d (before %d)", moved, before)
+ }
+ // The next pass has nothing to move: no announcement.
+ if err := fx.srv.fleetRelabelPass(ctx, now.Add(time.Minute)); err != nil {
+ t.Fatal(err)
+ }
+ if got := serialOf(t, fx); got != moved {
+ t.Fatalf("an idle pass bumped the serial: %d, was %d", got, moved)
+ }
+ })
+ t.Run("drain", func(t *testing.T) {
+ fx, _, _ := fleetBoxWorld(t, "code-rl-serial-drain", "pi-1", "pi-2")
+ putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) { r.FleetBox = "pi-1" })
+ before := serialOf(t, fx)
+ if stuck, err := fx.srv.drainBox(context.Background(), "pi", "pi-1"); err != nil || len(stuck) != 0 {
+ t.Fatalf("drainBox = %v, %v", stuck, err)
+ }
+ wantMovedTo(t, shopRec(t, fx, "a.example.com"), "pi-2")
+ if got := serialOf(t, fx); got <= before {
+ t.Fatalf("a drain that moved a record left the serial at %d (before %d)", got, before)
+ }
+ })
+ t.Run("detach", func(t *testing.T) {
+ fx, token, _ := soleSurvivorWorld(t, "code-rl-serial-detach", nil)
+ before := serialOf(t, fx)
+ if code, raw := detachAPI(t, fx, token, "pi-2", true); code != http.StatusOK {
+ t.Fatalf("API detach = %d %s", code, raw)
+ }
+ wantMovedTo(t, shopRec(t, fx, "b.example.com"), "pi-1")
+ if got := serialOf(t, fx); got <= before {
+ t.Fatalf("a detach that moved records left the serial at %d (before %d)", got, before)
+ }
+ })
+ t.Run("cancelled context", func(t *testing.T) {
+ // The writes landed before the caller's context ended (a detach
+ // that timed out mid-plan): they are still announced.
+ fx, _, reg := fleetBoxWorld(t, "code-rl-serial-cancel", "pi-1", "pi-2")
+ putFleetRecord(t, fx, "shop", "a.example.com", func(r *provision.Record) { r.FleetBox = "pi-1" })
+ if err := reg.MarkFleetBoxLabelled("pi", "pi-2", time.Now().UnixNano()); err != nil {
+ t.Fatal(err)
+ }
+ before := serialOf(t, fx)
+ ctx, cancel := context.WithCancel(context.Background())
+ plan := []relabel{{rec: *shopRec(t, fx, "a.example.com"), to: "pi-2", reason: "test"}}
+ cancel()
+ if moved := fx.srv.writeRelabels(ctx, "pi", plan, time.Now()); moved != 1 {
+ t.Fatalf("writeRelabels moved %d; want 1", moved)
+ }
+ if got := serialOf(t, fx); got <= before {
+ t.Fatalf("a move under a cancelled context left the serial at %d (before %d)", got, before)
+ }
+ })
+}