| index eab0921af..0f95086c7 100644 |
| --- a/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md |
| +++ b/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md |
| @@ -16,7 +16,9 @@ |
| |
| ## Review log |
| |
| -No plan review yet. The design's round history carries into every brief written from this plan (stopping rule 1). Three design rounds: R1 (6 findings), R2 (abandonment family, cut (a)), R3 (R3-1 exhaustive listing, R3-2 staging, R3-3 sweep). The plan review starts at round 1 and has the usual three-round budget. |
| +Plan round 1 (`CODEX-FINDINGS-fleet-seeded-create-plan-R1.md`): NOT READY, 3 P1 and 2 P2, all fixed in this revision. R1-1 app purge bypassed the hold (Task 16 "Every other retirement entrance"); R1-2 `finishSeed` under the record lock deadlocked with lifetimes on (Task 15); R1-3 region file uploads hit the import's one-box rule (Task 5); R1-4 the fleet sweep skipped trashed apps (Task 16); R1-5 delete answers for every aborted reason (Task 16). |
| + |
| +Earlier: no plan review before round 1. The design's round history carries into every brief written from this plan (stopping rule 1). Three design rounds: R1 (6 findings), R2 (abandonment family, cut (a)), R3 (R3-1 exhaustive listing, R3-2 staging, R3-3 sweep). The plan review starts at round 1 and has the usual three-round budget. |
| |
| ## Global Constraints |
| |
| @@ -221,6 +223,7 @@ func (s *Server) seedFileReady(ctx context.Context, region string) *doorRefusal |
| ``` |
| - `importGate` gains an `upload bool` argument. Only the PUT passes true, and only the PUT accepts a `file` seed. Stopped, commit and abort still answer SD-N59 for a file seed. |
| - `staleUploadRefusal`: a `file` seed waits for its upload while it is `reserving`. |
| +- **Upload readiness dispatches on the kind (plan R1-3).** `handleAPIImportUpload` re-checks readiness at `apiinstanceimport.go:416` with `seedRegionReady(..., true)`, whose `true` refuses a region with more than one box (`seedfloor.go:97`). An import keeps exactly that call. A region `file` seed calls `seedFileReady` instead (no one-box rule), and a fleet `file` seed calls `seedFleetReady` (Task 16). Test: `TestFileSeedRegionTwoBoxesBeginThroughUpload`, a non-HA region with two ready boxes, begin then PUT, both succeed. |
| - `runImportUpload` dispatches on `seed.Kind`. The check, the deadlines and the sentences stay the same. For a file seed: put to `s.cfg.SeedData` at `seeds.SnapshotKey`, then `SeedPublishFile`. On failure, `SeedAbortFileUploadBecause`. |
| - `seedStale`: a `file` seed `reserving` for more than `seedReserveTTL` is stale, as `--from` (design §3.3). |
| - `seedfinish.go:124`: `KindFile` joins `KindReplica` for the region replica delete. `deleteSeedReplica` already skips anything outside this console's data bucket (`:270`). |
| @@ -558,14 +561,14 @@ func (s *Server) handleFleetSeedRolledBack(w http.ResponseWriter, r *http.Reques |
| Under `withRecordLock`, `fleetSeedRecord` runs again, and then: |
| - `placed`: `SeedPlace(id)`. A record already `placed` with this id is a no-op success. Then delete `seeds.FleetSnapshotKey` from `s.cfg.Releases` (absent is fine), and bump the serial. |
| - `failed`: `SeedFail(id, sentence)`, then bump the serial. |
| -- `rolledback`: `SeedRolledBack(id)` (already `rolled-back` with this id is fine). Then `finishSeed`, which deletes the fleet snapshot and the record (Task 16), and bump the serial. |
| +- `rolledback`: `SeedRolledBack(id)` (already `rolled-back` with this id is fine), and bump the serial. **Release the record lock, then call `finishSeed`** (plan R1-2). `withRecordLock` holds the app lock (`recordlock.go:20`), and with lifetimes on `finishSeedOnce` reaches `retireRecordWithLifetime` → `withAppHost`, which takes the same non-reentrant app mutex (`lifetimes_retire.go:89`, `lifetimes.go:206`, `applocks.go:41`). `finishSeed`'s own seed-id and state checks and its CAS protect the finish; a finish that fails is retried by the sweep's step 6 as today. |
| - `provision.ErrSeedConflict` answers 409 with nothing changed. Any other error answers 502. |
| |
| - [ ] **Step 1: Failing tests:** |
| - `TestFleetSeedDoorRefusals`: another fleet's token, another box, a labelled record naming another box, an unlabelled record on a fleet with two active boxes, a region record, an `import` or `replica` seed, a malformed host. Each answers the identical 404 body with the record unchanged. A stale seed id answers 409 with the record unchanged. |
| - `TestFleetSeedDoorPlacedDeletesSnapshotOnce`: the first call moves to `placed` and deletes the snapshot. A repeat answers 200 and changes nothing. |
| - `TestFleetSeedDoorFailedMapsCodes`: each code gets its sentence, and an unknown code is a 400. |
| - - `TestFleetSeedDoorRolledBackFinishes`: the record is gone, the snapshot is gone, and the hostname can be created again. |
| + - `TestFleetSeedDoorRolledBackFinishes`: the record is gone, the snapshot is gone, and the hostname can be created again. Run it twice, with lifetimes off and on; the lifetimes-on run must complete (no recursive app lock) and a second app mutation afterwards must not block. |
| - `TestFleetSeedDoorRolledBackOnlyFromAborted`: a `ready` seed answers 409. |
| - The route and parity checks: `go test ./internal/console -run 'TestLinkedPolicyCoversEveryAppRoute|TestParityTableCoversConsoleRoutes' -count=1`, then `go test . -run '^TestParity' -count=1` after `make parity-doc`. |
| - [ ] **Step 2:** `go test ./internal/console -run 'TestFleetSeedDoor' -count=1`. Expect FAIL. |
| @@ -604,38 +607,39 @@ func (s *Server) seedFleetReady(ctx context.Context, fleet string) *doorRefusal |
| ``` |
| - **Begin.** A fleet-placed record (`registry.FleetPlacement(c.placed)`) skips the region and data-bucket checks and calls `seedFleetReady`. The rest is as Task 5. A pool is still FS-20. |
| - **Upload.** For a fleet record, the put goes to `s.cfg.Releases` at `seeds.FleetSnapshotKey`, create-only (`release.PutObjectFrom` with `""`, as `putSnapshot` does). The upload's readiness re-check calls `seedFleetReady`. |
| -- **Sweep.** `StartSeedsPass` no longer returns when `SeedData` is nil. Only the region half needs it. A second listing, for each fleet-placed app (`fleetPlacedApps`, `fleetsecretskey.go:361`, over every account with a fleet), runs `ListMod(seeds.FleetSnapshotsPrefix(sqid, app))` on `s.cfg.Releases`. It must be a `release.ModLister`, or the fleet half deletes nothing and logs. `ParseFleetSnapshotKey` and the same `snapshotDecision` decide, so an aborted fleet file seed's snapshot is deleted while its record stays aborted (R3-3). Step 6 (finish `rolled-back`) is unchanged. It only ever meets a fleet file seed that the door moved to `rolled-back`, which is after proof. The sweep never moves a fleet file seed to `rolled-back`. |
| +- **Sweep.** `StartSeedsPass` no longer returns when `SeedData` is nil. Only the region half needs it. A second listing, for each fleet-placed app **including trashed apps** (plan R1-4: `fleetPlacedApps` passes `includeTrash=false`, `fleetsecretskey.go:361` → `store.go:2077`, so add an `includeTrash` variant; the region half already covers trashed apps, `seedsweep.go:285`), over every account with a fleet, runs `ListMod(seeds.FleetSnapshotsPrefix(sqid, app))` on `s.cfg.Releases`. It must be a `release.ModLister`, or the fleet half deletes nothing and logs. `ParseFleetSnapshotKey` and the same `snapshotDecision` decide, so an aborted fleet file seed's snapshot is deleted while its record stays aborted (R3-3). Step 6 (finish `rolled-back`) is unchanged. It only ever meets a fleet file seed that the door moved to `rolled-back`, which is after proof. The sweep never moves a fleet file seed to `rolled-back`. |
| - **Finish.** `finishSeedOnce`: a fleet-placed record deletes its snapshot from `s.cfg.Releases` at the fleet key and does not need `SeedData`. The replica delete (`:124`) is skipped for a fleet record. `deleteSeedReplica` already refuses one (`:270`), and that is now explicit. |
| - **Delete (Decision D9).** `importDeleteRule :1012` today hands every non-import record to the ordinary delete. For a fleet-placed `file` seed: |
| - not yet `placed` (`reserving`, `ready`): `SeedAbort(id)`, bump the serial, and answer 202 `{"state":"aborting","message":FS-13}`; |
| - - `aborted` with no reason: 409 FS-33; |
| - - `aborted` with FS-30: 409 FS-34; |
| + - `aborted`, whatever its reason (plan R1-5): 409. FS-30 gets its specialised sentence FS-34; every other reason (none, FS-27, FS-28, FS-29, or an upload failure's) gets FS-33. No reason ever reaches the ordinary delete; |
| - `rolled-back`: `finishSeed`; |
| - `placed`: the ordinary delete. |
| |
| A region `file` seed keeps `--from`'s ordinary delete. |
| |
| +- **Every other retirement entrance (plan R1-1).** Instance delete is not the only way a record goes. App purge goes to lifetime retirement or `release.PurgeApp` (`ownership.go:635`); the lifetime path retires each record (`lifetimes_purge.go:125`), and the legacy path deletes app keys (`release/trash.go:401`). Neither checks a seed. Add `unfinishedFleetFileSeeds(app) ([]string, error)`: the hosts of the app whose record is a fleet-placed `file` seed in any state but `placed` or `rolled-back`. Every entrance that retires records or deletes app keys calls it **before any destructive work**, and refuses (409 FS-35, naming the hosts) when it returns any, or when it errors (fail closed). The implementer enumerates the entrances by grepping callers of `retireRecordWithLifetime`, `release.PurgeApp`, the trash-expiry sweep and account closure, and lists them in the task report; at least manual purge (lifetimes on and off) and automatic trash expiry. Once the owning box reports `rolledback` and the record is finished, the purge proceeds. Tests: `TestPurgeAppRefusesHeldFleetFileSeed` (lifetimes on and off, owner offline, replica objects left), `TestTrashExpirySkipsAppWithHeldFleetFileSeed`, `TestPurgeAppProceedsAfterRolledBack`. |
| + |
| - [ ] **Step 1: Failing tests:** |
| - `TestFileSeedBeginFleetWritesDeploymentKey`: begin and upload. The record is `ready`, and the snapshot is at `apps/<sqid>/<app>/seeds/<host>/<id>/snapshot.db` in the deployment bucket. Nothing is in the data bucket. A region app is unchanged (Task 5's test still passes). |
| - `TestSeedFleetReadyNamesBoxes`: one box missing `seeds_floor`, then one at protocol 3. Each is refused with the box named. `TestSeedFleetReadyStaleHeartbeat` is a 503. `TestSeedFleetReadyRefusesTwoActiveBoxes`, `TestSeedFleetReadyRefusesClaimControl`, `TestSeedFleetReadyAdmitsFlat`. |
| - `TestFromOnFleetStillRefuses` (kept). |
| - - `TestSeedsPassDeletesAbortedFleetFileSnapshotKeepsRecord` (R3-3), `TestSeedsPassAbortsStuckFleetFileReservation`, `TestSeedsPassDeletesOrphanFleetSnapshotAfterAnHour`, `TestSeedsPassFleetHalfRunsWithoutSeedData`. |
| + - `TestSeedsPassDeletesAbortedFleetFileSnapshotKeepsRecord` (R3-3), `TestSeedsPassDeletesAbortedFleetFileSnapshotInTrashedApp` (plan R1-4), `TestSeedsPassAbortsStuckFleetFileReservation`, `TestSeedsPassDeletesOrphanFleetSnapshotAfterAnHour`, `TestSeedsPassFleetHalfRunsWithoutSeedData`. |
| - `TestFleetFileSeedNoOwnerNeverFinished`: an aborted fleet file seed whose fleet has no active box. Sweeps and finishes leave the record alone, and the hostname stays held. |
| - - `TestDeleteFleetFileSeedBeforePlacementAborts` and `TestDeleteHeldFleetFileSeedRefuses` (with and without FS-30). `TestDeleteRegionFileSeedIsOrdinary`. |
| + - `TestDeleteFleetFileSeedBeforePlacementAborts` and `TestDeleteHeldFleetFileSeedRefuses`, table-driven over every terminal reason (none, FS-27, FS-28, FS-29, FS-30, an upload failure): each is 409 and the record is unchanged. `TestDeleteRegionFileSeedIsOrdinary`. |
| - `TestFinishFleetFileSeedUsesDeploymentKey`. |
| - Root: `TestInstancesDeletePendingPrintsSentence`. |
| - [ ] **Step 2:** Run the console tests with `-run 'TestFileSeedBeginFleet|TestSeedFleetReady|TestSeedsPass|TestFleetFileSeedNoOwner|TestDelete.*FileSeed|TestFinishFleetFileSeed'` and the root test anchored. Expect FAIL. |
| - [ ] **Step 3:** Implement. Run step 2 again, then `go test ./internal/console -run 'TestSeed|TestImport|TestFrom|TestFinish' -count=1`: PASS. |
| - [ ] **Step 4:** Record-write census: `beginFileSeed`, `runImportUpload`, `seedsPass`, `finishSeedOnce` and `importDeleteRule`, re-pinned. |
| - [ ] **Step 5:** Commit: `console: seed files on a customer fleet`. |
| -- [ ] **Step 6: Own review.** Opus. Name the invariant: nothing on the console moves a fleet file seed to `rolled-back` or deletes its record except after the door's `rolledback`. Name R3-3: the snapshot goes on abandonment, the record stays. Name the readiness rule against design §3.4. |
| +- [ ] **Step 6: Own review.** Opus. Name the invariant: nothing on the console moves a fleet file seed to `rolled-back` or deletes its record except after the door's `rolledback`, and name every retirement entrance the implementer listed (plan R1-1). Name R3-3: the snapshot goes on abandonment, the record stays. Name the readiness rule against design §3.4. |
| |
| ### Task 17: Slice 3 finish: docs, copy pin, census, branch review |
| |
| **Model:** Haiku for docs and the copy pin. Fable for the branch review. |
| |
| - [ ] **Step 1:** `docs/site/cli.md`: the fleet case under `instances create`: the one-box rule, the held hostname, and how a fleet owner frees it (remove the host's prefix in the fleet's bucket). `go test ./internal/docsite -count=1`. |
| -- [ ] **Step 2:** Pin the rest of the copy table in `approved_fleet_seeded_copy_test.go` (FS-13, FS-20 to FS-34, FS-40). `go test . -run '^TestApprovedFleetSeededCopy' -count=1`. |
| +- [ ] **Step 2:** Pin the rest of the copy table in `approved_fleet_seeded_copy_test.go` (FS-13, FS-20 to FS-35, FS-40). `go test . -run '^TestApprovedFleetSeededCopy' -count=1`. |
| - [ ] **Step 3:** Census for the root CLI change (`make census-card`, CLAIMS, `make census-propose NAME=fleet-seeded-create-3`). `make code-health`, `gofmt -l .`, `make parity-doc` (clean). |
| - [ ] **Step 4:** Push and describe. **Whole-branch review:** Fable, with Tasks 15 and 16's review results. Astra gives the census verdict. |
| - [ ] **Step 5:** Merge once CI is green. Subject: `Seed files on customer fleets (#1139, slice 3)`. |
| @@ -713,6 +717,7 @@ Order (AGENTS.md "rollout order"; design §6): boxes, then the floor, then the c |
| | FS-30 | a copy of its data is still in the fleet’s storage | design §3.6 (Seed.Reason) | |
| | FS-33 | %s is already being deleted. Its hostname is free once its box has cleaned up. | pending | |
| | FS-34 | %s keeps its hostname because a copy of its data is still in the fleet’s storage. Remove the host’s copy from the fleet’s bucket, and the hostname is freed on the box’s next pass. | pending | |
| +| FS-35 | %s can’t be purged yet: %s still hold their hostnames until their fleet box has cleaned up. | pending | |
| | — | the upload is not a database that passes an integrity check, so it was not kept. (and the other upload sentences) | reused (SD-N52, SD-N61, SD-N67) | |
| | — | %s places its instances in a pool or on a fleet, so it cannot take a seeded instance. | reused, unchanged, for `--from` and import | |
| |