carlos / platform Public

console: excuse a trashed record only when another box can carry it

Review fix (P1) for the trashed-app drain exception: on a fleet's last
box, a restore racing the drain (it takes the app's locks, not the
fleet's) would leave the restored instance with no box once the drained
machine is detached. The excuse now also needs a surviving box,
chooseMoveDestination with the record's rootfs flag excluding the
drained box; without one the record strands the drain as before, and
the trash state is not read.

Witnesses: a one-box fleet still refuses the drain; a store seam
restores the app right after the drain reads the marker, and the drain
leaves the record unwritten and unlabelled with the survivor able to
carry it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 800aec35aef8cf744fe76ac7238e1a0c62fc3de7 parent 21f3384
2 files changed, +119 −10
  • internal/console/fleetrelabel.go +23 −10
  • internal/console/fleetrelabel_test.go +96 −0

Intent

Human

<task-notification> <task-id>ac6d0304ce4186349</task-id> <tool-use-id>toolu_019uMQqDmbeZyS427ouZuUjz</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 Commit: 21f33841 console: a trashed app's unlabelled record no longer holds a drain Tests: the 3 new tests (4 refusal subtests) failed as the brief predicted before the fix: the trashed app was still stranded and its marker was read 0 times. They pass now. The step 6 pattern run passed in 292 s, gofmt and vet are clean, and census-card reports nothing to approve. Test setup changes (the assertions are as the brief wrote them): - **"production" subtest:** the flag is set before the trash, because `SetProduction` refuses a trashed app. - **"unreadable marker" subtest:** it overwrites the existing marker using its ETag, because a create-only Put conflicts. Concerns: - **No release public key on the console:** the box treats a missing key as "flag clear". The console instead fails to verify a flag that exists and strands the drain. This is the safe direction, and an absent flag still lets the drain through. - **Strand list keys:** the strand list is keyed by app name only, as before; the new memo is keyed by account and app. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/fleet-drain-followups/.superpowers/sdd/2026-11-15-fleet-drain-followups/task-1-report.md</result> <usage><subagent_tokens>79705</subagent_tokens><tool_uses>15</tool_uses><duration_ms>848377</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bvnhiix4b</task-id> <tool-use-id>toolu_01XCY2cTSGkuv3DTH7yhCcqz</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/24f2e8d0-8e47-4773-a96b-f7e9260c860f/tasks/bvnhiix4b.output</output-file> <status>completed</status> <summary>Background command "W=$PWD/.superpowers/sdd/2026-11-15-fleet-drain-followups &amp;&amp; cat &gt; $W/review-1-prompt.md &lt;&lt;EOF You are reviewing one task of a Go change in the carlos platform, read-only. Task-scoped gate. Requirements: read $W/task-1-brief.md. Binding global constraints: lines 15-32 of docs/superpowers/plans/2026-11-15-fleet-drain-followups.md. Background on why: "Product findings" 1 in $W/t9-drill-report.md. Implementer's report (unverified claims): $W/task-1-report.md Diff (base 4c892040, ... [807 characters truncated] ... line and a concrete failure scenario. ⚠️ Cannot verify from diff: items, if any. EOF codex exec -m gpt-6-astra -c model_reasoning_effort=high -s read-only "Follow the instructions in $W/review-1-prompt.md" &lt;/dev/null &gt; $W/review-1-astra.md 2&gt;&amp;1; tail -60 $W/review-1-astra.md" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>ac6d0304ce4186349</task-id> <tool-use-id>toolu_015y25shxfAqZwqQ11aUMMA5</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" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>I'm waiting for the background test run to finish.</result> <usage><subagent_tokens>95721</subagent_tokens><tool_uses>11</tool_uses><duration_ms>121311</duration_ms></usage> </task-notification>

Attributed to this commit: 3.21 g CO₂e (341,769 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 53edd6ede..198a5925b 100644
--- a/internal/console/fleetrelabel.go
+++ b/internal/console/fleetrelabel.go
@@ -51,11 +51,12 @@ import (
// runs or refuses up front, naming the apps, and marks the box draining in
// the registry (draining_since). An unlabelled record of an app in the
// Trash whose routes the boxes have retired (trashRetired) does not hold
-// the drain and is left as it is. A draining box stays active, so it keeps
-// its fleet access and can see its 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).
+// the drain, when another box could carry it, and is left as it is. A
+// draining box stays active, so it keeps its fleet access and can see its
+// 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).
// fleetRelabelInterval is the worker's period.
const fleetRelabelInterval = 5 * time.Minute
@@ -377,11 +378,14 @@ func (e *fleetPausedError) Error() string { return msgLabelsPaused(e.fleet, e.bo
// refuses, answering the apps whose records cannot move, sorted, with
// 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): 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. A record also cannot
-// move when the platform cannot move it (movable), or when no other box
-// can take it. Otherwise the box is marked draining (it keeps its
+// routes (trashRetired) and another box of the fleet could carry it
+// (chooseMoveDestination, excluding this one): 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
+// racing the drain would leave the instance with no box. A record also
+// cannot move when the platform cannot move it (movable), or when no other
+// box can take it. Otherwise the box is marked draining (it keeps its
// fleet access and gets no new assignment) and each record is relabelled
// to chooseDestination's choice. A record that changed since it was read,
// or whose import has not committed, is left for the worker, which moves
@@ -465,6 +469,15 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str
continue
}
if rec.FleetBox == "" {
+ // The excuse needs a box that stays: some other active box of
+ // 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) == "" {
+ strand[rec.App] = true
+ continue
+ }
ref := AppRef{Sqid: rec.Account, App: rec.App}
gone, seen := retired[ref]
if !seen {
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go
index e00c4cafe..787ee2592 100644
--- a/internal/console/fleetrelabel_test.go
+++ b/internal/console/fleetrelabel_test.go
@@ -561,6 +561,102 @@ func TestDrainSkipsATrashedAppsUnlabelledRecord(t *testing.T) {
wantNoLabel(t, r)
}
+// Fix round 1 (review P1): the excuse needs a box that stays. On a
+// one-box fleet a trashed app's unlabelled record still strands the drain,
+// since a restore racing the drain would leave the instance on no box. The
+// trash state is not even read there.
+func TestDrainOfTheLastBoxStillRefusesATrashedApp(t *testing.T) {
+ ctx := context.Background()
+ fx, _, reg := fleetBoxWorld(t, "code-rl-trash-last", "pi-1")
+ placeBlog(t, fx)
+ putFleetRecord(t, fx, "blog", "x.example.com", nil)
+ if err := release.TrashApp(ctx, fx.rel, fx.sqid, "blog", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(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 n := cs.getsOf(release.AppTombstoneKey(fx.sqid, "blog")); n != 0 {
+ t.Fatalf("the trash marker was read %d times with no box to stay", n)
+ }
+ if b := boxRow(t, reg, "pi-1"); b.DrainingSince != 0 {
+ t.Fatal("a refused drain marked the box draining")
+ }
+}
+
+// restoreOnGet restores app blog (deletes its trash marker) once, just
+// after the first read of key: a restore landing between the drain's trash
+// read and the drain's end.
+type restoreOnGet struct {
+ release.Store
+ key string
+ fx *consoleFixture
+ done bool
+}
+
+func (r *restoreOnGet) Get(ctx context.Context, key string) ([]byte, string, error) {
+ body, etag, err := r.Store.Get(ctx, key)
+ if key == r.key && !r.done {
+ r.done = true
+ if rerr := release.RestoreApp(ctx, r.fx.rel, r.fx.sqid, "blog"); rerr != nil {
+ return nil, "", rerr
+ }
+ }
+ return body, etag, err
+}
+
+// Fix round 1 (review P1), the race: blog is restored after the drain read
+// its trash marker and before the drain ends. The drain still succeeds,
+// excusing the record, and that is safe: the record was not written, so it
+// is still unlabelled on the fleet, and the surviving box pi-2 is one a
+// record can be on, so the restored instance is carried by pi-2.
+func TestDrainRacingARestoreLeavesTheInstanceOnTheSurvivor(t *testing.T) {
+ ctx := context.Background()
+ fx, _, reg := fleetBoxWorld(t, "code-rl-trash-race", "pi-1", "pi-2")
+ placeBlog(t, fx)
+ putFleetRecord(t, fx, "blog", "x.example.com", nil)
+ before := blogRecBytes(t, fx, "x.example.com")
+ if err := release.TrashApp(ctx, fx.rel, fx.sqid, "blog", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ race := &restoreOnGet{Store: fx.rel, key: release.AppTombstoneKey(fx.sqid, "blog"), fx: fx}
+ fx.srv.cfg.Releases = race
+ stuck, err := fx.srv.drainBox(ctx, "pi", "pi-1")
+ if err != nil || len(stuck) != 0 {
+ t.Fatalf("drainBox = %v, %v; want nothing stranded", stuck, err)
+ }
+ if !race.done {
+ t.Fatal("the drain never read the trash marker, so the witness proves nothing")
+ }
+ if tomb, err := release.ReadAppTombstone(ctx, fx.rel, fx.sqid, "blog"); err != nil || tomb != nil {
+ t.Fatalf("blog is still in the trash (%v, %v); the restore did not land", tomb, err)
+ }
+ if b := boxRow(t, reg, "pi-1"); b.DrainingSince == 0 {
+ t.Fatal("the drain did not mark pi-1 draining")
+ }
+ if got := blogRecBytes(t, fx, "x.example.com"); !bytes.Equal(got, before) {
+ t.Fatalf("the excused record was written:\n%s\nwant\n%s", got, before)
+ }
+ r, err := provision.GetRecord(ctx, fx.rel, fx.sqid, "blog", "x.example.com")
+ if err != nil || r.Retired || r.Region != "fleet/pi" {
+ t.Fatalf("after the race: %+v, %v; want the record kept on fleet/pi", r, err)
+ }
+ wantNoLabel(t, r) // unlabelled: every box of the fleet carries it
+ v, err := fx.srv.loadFleetView(ctx, "pi")
+ 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)
+ }
+}
+
// The excuse is the box's own removable test (marker and production flag
// both positively read, the flag clear) and covers unlabelled records
// only. A trashed app the boxes still serve, or whose state cannot be