spec #658 rev 5: round 3 READY AFTER FIXES, guard fixture added
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+47
−3
docs/superpowers/specs/2026-11-07-instance-restore-658-design.md+8 −3docs/superpowers/specs/CODEX-FINDINGS-instance-restore-658-R3.md+39 −0
CI passed — run details
diff --git a/docs/superpowers/specs/2026-11-07-instance-restore-658-design.md b/docs/superpowers/specs/2026-11-07-instance-restore-658-design.md| index b4878bc73..4bf5953c5 100644 |
| --- a/docs/superpowers/specs/2026-11-07-instance-restore-658-design.md |
| +++ b/docs/superpowers/specs/2026-11-07-instance-restore-658-design.md |
| @@ -1,6 +1,6 @@ |
| # Restore a deleted instance with its own data (#658) |
| -Rev 4, 2026-11-08. Branch `design-instance-restore-658`. Discussion #658 on carlos/platform (taken by Paul, 2026-11-07). Rev 2 had the builder check and Paul's ruling on older deletions; rev 3 answered Astra round 1; rev 4 answers round 2 (`CODEX-FINDINGS-instance-restore-658-R1.md`, `-R2.md`, both NOT READY). Round 2 triggered stopping rule 2 in the provenance family, and Paul chose the cut on #658 (2026-11-08, option 1): provenance is recorded at the original create from this release on, never reconstructed. Dispositions in §10. |
| +Rev 5, 2026-11-08 (rev 4 plus round 3's P2). Branch `design-instance-restore-658`. Discussion #658 on carlos/platform (taken by Paul, 2026-11-07). Rev 2 had the builder check and Paul's ruling on older deletions; rev 3 answered Astra round 1; rev 4 answers round 2 (`CODEX-FINDINGS-instance-restore-658-R1.md`, `-R2.md`, both NOT READY). Round 2 triggered stopping rule 2 in the provenance family, and Paul chose the cut on #658 (2026-11-08, option 1): provenance is recorded at the original create from this release on, never reconstructed. Dispositions in §10. |
| ## 1. Why |
| @@ -68,7 +68,7 @@ A restore of `<host>` by account A and app P, whose current app lifetime is L (` |
| 5. The stored body and the request are both plain (§2 non-goals): kind `instance`, paths derived, no HA, runtime, pool, fleet placement, fleet box, replica role or assignment, seed, demo or demo claim, and the request carries no `from` or import. Otherwise R7. |
| 6. Region (§3 item 2, R5), then staging (§3 item 3, R6). |
| -**Guard.** A randomized simulation drives `restoreProof` and the real create, delete and recovery paths against an in-memory store through sequences of: activation, invalidation, reactivation, managed-fleet enrolment (rewriting `@mode.At`), clock steps backwards and forwards, lifetime cutover, creates with lifetimes on and off in every mode, deletes through every retirement outcome (including a lost N1 response), app purge and recreation under the same name, lazy migration, and restores. It tracks which account, app and app lifetime wrote each hostname's data, and asserts: a restore passes only when every write under that hostname came from the restoring account, app and lifetime. It runs niced and bounded in CI (the repo's simulation budget). |
| +**Guard.** A randomized simulation drives `restoreProof` and the real create, delete and recovery paths against an in-memory store through sequences of: activation, invalidation, reactivation, managed-fleet enrolment (rewriting `@mode.At`), clock steps backwards and forwards, lifetime cutover, creates with lifetimes on and off in every mode, deletes through every retirement outcome (including a lost N1 response), app purge and recreation under the same name, lazy migration, and restores. It tracks which account, app and app lifetime wrote each hostname's data, and asserts: a restore passes only when every write under that hostname came from the restoring account, app and lifetime. Today's paths cannot produce the dangerous starting state from an empty store (every create marks first), so the simulation also starts from a fixture, available to the generator: another owner Q's warm database under the hostname on an inventoried platform box, with no replica objects, mark, slot or allocation, and Q's ownership tracked only in the data oracle. The fixed trace on it: P creates the host with lifetimes on in incomplete mode without a wake, the clock steps back, activation runs with a listing that includes Q's file, P deletes normally, P restores. P owns the surviving mark and slot but has no origin, and must get R8. Swapping rev 3's timestamp rule in for the origin check must fail this trace. It runs niced and bounded in CI (the repo's simulation budget). |
| ## 5. Retirement evidence |
| @@ -106,7 +106,7 @@ R3 is gone (rev 2's pre-cutover refusal is now R8 through §4 stage 2 item 3). |
| One plan, one merge (AGENTS.md rule 6): the door, §4 and §5 together, since restore needs a restorable row to do anything. What Paul can see: on dev, an instance created after the roll, then deleted, comes back with its data. No switch: restore is a request field, on from the release that carries it (rule 5). Who asks: the front door app (#658). |
| -Witnesses, through the real door: create, write a row, delete, restore, read the row back; delete and restore twice; and refusals: another account and another app with a conflicting region, staging, missing body and older app lifetime, all answering the same S1, paired with the rightful owner's detailed answer for each (R2, R4 to R8); staging holding only `build-state.json`; a lost N1 response proven by `record_seq`; a host created before the release (no origin); a host created with lifetimes off after activation, then cut over, deleted, and its app purged and recreated (R4 or R8, never a pass); a managed-fleet enrolment after the origin (still restorable). Plus the §4 guard simulation. |
| +Witnesses, through the real door: create, write a row, delete, restore, read the row back; delete and restore twice; and refusals: another account and another app with a conflicting region, staging, missing body and older app lifetime, all answering the same S1, paired with the rightful owner's detailed answer for each (R2, R4 to R8); staging holding only `build-state.json`; a lost N1 response proven by `record_seq`; a host created before the release (no origin); a host created with lifetimes off after activation, then cut over, deleted, and its app purged and recreated (R4 or R8, never a pass); a managed-fleet enrolment after the origin (still restorable). Plus the §4 guard simulation and its unmarked-predecessor trace. |
| Review: AGENTS.md stopping rules (three Astra rounds at most; stop at the first round with no P1). Census: the change is in `internal/console`, outside the root binary; the plan confirms with `make census-card`. |
| @@ -115,6 +115,7 @@ Review: AGENTS.md stopping rules (three Astra rounds at most; stop at the first |
| - How the restore flag travels through `handleAPIInstanceCreate` and `createRecordWithLifetimeLocked`, and how the two evaluations of the proof share reads. |
| - The SQLite migration (nullable columns; older rows stay null and are never restorable). |
| - Whether the mark's `Account` and the allocation's `account` use the same identifier (sqid or id), and normalising if not. |
| +- Carrying the stronger mark observation (fresh, under `active`) out of `markHost`, whose `markPass` today folds fresh marks and pre-activation conflicts together (hostsused.go:596, :621), without changing the mark's create-only semantics. The seed and import doors share the lifetime create protocol (apiinstanceseed.go:84) and must not set `restore_origin`. |
| - Plan task 1's two inventories: the writers of `record_retirements` and removers of data-kind records (§5); the sibling-box warm-file check (§6). |
| ## 10. Round 1 dispositions |
| @@ -134,3 +135,7 @@ Round 2 resolved round 1's staging, seed and all four P2 findings, and found two |
| 1. P1 timestamp provenance: replaced, not patched. The origin is a flag the original create records from what it observed (§4 stage 2 item 3); no timestamp is compared. |
| 2. P1 empty allocation history: closed by the same flag. Eligibility needs a positive origin row bound to L, and an allocation for the retired incarnation; an empty or migrated history answers R8. |
| 3. P2 refusal precedence: accepted. §3 item 1 and §4 split ownership (S1) from eligibility (detailed refusals), both evaluated in one function, twice. |
| + |
| +## 10c. Round 3 disposition |
| + |
| +Round 3 (`CODEX-FINDINGS-instance-restore-658-R3.md`): READY AFTER FIXES. Both round 2 P1s and the P2 resolved; no P1. Its one P2, the guard's missing unmarked-predecessor fixture, is applied in §4 Guard and §8. Review is over (stopping rule 1). |
diff --git a/docs/superpowers/specs/CODEX-FINDINGS-instance-restore-658-R3.md b/docs/superpowers/specs/CODEX-FINDINGS-instance-restore-658-R3.md| new file mode 100644 |
| index 000000000..5c5b4b1ce |
| --- /dev/null |
| +++ b/docs/superpowers/specs/CODEX-FINDINGS-instance-restore-658-R3.md |
| @@ -0,0 +1,39 @@ |
| +# Instance restore #658 — round 3 findings |
| + |
| +Reviewed rev 4 at `2176ad6b3ac3811dccbcc58198d7218bd48effaf`. The brief names `a4279dec34226358cc71d1d16e4fc76cfa003629`; the design is unchanged between those commits. Read both authority specs and checked the relevant code in this checkout. The diff against the amadan remote's `origin/main` contains only the six instance-restore design, brief and findings documents. No unmerged implementation was used. No subagents or test suites were run. |
| + |
| +## Round 2 dispositions |
| + |
| +1. **P1 timestamp provenance — resolved.** §4 stage 2 item 3 requires a positive origin recorded from the original mark operation, with lifetimes on, active mode and a fresh mark. It no longer compares timestamps. Activation finishes its inventory marks before publishing active mode (`internal/console/hostsused_activate.go:441`, `:443`, `:469`), and refuses pending allocations, retirements and migrations (`:334`, `:346`). The activation command holds the console's serve lock (`cmd/console/hostsused.go:118`); the serving console holds the same lock (`cmd/console/main.go:322`). Managed enrollment can still rewrite `At` (`internal/console/managedhistory.go:60`), but that no longer changes the origin evidence. The remaining regression-coverage omission is P2 finding 1 below. |
| +2. **P1 empty allocation history — resolved.** The revised rule requires an origin row, all non-void rows bound to A/P/L, and a row at the retired slot's incarnation (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:64`). Lifetimes-off creation writes a record without an allocation (`internal/console/hostsused.go:709`, `:717`); migration is a separate intent and writer (`internal/console/lifetimes_migrate.go:139`, `:338`). Neither can supply the required origin. Purging and recreating an app mints a new lifetime (`internal/console/lifetimes_store.go:387`, `:401`), which the all-rows comparison rejects. |
| +3. **P2 refusal precedence — resolved.** Stage 1 now checks only the mark and slot's account/app ownership; stage 2 owns eligibility and its detailed refusals. The early placement and locked recheck are explicit (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:38`, `:56`, `:60`). This permits the rightful owner's R2/R4–R8 responses without exposing them to a different account or app. An inventory mark without an owner remains S1, as the stated stage-1 rule requires. |
| + |
| +## P1 |
| + |
| +None found. |
| + |
| +## P2 |
| + |
| +### 1. The guard does not specify the unmarked historical data needed to reproduce the provenance regression |
| + |
| +**Section:** §4 Guard and §8 witnesses (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:71`, `:109`). |
| + |
| +**Problem and evidence:** The simulation drives the real current create, delete and recovery paths, including lifetimes-off creates in incomplete mode. Those paths cannot generate the original untracked-owner setup from an empty store: the lifetimes-off writer still calls `markBeforeCreate` before publishing (`internal/console/hostsused.go:709`, `:713`, `:717`), and `markHost` writes a mark even in incomplete mode (`:605`, `:616`, `:621`). `MarkHostUsed` preserves the first mark on conflict (`internal/provision/hostsused.go:82`, `:83`). The specified action list has no initial legacy disk/object state without marks or allocations, and the explicit witnesses do not require it either. |
| + |
| +**Failure scenario:** A simulator starts empty and creates Q's data through today's lifetimes-off path. Q receives the first mark. P later creates the same host before activation, but Q's mark survives, so P's restore fails stage 1. This does not exercise round 1 P1 finding 1 or round 2 P1 finding 1: those require Q's old warm database with **no mark**, followed by P obtaining the first create mark without waking the database. A regression that accepts P's pre-activation mark through the old timestamp rule can therefore escape this simulation. Merely adding clock rollback to the generated operations does not produce the missing historical state. |
| + |
| +**Concrete fix:** Require a deterministic starting fixture, also available to the random generator, containing Q's warm database under H on an inventoried platform box, with no replica objects, mark, slot or allocation history. Track Q's ownership in the data oracle independently of those absent control-plane records. Then run P's lifetimes-on create in incomplete mode without a wake, roll the clock backwards, activate using a listing that includes Q's file, delete P's record normally, and attempt restore. Assert that P has no origin and receives R8 despite owning both the surviving mark and slot. Keep this trace alongside the existing lifetimes-off → cutover → purge/recreate witness. The trace should expose the old timestamp admission if substituted for the origin check. |
| + |
| +**Fault family:** Regression coverage for hostname data provenance across owners and app lifetimes. This is a missing test requirement, not an identified bypass of rev 4's origin rule. |
| + |
| +## Other checks |
| + |
| +- The only production `BeginAllocation` caller is the shared lifetime create protocol, after its mark step (`internal/console/lifetimes_create.go:128`, `:142`, `:146`). Seed/import creation uses that same protocol (`internal/console/apiinstanceseed.go:84`, `:86`), so the implementation must preserve the spec's explicit exclusion of seeds when setting the origin. The mark observation must be carried out of `markHost`: today's `markPass` combines fresh marks with pre-activation conflicts (`internal/console/hostsused.go:596`, `:621`). The spec requires the stronger observation and is implementable without changing the mark's create-only semantics. |
| +- Recovery reads and replays the persisted allocation; it does not begin a replacement allocation or reconstruct origin evidence (`internal/console/lifetimes_recovery.go:74`, `:84`, `:231`, `:237`). Its mark check requires an existing mark once active or invalidated (`internal/console/hostsused.go:561`, `:567`). Lifetimes-off and sidecar writers remain behind their own mark checks; migration rewrites an existing record. No additional production origin writer was found. |
| +- The plain repeated-restore sequence fits the lineage rule: the original non-void allocation retains the origin; each restore adds a higher incarnation carrying `restore_of`; all remain bound to the same app lifetime. Allocation chooses a number above both the stored maximum and the slot (`internal/console/lifetimes_create.go:108`, `:113`, `:123`). Terminal allocation rows retain their other columns (`internal/console/lifetimes_store.go:110`, `:116`). Losing an origin or a matching incarnation through a database rollback causes refusal rather than reconstruction. |
| +- The retirement proof remains consistent with the code: N1 uses the captured ETag (`internal/console/lifetimes_retire.go:317`, `:323`); tombstoning preserves the sequence (`internal/provision/lifetime.go:157`), and the canonical writer advances it (`internal/provision/record_sequence.go:167`, `:172`). §5 excludes unproven terminal outcomes. The proposed evidence must survive recovery and be persisted before tombstone removal, as required by proving it before N3. |
| +- The whole-prefix staging refusal matches promotion's read boundary (`internal/activator/backend_exec.go:3849`, `:3862`). Seed exclusion covers the purge before the warm-file test (`internal/activator/backend_exec.go:988`, `internal/activator/seedplace.go:282`, `:290`). Neither #661 nor the accepted sibling-box wake behavior is reopened here. |
| + |
| +This is round 3 of 3. Apply the P2 coverage fix without another review round; no P1 remains outstanding. |
| + |
| +**READY AFTER FIXES** |