console: a trashed app's unlabelled record no longer holds a drain
#1008 T9 drill, finding 1: an app in the Trash blocked every drain of its fleet until it purged, because its unlabelled records stranded the drain like a live app's. drainBox now excuses an unlabelled record whose app the boxes have retired: its trash marker positively read and its production flag positively clear (absent, or not production), the same two reads as the box's removable test (reconcile.go productionClear). An unreadable marker or flag is treated as served and still strands the drain, as do labelled records of a trashed app that cannot move. The excused record is not written and stays unlabelled; trash state is read once per app per drain, only for apps with an unlabelled record. Restore keeps working: the marker goes and the record is still on the fleet, unlabelled, for every remaining box to mint again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/console/fleetrelabel.go+52 −4internal/console/fleetrelabel_test.go+150 −0
Intent
<task-notification> <task-id>a6be3b106b1563a0b</task-id> <tool-use-id>toolu_01J4nyXTpXQ5H1xPQ6hNZD7H</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/24f2e8d0-8e47-4773-a96b-f7e9260c860f/tasks/a6be3b106b1563a0b.output</output-file> <status>completed</status> <summary>Agent "Investigate P3 fleet agent cold reads" 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>**Cause:** after a restart, a fleet box doesn't reconcile until `instancesLoop`'s first pass, one minute after start (`internal/host/agent.go:4589`). The fast loop treats the serial bump from the label as old history (`agent.go:3380-3389`). Boxes with the change index get a full pass at boot through `recordViewBackstop`, but a fleet box has no record view, so that branch at `changeindex.go:158` never runs. **The "context deadline exceeded" lines are a side issue.** They come from the startup HA ingress pass (`haingress.go:141/166/172`). It has a flat 5 s budget, which can't cover a walk of every record over the door, and it holds `reconcileMu`. Its four attempts match the box and hub logs to the second: 07:05:51, 07:06:08, 07:06:23 and 07:11:01, with the hub's "context canceled" lines at the same moments. **Evidence:** b's row converged at 07:11:29.45Z, 60 s plus pass time after the tunnel came up at 07:10:24.8Z. The first restart shows the same shape: route removed 65 s after connecting. box-1 never restarted (NRestarts 0, up since 11-14 22:40Z), so the plan's "box-1's own restart" was wrong; both restarts were box-2's. The box-2 lines come from the drill agent's transcript, because the box is gone and no shipped logs exist under `fleets/r10r/`. **Confidence:** high. **Fix size:** small, one package (`internal/host`), about 10 lines plus a test. When no record view is armed, set `backstopFullDue` right after `armChangeIndex`, so the fast loop's first tick runs a full pass. Expected gap: about 10-15 s instead of about 63 s. The deterministic test drives `fastTick` and checks for exactly one boot pass. It needs a census card. An optional second change, which needs the region HA owner's view first, would skip the startup HA ingress pass on fleet boxes. Access was SSM `journalctl` reads on box-1 and sophie plus S3 LIST only. My scratch directory is deleted. Findings: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/fleet-drain-followups/.superpowers/sdd/2026-11-15-fleet-drain-followups/p3-findings.md</result> <usage><subagent_tokens>132059</subagent_tokens><tool_uses>39</tool_uses><duration_ms>316986</duration_ms></usage> </task-notification>
Attributed to this commit: 9.65 g CO₂e (1,048,807 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 626ab67b3..53edd6ede 100644 |
| --- a/internal/console/fleetrelabel.go |
| +++ b/internal/console/fleetrelabel.go |
| @@ -49,7 +49,9 @@ import ( |
| // |
| // The drain (`carlos fleets drain`, drainBox) moves every record the box |
| // runs or refuses up front, naming the apps, and marks the box draining in |
| -// the registry (draining_since). A draining box stays active, so it keeps |
| +// 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 |
| @@ -374,8 +376,12 @@ func (e *fleetPausedError) Error() string { return msgLabelsPaused(e.fleet, e.bo |
| // fleet's lock, it moves every record the box runs to another box, or |
| // refuses, answering the apps whose records cannot move, sorted, with |
| // nothing written. A record cannot move when it is unlabelled (every box |
| -// runs it), when the platform cannot move it (movable), or when no other |
| -// box can take it. Otherwise the box is marked draining (it keeps its |
| +// 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 |
| // 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 |
| @@ -446,6 +452,10 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str |
| return nil, errFleetDrainIncomplete |
| } |
| strand := map[string]bool{} |
| + // retired memoises trashRetired per app: one marker read and at most |
| + // one flag read per app per drain, only for apps with an unlabelled |
| + // record here. |
| + retired := map[AppRef]bool{} |
| var plan []relabel |
| for _, rec := range recs { |
| if rec.ReplicaAssignment != nil { |
| @@ -455,7 +465,23 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str |
| continue |
| } |
| if rec.FleetBox == "" { |
| - strand[rec.App] = true |
| + ref := AppRef{Sqid: rec.Account, App: rec.App} |
| + gone, seen := retired[ref] |
| + if !seen { |
| + var err error |
| + gone, err = s.trashRetired(ctx, rec.Account, rec.App) |
| + switch { |
| + case 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 |
| } |
| ok, stateless, err := s.movableVerified(ctx, rec) |
| @@ -509,6 +535,28 @@ func (s *Server) drainBox(ctx context.Context, fleet, label string) (stuck []str |
| return nil, nil |
| } |
| +// trashRetired reports whether the boxes have retired app's routes because |
| +// it is in the Trash: its marker positively read (release.ReadAppTombstone) |
| +// and its production flag positively clear (release.GetProduction with |
| +// s.cfg.ReleasePub: absent, or present and not production). This is |
| +// reconcile's removable test (internal/provision/reconcile.go:1766-1775, |
| +// productionClear) asked of the same bucket. An unreadable marker or flag |
| +// is an error, which the caller treats as "still served". |
| +func (s *Server) trashRetired(ctx context.Context, sqid, app string) (bool, error) { |
| + tomb, err := release.ReadAppTombstone(ctx, s.cfg.Releases, sqid, app) |
| + if err != nil { |
| + return false, err |
| + } |
| + if tomb == nil { |
| + return false, nil |
| + } |
| + flag, err := release.GetProduction(ctx, s.cfg.Releases, s.cfg.ReleasePub, sqid, app) |
| + if err != nil { |
| + return false, err |
| + } |
| + return flag == nil || !flag.Production, nil |
| +} |
| + |
| // The values of `carlos fleets ls`'s labels_paused: absent when the fleet |
| // is not paused, fleetLabelsPaused when a box of a fleet with labels |
| // reports a release below the floor, fleetLabelsUnknown when some box's |
diff --git a/internal/console/fleetrelabel_test.go b/internal/console/fleetrelabel_test.go| index 84267bd9d..e00c4cafe 100644 |
| --- a/internal/console/fleetrelabel_test.go |
| +++ b/internal/console/fleetrelabel_test.go |
| @@ -506,6 +506,156 @@ func TestDrainRefusesAnUnmanagedRecord(t *testing.T) { |
| } |
| } |
| +// blogRecBytes is the raw object of blog's record of h. |
| +func blogRecBytes(t *testing.T, fx *consoleFixture, h string) []byte { |
| + t.Helper() |
| + b, _, err := fx.rel.Get(context.Background(), provision.RecordKey(fx.sqid, "blog", h)) |
| + if err != nil { |
| + t.Fatalf("read blog's record of %s: %v", h, err) |
| + } |
| + return b |
| +} |
| + |
| +// #1008 T9 finding 1: an app in the Trash blocked every drain of its |
| +// fleet until it purged. An unlabelled record of an app whose marker is |
| +// read and whose production flag is clear is not served by any box, is |
| +// still carried by every other box, and comes back on restore, so it no |
| +// longer holds the drain. Its record is not written. |
| +func TestDrainSkipsATrashedAppsUnlabelledRecord(t *testing.T) { |
| + ctx := context.Background() |
| + fx, _, reg := fleetBoxWorld(t, "code-rl-drain-trash", "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", nil) // unlabelled: every box carries it |
| + before := blogRecBytes(t, fx, "x.example.com") // raw object bytes, for "not written" |
| + |
| + // Baseline: live, it strands the drain (as TestDrainRefusesAnUnmanagedRecord/unlabelled). |
| + if stuck, err := fx.srv.drainBox(ctx, "pi", "pi-1"); err != nil || !slices.Equal(stuck, []string{"blog"}) { |
| + t.Fatalf("live: drainBox = %v, %v; want blog stranded", stuck, err) |
| + } |
| + if err := release.TrashApp(ctx, fx.rel, fx.sqid, "blog", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + stuck, err := fx.srv.drainBox(ctx, "pi", "pi-1") |
| + if err != nil || len(stuck) != 0 { |
| + t.Fatalf("trashed: drainBox = %v, %v; want nothing stranded", stuck, err) |
| + } |
| + if r := shopRec(t, fx, "a.example.com"); r.FleetBox != "pi-2" || !r.FleetBoxMoved { |
| + t.Fatalf("shop's 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") |
| + } |
| + if got := blogRecBytes(t, fx, "x.example.com"); !bytes.Equal(got, before) { |
| + t.Fatalf("the trashed app's record was written:\n%s\nwant\n%s", got, before) |
| + } |
| + // Restore keeps working: the marker goes and the record is there, |
| + // unlabelled, on the fleet, for the remaining boxes to mint. |
| + if err := release.RestoreApp(ctx, fx.rel, fx.sqid, "blog"); err != nil { |
| + t.Fatal(err) |
| + } |
| + 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 restore: %+v, %v; want the record kept on fleet/pi", r, err) |
| + } |
| + wantNoLabel(t, r) |
| +} |
| + |
| +// 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 |
| +// read, or whose record is labelled and cannot move, still strands the |
| +// drain with nothing written. |
| +func TestDrainStillRefusesATrashedAppTheBoxesServe(t *testing.T) { |
| + // overwrite replaces the object at key with body. |
| + overwrite := func(t *testing.T, fx *consoleFixture, key string, body []byte) { |
| + t.Helper() |
| + _, etag, err := fx.rel.Get(context.Background(), key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.rel.Put(context.Background(), key, body, etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + for _, tc := range []struct { |
| + name string |
| + recMut func(*provision.Record) |
| + // before runs before blog is trashed (the production flag cannot be |
| + // set on a trashed app), after once it is. |
| + before, after func(t *testing.T, fx *consoleFixture) |
| + }{ |
| + {"production", nil, func(t *testing.T, fx *consoleFixture) { |
| + if err := release.SetProduction(context.Background(), fx.rel, fx.priv, fx.sqid, "blog", true, "paul@keymail.dev"); err != nil { |
| + t.Fatal(err) |
| + } |
| + }, nil}, |
| + {"unreadable marker", nil, nil, func(t *testing.T, fx *consoleFixture) { |
| + overwrite(t, fx, release.AppTombstoneKey(fx.sqid, "blog"), []byte(`{"schema":2}`)) |
| + }}, |
| + {"unreadable flag", nil, nil, func(t *testing.T, fx *consoleFixture) { |
| + if _, err := fx.rel.Put(context.Background(), release.ProductionKey(fx.sqid, "blog"), []byte("not a flag"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + }}, |
| + {"labelled and unmovable", func(r *provision.Record) { r.FleetBox, r.Addr = "pi-1", "127.0.0.1:9000" }, nil, nil}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + ctx := context.Background() |
| + fx, _, reg := fleetBoxWorld(t, "code-rl-trash-served-"+strings.ReplaceAll(tc.name, " ", "-"), "pi-1", "pi-2") |
| + if !fx.srv.cfg.ReleasePub.Equal(fx.pub) { |
| + t.Fatal("the fixture's console does not hold the release root's public key") |
| + } |
| + 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", tc.recMut) |
| + if tc.before != nil { |
| + tc.before(t, fx) |
| + } |
| + if err := release.TrashApp(ctx, fx.rel, fx.sqid, "blog", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if tc.after != nil { |
| + tc.after(t, fx) |
| + } |
| + 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") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The trash state is read only for an app with an unlabelled record on the |
| +// fleet, and once per app per drain however many such records it has. |
| +func TestDrainReadsTrashStateOnlyForUnlabelledApps(t *testing.T) { |
| + fx, _, _ := fleetBoxWorld(t, "code-rl-trash-reads", "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, "shop", "b.example.com", nil) |
| + putFleetRecord(t, fx, "shop", "c.example.com", nil) |
| + putFleetRecord(t, fx, "blog", "x.example.com", func(r *provision.Record) { r.FleetBox = "pi-1" }) |
| + cs := newCountStore(fx.rel) |
| + fx.srv.cfg.Releases = cs |
| + if _, err := fx.srv.drainBox(context.Background(), "pi", "pi-1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if n := cs.getsOf(release.AppTombstoneKey(fx.sqid, "blog")); n != 0 { |
| + t.Fatalf("blog, with no unlabelled record, had its trash marker read %d times", n) |
| + } |
| + if n := cs.getsOf(release.AppTombstoneKey(fx.sqid, "shop")); n != 1 { |
| + t.Fatalf("shop's trash marker was read %d times; want once for its two unlabelled records", n) |
| + } |
| +} |
| + |
| // drainedPi1 is a world where pi-1 held a.example.com and was drained: its |
| // record is on pi-2 and pi-1 is draining. |
| func drainedPi1(t *testing.T, code string) (*consoleFixture, string, *registry.Registry) { |