console: move a detached box's records to the sole survivor
#1008 T9 finding 2: after detach-box --terminated on a two-box fleet, records labelled to the detached box stayed tied to it and answered 503, because the relabel worker acted only on an Active view (two or more active boxes). The worker now loads its view through relabelView, which reads a one-box fleet whole when goneLabelledBox holds (exactly one active box and a non-active box that was named on a record). relabelFleet gates on v.Complete instead of v.Active; v.Active keeps its meaning for the create door, replica placement and the label door. Both detach doors run the fleet's relabel at once under the lock they hold (relabelAfterDetach, best effort, 20 s bound, off on a host-claim console); their answers are unchanged. R2 and R3 are unchanged: every move is SetRecordFleetBox (FleetBoxMoved) and still goes through movableVerified and chooseMoveDestination, so a stale, draining, not-ready or below-floor survivor takes nothing. TestReplicaLegacyRelabelSurvivesEarlyReturn/incomplete built an Active-but-incomplete view the loader never makes; its incomplete view now goes to replica placement alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/fleetbox.go+4 −1internal/console/fleetbox_test.go+7 −2internal/console/fleetrelabel.go+70 −4internal/console/fleetrelabel_test.go+273 −0internal/console/fleets.go+2 −0internal/console/replicaplacement_fix_test.go+6 −2
Intent
<task-notification> <task-id>ac6d0304ce4186349</task-id> <tool-use-id>toolu_01RrrQs5BzNkkE63AT1veWi9</tool-use-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 - 234f819b console: a trashed record's survivor must run its stateless release Tests: the 6 trash-drain tests pass (3.4 s) and the step-6 pattern passes (283.6 s); gofmt and vet are clean. The new mixed-version test failed with stateless forced to false (`drainBox = []`) and passes with the fix. Fix: an excused record now goes through `movableVerified`, and its stateless answer is passed to `chooseMoveDestination`. If the manifest can't be verified, the record strands the drain. `ok` is ignored, with a comment saying why, because the record is left in place, not moved. The race test's final check now includes stateless capability. One addition beyond the ruling: the "in the trash ... do not hold the drain" log line now prints only when a record is actually excused, so it can't announce an excuse the stateless check then withdraws. Concern: a console without the release public key still strands the drain when a production flag exists, where the box would act on the trash marker. 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 (round 2 appended)</result> <usage><subagent_tokens>115178</subagent_tokens><tool_uses>7</tool_uses><duration_ms>417012</duration_ms></usage> </task-notification>
Attributed to this commit: 4.67 g CO₂e (495,275 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/fleetbox.go b/internal/console/fleetbox.go| index a3cf2ef96..a3e5b1d64 100644 |
| --- a/internal/console/fleetbox.go |
| +++ b/internal/console/fleetbox.go |
| @@ -45,7 +45,10 @@ import ( |
| // records count toward neither (fleetLabelsRecord). Records is the |
| // inventory the view was built from (every record placed on the fleet, |
| // static ones included), read only when the fleet has two or more active |
| -// boxes; the relabel worker and the drain act on it. |
| +// boxes; the relabel worker and the drain act on it. Complete: every read |
| +// above was whole; on a one-box view it is set only when the caller asked |
| +// for the whole view, as the relabel worker does for a fleet whose other |
| +// box was detached after being named on a record (relabelView). |
| type fleetView struct { |
| Boxes []fleetBoxView |
| Active, HasSidecars, DeploymentCurrent bool |
diff --git a/internal/console/fleetbox_test.go b/internal/console/fleetbox_test.go| index 8e37993db..70352aa3b 100644 |
| --- a/internal/console/fleetbox_test.go |
| +++ b/internal/console/fleetbox_test.go |
| @@ -418,10 +418,15 @@ func (c *countStore) getsOf(keys ...string) int { |
| return n |
| } |
| -func (c *countStore) listsOf(prefix string) int { |
| +// listsOf is how many listings of prefixes were made. |
| +func (c *countStore) listsOf(prefixes ...string) int { |
| c.mu.Lock() |
| defer c.mu.Unlock() |
| - return c.lists[prefix] |
| + n := 0 |
| + for _, p := range prefixes { |
| + n += c.lists[p] |
| + } |
| + return n |
| } |
| func TestInventoryRereadsOnlyChangedRecords(t *testing.T) { |
diff --git a/internal/console/fleetrelabel.go b/internal/console/fleetrelabel.go| index 1513a1da3..2a084c5d6 100644 |
| --- a/internal/console/fleetrelabel.go |
| +++ b/internal/console/fleetrelabel.go |
| @@ -20,7 +20,9 @@ import ( |
| // Managed fleets 1b, Task 6 (spec "1b addendum", rules 2, 4, 5, 8, 11). |
| // |
| // The relabel worker, FleetRelabel, runs one pass every five minutes. Per |
| -// fleet, under the fleet's lock and from one loadFleetView: |
| +// fleet, under the fleet's lock and from one relabelView (loadFleetView, |
| +// read whole also for a fleet left with one active box after a box named |
| +// on a record was detached, #1008 T9 finding 2): |
| // |
| // - When the fleet has labels and one of its boxes reports a release |
| // below release.FleetBoxLabelFloor, the pass logs an ERROR naming the |
| @@ -56,7 +58,9 @@ import ( |
| // records leave. The worker finishes any move the drain could not make at |
| // once. The detach doors refuse a box the console ever named on a record |
| // unless the request confirms its machine is terminated (rule 5, |
| -// detachHeld). |
| +// detachHeld). A detach door then runs the fleet's relabel at once under |
| +// the lock it holds (relabelAfterDetach), so the detached box's records |
| +// move to a survivor without waiting for the worker. |
| // fleetRelabelInterval is the worker's period. |
| const fleetRelabelInterval = 5 * time.Minute |
| @@ -115,7 +119,7 @@ func (s *Server) fleetRelabelPass(ctx context.Context, now time.Time) error { |
| ctx = withWriteMemo(ctx) |
| for _, f := range fleets { |
| unlock := s.lockFleet(f.Name) |
| - v, err := s.loadFleetViewAt(ctx, f.Name, now) |
| + v, err := s.relabelView(ctx, f.Name, now) |
| if err != nil { |
| log.Printf("console: fleet relabel %s: view: %v", f.Name, err) |
| jobFailed(ctx, err) |
| @@ -135,6 +139,63 @@ func (s *Server) fleetRelabelPass(ctx context.Context, now time.Time) error { |
| return nil |
| } |
| +// goneLabelledBox reports whether a relabel pass must read a one-box fleet |
| +// whole: exactly one of boxes is active, and some box that is not active |
| +// (detached) was named on a record (LabelledAt != 0), so records may still |
| +// name it (#1008 T9 finding 2). Lost and draining boxes stay active, so a |
| +// fleet that still has two active boxes is read whole anyway. |
| +func goneLabelledBox(boxes []registry.FleetBox) bool { |
| + active, gone := 0, false |
| + for _, b := range boxes { |
| + if b.Status == "active" { |
| + active++ |
| + } else if b.LabelledAt != 0 { |
| + gone = true |
| + } |
| + } |
| + return active == 1 && gone |
| +} |
| + |
| +// relabelView is the view a relabel pass acts on, as of now: |
| +// loadFleetViewRequiredAt, read whole also when goneLabelledBox holds. |
| +func (s *Server) relabelView(ctx context.Context, fleet string, now time.Time) (fleetView, error) { |
| + reg, err := s.openPassRegistry() |
| + if err != nil { |
| + return fleetView{Load: map[string]int{}}, err |
| + } |
| + boxes, err := reg.ListFleetBoxes(fleet) |
| + if err != nil { |
| + return fleetView{Load: map[string]int{}}, err |
| + } |
| + return s.loadFleetViewRequiredAt(ctx, fleet, now, goneLabelledBox(boxes)) |
| +} |
| + |
| +// fleetDetachRelabelTimeout bounds the relabel a detach door runs. |
| +const fleetDetachRelabelTimeout = 20 * time.Second |
| + |
| +// relabelAfterDetach runs fleet's relabel at once after a detach door |
| +// detached a box, under the fleet lock the door holds, so the detached |
| +// box's records move to a survivor now rather than at the next worker |
| +// pass. Best effort: an error is logged and the worker repeats it within |
| +// fleetRelabelInterval. Off on a host-claim console, as the worker is. |
| +func (s *Server) relabelAfterDetach(ctx context.Context, fleet string) { |
| + if s.cfg.HostClaim || s.cfg.Releases == nil || s.cfg.Registry == "" { |
| + return |
| + } |
| + ctx, cancel := context.WithTimeout(ctx, fleetDetachRelabelTimeout) |
| + defer cancel() |
| + now := time.Now() |
| + v, err := s.relabelView(ctx, fleet, now) |
| + if err != nil { |
| + log.Printf("console: fleet detach %s: relabel: view: %v; the relabel worker moves its records", fleet, err) |
| + return |
| + } |
| + moved, _ := s.relabelFleet(ctx, fleet, v, now) |
| + if moved > 0 { |
| + log.Printf("console: fleet detach %s: moved %d records off the detached box", fleet, moved) |
| + } |
| +} |
| + |
| // relabel is one planned label write: rec to box to, and why. |
| type relabel struct { |
| rec provision.Record |
| @@ -153,7 +214,12 @@ func (s *Server) relabelFleet(ctx context.Context, fleet string, v fleetView, no |
| fleet, box, releaseOrUnknown(rel), release.FleetBoxLabelFloor) |
| return 0, nil |
| } |
| - if !v.Active { |
| + // Moving off a gone box needs the whole view and nothing more: on two |
| + // or more active boxes Complete is Active, and a one-box view is whole |
| + // only when relabelView or replica placement asked for it. |
| + // chooseMoveDestination still refuses a stale, draining or below-floor |
| + // survivor. |
| + if !v.Complete { |
| return 0, nil |
| } |
| // No first labelling here (D2): only records that already carry a |
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go| index 37afebe35..09fb2343f 100644 |
| --- a/internal/console/fleetrelabel_test.go |
| +++ b/internal/console/fleetrelabel_test.go |
| @@ -1308,3 +1308,276 @@ func TestLostBoxAndDrainLeaveAUnitInPlace(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// #1008 T9 finding 2: a two-box fleet loses a box. After detach-box |
| +// --terminated the records labelled to it stayed tied to it and answered |
| +// 503: the worker skipped fleets with fewer than two active boxes. The |
| +// worker now reads a one-box fleet whole when a detached box was ever |
| +// labelled, and moves those records to the survivor, restore-required |
| +// (R2). A record already on the survivor is not written. |
| +func TestDetachedBoxRecordsMoveToTheSoleSurvivor(t *testing.T) { |
| + ctx := context.Background() |
| + fx, _, reg := fleetBoxWorld(t, "code-rl-sole", "pi-1", "pi-2") |
| + for _, h := range []string{"a.example.com", "b.example.com", "c.example.com"} { |
| + putFleetRecord(t, fx, "shop", h, nil) |
| + } |
| + labelOn(t, fx, reg, "a.example.com", "pi-1") |
| + labelOn(t, fx, reg, "b.example.com", "pi-2") |
| + labelOn(t, fx, reg, "c.example.com", "pi-2") |
| + if err := reg.SetFleetBoxStatus("pi", "pi-2", "detached"); err != nil { // the machine is gone |
| + t.Fatal(err) |
| + } |
| + now := time.Now() |
| + // The old gate: one active box is never Active. |
| + if v, err := fx.srv.loadFleetViewAt(ctx, "pi", now); err != nil || v.Active || v.Complete { |
| + t.Fatalf("plain view %+v, %v; want neither Active nor Complete", v, err) |
| + } |
| + cs := newCountStore(fx.rel) |
| + fx.srv.cfg.Releases = cs |
| + if err := fx.srv.fleetRelabelPass(ctx, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, h := range []string{"b.example.com", "c.example.com"} { |
| + wantMovedTo(t, shopRec(t, fx, h), "pi-1") |
| + } |
| + if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-1" || r.FleetBoxMoved { |
| + t.Fatalf("a was already on the survivor and was rewritten: %+v", r) |
| + } |
| + if n := cs.recordPuts(); n != 2 { |
| + t.Fatalf("the pass wrote %d records; want 2", n) |
| + } |
| + // A second pass finds nothing to move. |
| + cs.reset() |
| + if err := fx.srv.fleetRelabelPass(ctx, now.Add(time.Minute)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := cs.recordPuts(); n != 0 { |
| + t.Fatalf("a second pass wrote %d records", n) |
| + } |
| +} |
| + |
| +// wantMovedTo fails unless rec is labelled box, assigned now, and marked |
| +// moved, so it never starts empty there (R2). |
| +func wantMovedTo(t *testing.T, rec *provision.Record, box string) { |
| + t.Helper() |
| + if rec.FleetBox != box { |
| + t.Fatalf("record %s labelled %q; want %q", rec.Host, rec.FleetBox, box) |
| + } |
| + at, err := time.Parse(time.RFC3339Nano, rec.FleetBoxAt) |
| + if err != nil || time.Since(at) > time.Minute { |
| + t.Fatalf("record %s assigned at %q (%v); want now", rec.Host, rec.FleetBoxAt, err) |
| + } |
| + if !rec.FleetBoxMoved { |
| + t.Fatalf("%s moved without FleetBoxMoved: it could start empty (R2)", rec.Host) |
| + } |
| +} |
| + |
| +// soleSurvivorWorld is pi-1 holding a and pi-2 holding b and c, both boxes |
| +// marked labelled, each record labelled at its creation with mut applied |
| +// (a rootfs record's runtime is fixed when it is created). |
| +func soleSurvivorWorld(t *testing.T, code string, mut func(*provision.Record)) (*consoleFixture, string, *registry.Registry) { |
| + t.Helper() |
| + fx, token, reg := fleetBoxWorld(t, code, "pi-1", "pi-2") |
| + for _, b := range []string{"pi-1", "pi-2"} { |
| + if err := reg.MarkFleetBoxLabelled("pi", b, time.Now().UnixNano()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + for h, box := range map[string]string{"a.example.com": "pi-1", "b.example.com": "pi-2", "c.example.com": "pi-2"} { |
| + putFleetRecord(t, fx, "shop", h, func(r *provision.Record) { |
| + r.FleetBox, r.FleetBoxAt = box, time.Now().UTC().Format(time.RFC3339Nano) |
| + if mut != nil { |
| + mut(r) |
| + } |
| + }) |
| + } |
| + return fx, token, reg |
| +} |
| + |
| +// The detach doors move the detached box's records at once, under the |
| +// lock they hold, with no worker pass, and answer as before. |
| +func TestDetachDoorMovesTheDetachedBoxesRecords(t *testing.T) { |
| + for _, door := range []string{"api", "page"} { |
| + t.Run(door, func(t *testing.T) { |
| + fx, token, reg := soleSurvivorWorld(t, "code-rl-door-sole-"+door, nil) |
| + if door == "api" { |
| + if code, raw := detachAPI(t, fx, token, "pi-2", true); code != http.StatusOK || strings.TrimSpace(raw) != "{}" { |
| + t.Fatalf("API detach = %d %s; want 200 {}", code, raw) |
| + } |
| + } else if body := detachPage(t, fx, "pi-2", true); !strings.Contains(body, "Detached pi/pi-2.") { |
| + t.Fatalf("page detach shows no confirmation:\n%s", body) |
| + } |
| + if b := boxRow(t, reg, "pi-2"); b.Status != "detached" { |
| + t.Fatalf("box %+v; want detached", b) |
| + } |
| + for _, h := range []string{"b.example.com", "c.example.com"} { |
| + wantMovedTo(t, shopRec(t, fx, h), "pi-1") |
| + } |
| + if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-1" || r.FleetBoxMoved { |
| + t.Fatalf("a was rewritten: %+v", r) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The sole survivor is a destination only as chooseMoveDestination allows: |
| +// a stale, draining, not-ready (for a rootfs record) or below-floor |
| +// survivor takes nothing. |
| +func TestSoleSurvivorMustBeAValidDestination(t *testing.T) { |
| + cases := []struct { |
| + name string |
| + mut func(*provision.Record) |
| + setup func(t *testing.T, fx *consoleFixture, reg *registry.Registry, now time.Time) |
| + log string |
| + }{ |
| + {name: "stale", setup: func(t *testing.T, fx *consoleFixture, reg *registry.Registry, now time.Time) { |
| + piBeat(t, fx, "pi-1", true, now.Add(-21*time.Minute), release.FleetRecordLabelFloor) |
| + }}, |
| + {name: "draining", setup: func(t *testing.T, fx *consoleFixture, reg *registry.Registry, now time.Time) { |
| + if _, err := reg.SetFleetBoxDraining("pi", "pi-1", now.UnixNano()); err != nil { |
| + t.Fatal(err) |
| + } |
| + }}, |
| + {name: "rootfs not ready", mut: func(r *provision.Record) { |
| + alwaysOn := false |
| + r.Runtime, r.Hibernate = provision.RuntimeRootfsV1, &alwaysOn |
| + }, |
| + setup: func(t *testing.T, fx *consoleFixture, reg *registry.Registry, now time.Time) { |
| + piBeat(t, fx, "pi-1", false, now, release.FleetRecordLabelFloor) |
| + }}, |
| + {name: "below the label floor", log: "relabelling is paused", |
| + setup: func(t *testing.T, fx *consoleFixture, reg *registry.Registry, now time.Time) { |
| + piBeat(t, fx, "pi-1", true, now, "v0.32.0") |
| + }}, |
| + } |
| + for i, tc := range cases { |
| + t.Run(tc.name, func(t *testing.T) { |
| + ctx := context.Background() |
| + now := time.Now() |
| + fx, _, reg := soleSurvivorWorld(t, "code-rl-sole-bad-"+string(rune('a'+i)), tc.mut) |
| + if err := reg.SetFleetBoxStatus("pi", "pi-2", "detached"); err != nil { |
| + t.Fatal(err) |
| + } |
| + tc.setup(t, fx, reg, now) |
| + cs := newCountStore(fx.rel) |
| + fx.srv.cfg.Releases = cs |
| + var logs bytes.Buffer |
| + restore := captureLogTo(&logs) |
| + err := fx.srv.fleetRelabelPass(ctx, now) |
| + restore() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if r := shopRec(t, fx, "b.example.com"); r.FleetBox != "pi-2" || r.FleetBoxMoved { |
| + t.Fatalf("b moved to an invalid survivor: %+v", r) |
| + } |
| + if n := cs.recordPuts(); n != 0 { |
| + t.Fatalf("the pass wrote %d records; want none", n) |
| + } |
| + if tc.log != "" && !strings.Contains(logs.String(), tc.log) { |
| + t.Fatalf("no %q line in the log:\n%s", tc.log, logs.String()) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// R3 across a detach: an always-on stateless record on a detached box moves |
| +// to the sole survivor only when it runs the stateless runtime floor. |
| +func TestDetachedStatelessRecordNeedsTheRuntimeFloor(t *testing.T) { |
| + for _, tc := range []struct { |
| + name, survivor string |
| + moves bool |
| + }{ |
| + {"survivor at the label floor", release.FleetBoxLabelFloor, false}, |
| + {"survivor at the runtime floor", release.StatelessRuntimeFloor, true}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + now := time.Now() |
| + code := "code-r3-detached-stay" |
| + if tc.moves { |
| + code = "code-r3-detached-move" |
| + } |
| + fx, reg := statelessShopWorldOn(t, code, "edge", now, |
| + map[string]string{"pi-1": release.StatelessRuntimeFloor, "pi-2": tc.survivor}) |
| + if err := reg.MarkFleetBoxLabelled("pi", "pi-1", now.UnixNano()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.SetFleetBoxStatus("pi", "pi-1", "detached"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.srv.fleetRelabelPass(context.Background(), now); err != nil { |
| + t.Fatal(err) |
| + } |
| + r := shopRec(t, fx, "a.example.com") |
| + if tc.moves { |
| + wantMovedTo(t, r, "pi-2") |
| + } else if r.FleetBox != "pi-1" || r.FleetBoxMoved { |
| + t.Fatalf("a stateless record moved below the runtime floor: %+v", r) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Request budget: a one-box fleet is read whole only when a detached box |
| +// was labelled. Without one, a pass lists no records and writes none. |
| +func TestOneBoxFleetReadsNoInventoryWithoutAGoneLabelledBox(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + second bool |
| + }{ |
| + {"never had a second box", false}, |
| + {"detached box never labelled", true}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + code := "code-rl-onebox-lone" |
| + if tc.second { |
| + code = "code-rl-onebox-unlabelled" |
| + } |
| + fx, _, reg := fleetBoxWorld(t, code, "pi-1") |
| + putFleetRecord(t, fx, "shop", "a.example.com", nil) |
| + labelOn(t, fx, reg, "a.example.com", "pi-1") |
| + if tc.second { |
| + registerFleetBox(t, reg, "pi", "pi-2") |
| + if err := reg.SetFleetBoxStatus("pi", "pi-2", "detached"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if b := boxRow(t, reg, "pi-2"); b.LabelledAt != 0 { |
| + t.Fatalf("pi-2 is labelled: %+v", b) |
| + } |
| + } |
| + cs := newCountStore(fx.rel) |
| + fx.srv.cfg.Releases = cs |
| + if err := fx.srv.fleetRelabelPass(context.Background(), time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := cs.listsOf(provision.RecordsPrefix(fx.sqid, "shop"), provision.SidecarsPrefix(fx.sqid, "shop")); n != 0 { |
| + t.Fatalf("the pass listed shop's records %d times; want none", n) |
| + } |
| + if n := cs.recordPuts(); n != 0 { |
| + t.Fatalf("the pass wrote %d records; want none", n) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestGoneLabelledBox(t *testing.T) { |
| + box := func(label, status string, labelledAt int64) registry.FleetBox { |
| + return registry.FleetBox{Fleet: "pi", Label: label, Status: status, LabelledAt: labelledAt} |
| + } |
| + for _, tc := range []struct { |
| + name string |
| + boxes []registry.FleetBox |
| + want bool |
| + }{ |
| + {"one active, one detached labelled", []registry.FleetBox{box("pi-1", "active", 1), box("pi-2", "detached", 1)}, true}, |
| + {"one active, one detached unlabelled", []registry.FleetBox{box("pi-1", "active", 1), box("pi-2", "detached", 0)}, false}, |
| + {"two active, one detached labelled", []registry.FleetBox{box("pi-1", "active", 0), box("pi-2", "active", 0), box("pi-3", "detached", 1)}, false}, |
| + {"none active", []registry.FleetBox{box("pi-1", "detached", 1), box("pi-2", "detached", 1)}, false}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + if got := goneLabelledBox(tc.boxes); got != tc.want { |
| + t.Fatalf("goneLabelledBox = %v; want %v", got, tc.want) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/fleets.go b/internal/console/fleets.go| index e337429ff..bad2b9c16 100644 |
| --- a/internal/console/fleets.go |
| +++ b/internal/console/fleets.go |
| @@ -633,6 +633,7 @@ func (s *Server) handleAPIFleetDetachBox(w http.ResponseWriter, r *http.Request) |
| return |
| } |
| s.audit(acct, fleet.Name, addr, "fleet-detach-box", "detached "+fleet.Name+"/"+label+" (cli)") |
| + s.relabelAfterDetach(r.Context(), fleet.Name) |
| reply := map[string]any{} |
| if len(warnings) > 0 { |
| reply["warnings"] = warnings |
| @@ -1722,6 +1723,7 @@ func (s *Server) handleFleetDetachBoxPage(w http.ResponseWriter, r *http.Request |
| return |
| } |
| s.audit(acct, fleet.Name, addr, "fleet-detach-box", "detached "+fleet.Name+"/"+label+" (console)") |
| + s.relabelAfterDetach(r.Context(), fleet.Name) |
| confirmation := "Detached " + fleet.Name + "/" + label + "." |
| back("ok", strings.Join(append([]string{confirmation}, warnings...), "\n")) |
| } |
diff --git a/internal/console/replicaplacement_fix_test.go b/internal/console/replicaplacement_fix_test.go| index d208d20b2..5a12ab395 100644 |
| --- a/internal/console/replicaplacement_fix_test.go |
| +++ b/internal/console/replicaplacement_fix_test.go |
| @@ -85,18 +85,22 @@ func TestReplicaLegacyRelabelSurvivesEarlyReturn(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + // rv is the view replica placement returns early on. The relabel |
| + // acts on v: an incomplete view writes nothing (its gate is |
| + // Complete), so "incomplete" withholds it from placement alone. |
| + rv := v |
| switch reason { |
| case "busy": |
| unlock := fx.srv.lockApp(fx.sqid, "blog") |
| defer unlock() |
| case "incomplete": |
| - v.Complete = false |
| + rv.Complete = false |
| case "floor": |
| fx.srv.consoleBuild = release.StatelessRuntimeFloor |
| } |
| unlock := fx.srv.lockFleet("pi") |
| defer unlock() |
| - if err := fx.srv.reconcileReplicaFleet(context.Background(), "pi", v, time.Now()); err != nil { |
| + if err := fx.srv.reconcileReplicaFleet(context.Background(), "pi", rv, time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| if _, err := fx.srv.relabelFleet(context.Background(), "pi", v, time.Now()); err != nil { |