carlos / platform Public

plan: #1139 plan round 1 fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ad30bf9d645be23bf2646cd7435ed7aa3a4f8135 parent 69aab62
2 files changed, +68 −10
  • docs/superpowers/plans/2026-11-20-fleet-seeded-create.md +15 −10
  • docs/superpowers/plans/CODEX-FINDINGS-fleet-seeded-create-plan-R1.md +53 −0
diff --git a/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md b/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md
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 |
diff --git a/docs/superpowers/plans/CODEX-FINDINGS-fleet-seeded-create-plan-R1.md b/docs/superpowers/plans/CODEX-FINDINGS-fleet-seeded-create-plan-R1.md
new file mode 100644
index 000000000..09aca9770
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-FINDINGS-fleet-seeded-create-plan-R1.md
@@ -0,0 +1,53 @@
+Found **3 P1s and 2 P2s**. Reviewed the requested revision; HEAD only adds the review brief. No files changed or tests run.
+
+1. **P1 — Task 16 protects instance deletion, but app purge bypasses the cleanup invariant.**
+
+ **Evidence:** The plan guards `importDeleteRule` at `docs/superpowers/plans/2026-11-20-fleet-seeded-create.md:609`. However, `internal/console/ownership.go:635` sends app purge directly to either lifetime retirement or `release.PurgeApp`. The lifetime path retires each present record at `internal/console/lifetimes_purge.go:125`; the legacy sweep deletes app keys at `internal/release/trash.go:401`. Neither requires a fleet seed’s `rolled-back` state.
+
+ **Failure scenario:** An aborted fleet file seed holds its hostname because its box is offline or replica objects remain. Trashing and purging the app removes that record without any owning-box cleanup proof. This bypasses `rollbackFleetFileSeed` entirely.
+
+ **Fix:** Add an explicit task guarding app purge and other record-retirement entrances against unfinished fleet file seeds, including lifetime-enabled and legacy paths. Refuse before destructive work begins; only permit cleanup after the existing rollback proof. Test manual purge and automatic expiry with an offline owner and remaining replica objects.
+
+ **Fault family:** Abandonment — hostname release requires owning-box cleanup proof.
+
+2. **P1 — Task 15 calls `finishSeed` while holding a lock it reacquires.**
+
+ **Evidence:** The plan places the `rolledback` transition and `finishSeed` under `withRecordLock` at `docs/superpowers/plans/2026-11-20-fleet-seeded-create.md:558`. That helper acquires the app lock (`internal/console/recordlock.go:20`). With lifetimes enabled, `finishSeedOnce` calls `retireRecordWithLifetime` (`internal/console/seedfinish.go:134`), which enters `withAppHost` (`internal/console/lifetimes_retire.go:89`) and acquires the same app lock (`internal/console/lifetimes.go:206`). The lock is a non-reentrant mutex (`internal/console/applocks.go:41`).
+
+ **Failure scenario:** A valid `rolledback` report changes the state, then hangs during finish. It holds the app lock indefinitely, blocking subsequent app mutations and sweep completion.
+
+ **Fix:** Authenticate again and perform the transition under `withRecordLock`, then release it before calling `finishSeed`. Its existing seed-ID/state checks and CAS protect finishing. Exercise the complete handler with lifetimes enabled.
+
+ **Fault family:** Lock ownership — no recursive acquisition of the app mutex.
+
+3. **P1 — Task 5 leaves region file uploads subject to the import-only one-box restriction.**
+
+ **Evidence:** The plan explicitly allows region file seeds without a one-box restriction at `docs/superpowers/plans/2026-11-20-fleet-seeded-create.md:215`, but its upload changes at lines 222–224 do not replace the readiness call in `handleAPIImportUpload`. That call is `seedRegionReady(..., true)` at `internal/console/apiinstanceimport.go:416`; `true` rejects multiple region boxes at `internal/console/seedfloor.go:97`. Task 16 explicitly changes the fleet upload re-check, but no equivalent region-file dispatch is specified.
+
+ **Failure scenario:** On a supported, non-HA region with two ready boxes, begin succeeds and reserves the hostname, but PUT refuses because “An import needs a region with one box.”
+
+ **Fix:** Specify upload readiness dispatch explicitly: imports retain `seedRegionReady(..., true)`; region file seeds use `seedFileReady`; fleet file seeds use `seedFleetReady`. Add a two-box region begin-through-upload test.
+
+ **Fault family:** Admission consistency — an accepted file-seed placement must remain uploadable.
+
+4. **P2 — Task 16’s snapshot sweep excludes trashed apps.**
+
+ **Evidence:** The planned fleet enumeration uses `fleetPlacedApps` at `docs/superpowers/plans/2026-11-20-fleet-seeded-create.md:607`. That helper passes `includeTrash=false` (`internal/console/fleetsecretskey.go:361`), ultimately selecting only `deleted_at = 0` apps (`internal/console/store.go:2077`). Existing snapshot cleanup explicitly covers aborted seeds in trashed apps (`internal/console/seedsweep.go:285`).
+
+ **Failure scenario:** Trash an app with an abandoned fleet seed whose hostname remains held. Its deployment-bucket snapshot is excluded from subsequent sweeps, contrary to R3-3’s requirement that abandonment releases the snapshot independently of the record.
+
+ **Fix:** Enumerate retained fleet apps including trash, with a test proving that the snapshot disappears while the aborted record remains.
+
+ **Fault family:** Snapshot retention — held hostnames must not retain abandoned upload data.
+
+5. **P2 — Task 16 does not define deletion responses for most terminal failure reasons.**
+
+ **Evidence:** The delete table only covers `aborted` with no reason or FS-30 (`docs/superpowers/plans/2026-11-20-fleet-seeded-create.md:611`). Task 15 also writes FS-27, FS-28 and FS-29 through `failed` (lines 553–560); Task 5 writes upload-failure reasons (line 224).
+
+ **Failure scenario:** Deleting a seed aborted for a mismatch, invalid database or pre-existing copy reaches an unspecified branch. The current import fallback cannot supply the intended fleet-specific response.
+
+ **Fix:** Define refusal for **every** aborted fleet file seed, regardless of reason. FS-30 may select its specialized explanation; all other reasons must still preserve the hostname. Add table coverage for each terminal reason.
+
+ **Fault family:** Abandonment — error reporting must never bypass the hostname hold.
+
+**NOT READY**
\ No newline at end of file