Managed fleets design: 1b addendum (records name their box, one runner, relabel on loss, #470), 1c merged
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+77
−8
docs/superpowers/specs/2026-10-28-managed-fleets-design.md+77 −8
CI passed — run details
diff --git a/docs/superpowers/specs/2026-10-28-managed-fleets-design.md b/docs/superpowers/specs/2026-10-28-managed-fleets-design.md| index ccd16fa67..25b9a1e48 100644 |
| --- a/docs/superpowers/specs/2026-10-28-managed-fleets-design.md |
| +++ b/docs/superpowers/specs/2026-10-28-managed-fleets-design.md |
| @@ -131,14 +131,83 @@ is to establish what a multi-box fleet does today. If it already |
| spreads instances with one writer each, 1b is a test. If it doesn't, 1b |
| is a small placement rule, owned by the console and recorded on the |
| instance (my guess: least-loaded ready box at create, fixed after). |
| -This is the largest unknown in the design. |
| - |
| -**1c. A reboot doesn't cost 15 minutes (#451).** After a rootfs box |
| -reboots, the agent can't recognise the lease its own previous boot |
| -held, because the lease owner names the pid but not the boot id, so the |
| -instance waits out the lease. Fix #451: a lease is recognisable as this |
| -box's earlier boot and released at start. Verify by rebooting a dev |
| -fleet box under load. |
| +This is the largest unknown in the design. Settled by the 1b addendum |
| +below. |
| + |
| +**1b addendum (2026-10-30, proposed; awaiting Paul).** What main does |
| +today (read at d3908d93): |
| + |
| +- Every box of a fleet mints every record of the fleet (`inScope`, |
| + `internal/provision/reconcile.go:487-499`; a record has no box field), |
| + stages every record's build (`internal/release/adopt.go:1233-1263`) |
| + and tries to start every always-on rootfs resident |
| + (`internal/activator/rootfs_service.go:723-743`). The per-host |
| + Litestream lease picks the one that runs it; the losers answer 503 |
| + until the lease expires (15 min). |
| +- The winner writes `fleets/<f>/bindings/<host>.json` |
| + (`internal/host/fleetbind.go`), the hub copies it into the route's |
| + `FleetBox` every 5-6 minutes, and `fleetChannelFor` falls back to the |
| + first connected box in sorted order when nothing is bound. So nothing |
| + spreads instances: new traffic lands on the alphabetically first box. |
| +- A box that wins a lease reuses its own local database without |
| + checking for newer writes (`internal/activator/backend_exec.go:882-883`; |
| + the comment at `activator.go:2583-2589` says this holds only with one |
| + box). On a fleet of two or more that boots stale data: #470. |
| +- A dead box's instances already come back on a survivor once its lease |
| + lapses (about 15 minutes), through the hub's fallback. |
| + |
| +The rule (my calls, for Paul's approval): |
| + |
| +1. **The record names its box.** A fleet-placed instance record gets |
| + the label of the box that runs it. The console sets it at create: |
| + the fleet's active, fresh and ready box (rootfs-ready and on the |
| + version floor for a rootfs app) holding the fewest assigned records, |
| + ties broken by label. Records count, not live load: it is |
| + deterministic and needs no new metric. |
| +2. **Only that box mints and runs it.** A fleet box's reconcile admits a |
| + record with a box label only when the label is its own. A record |
| + with no label (every record on main today) keeps today's behaviour, |
| + so single-box fleets change nothing. When a fleet has two or more |
| + active boxes, a console pass labels its unlabelled records once, by |
| + rule 1. Staging and resident starts follow minting, so a box stages |
| + and starts only its own. |
| +3. **The hub knows the box from the start.** 1a's forward row carries |
| + the record's box label as `FleetBox`, so the first request goes to the |
| + right box without waiting for a binding. Bindings still update after |
| + each wake. This is a change to the 1a code once it merges, not to the |
| + 1a spec's trust rules. |
| +4. **A lost box's instances move.** The console relabels a box's |
| + records to survivors (rule 1's choice) when the box is detached or |
| + removed, or when its heartbeat has been absent for longer than the |
| + lease (15 minutes) plus a margin. The lease still guarantees one |
| + writer: a box that was only partitioned keeps its lease until it |
| + lapses, and the new box waits for it. When the old box returns, its |
| + reconcile no longer admits those records and it drops them. |
| +5. **Removal drains.** Removing a box relabels its records to the other |
| + ready boxes first; the old box hibernates them, releasing their |
| + leases, and the new box wakes them from the fleet bucket. Removal is |
| + still refused when no other box can take them (Phase 2 §Removal). |
| +6. **No stale local copy (#470).** On a fleet box, a box keeps its local |
| + database on acquire only when the lock it took was last held by this |
| + same box (owner `ref` and `iid` match; the owner string carries both |
| + since 4029ac5). Otherwise it discards the local copy and restores |
| + from the fleet bucket, as the HA path already decides |
| + (`hafresh.DecideKeep`). An owner it cannot parse counts as another |
| + box. |
| +7. **Rootfs admission follows the box.** A rootfs placement is admitted |
| + when the chosen box is rootfs-ready, replacing "one fresh box ready |
| + and every box on the floor" (`internal/console/rootfs.go:160-212`). |
| + |
| +Tests that prove it: a real two-box fleet test (activator, lease and |
| +restore, not the modelled lease of `TestTwoBoxFleetEndToEnd`) covering |
| +spread at create, one writer, failover after a lost box, the return of |
| +the old box, and no stale read after A, then B, then A serve the same |
| +instance. The 1b plan waits for 1a to merge (stopping rule 4). |
| + |
| +**1c. A reboot doesn't cost 15 minutes (#451).** MERGED as 4029ac5 |
| +(2026-10-30). A box takes an unexpired legacy lock at once when its |
| +owner is this same instance under a different kernel boot. Remaining: |
| +the dev reboot drill. |
| ### Phase 2: managed fleets, no billing |