carlos / platform Public

spec #658 rev 4: record restore provenance at the original create

Paul's cut after round 2 (stopping rule 2): a restore-origin flag set by
a create that wrote its mark fresh under an active history with
lifetimes on; one proof function guarded by a randomized simulation;
ownership (S1) split from eligibility.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a4279dec34226358cc71d1d16e4fc76cfa003629 parent b813ec7
1 file changed, +37 −21
  • docs/superpowers/specs/2026-11-07-instance-restore-658-design.md +37 −21
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 155a8d7af..b4878bc73 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 3, 2026-11-07. 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 answers Astra round 1 (`CODEX-FINDINGS-instance-restore-658-R1.md`, NOT READY, three P1s and four P2s; dispositions in §10).
+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.
## 1. Why
@@ -17,7 +17,7 @@ Goals:
- Delete keeps durable, proven evidence of the record it retired (§5).
Non-goals (each refused up front):
-- Instances deleted before the release that ships this, and instances whose hostname was first marked before the current activation of the hostname history (R8). Paul, 2026-11-07: "Refuse older is fine". The live case on account oficina keeps the front door's interim: a fresh address.
+- Instances whose original create predates the release that ships this, or was not admitted with a fresh mark under a completed activation with lifetimes on (§4 item 3), and instances deleted before that release (R8). Paul, 2026-11-07: "Refuse older is fine". The live case on account oficina keeps the front door's interim: a fresh address.
- Restoring outside the console's own region (R5). The console cannot read another region's data bucket (apidb.go:40 `ErrResidency`), so it cannot make the staging check of §3 there.
- Sidecars, HA, rootfs, pool, fleet-placed, addr-backed, replica, demo, seeded and imported instances, as the old record or the request (R7). A seeded database carries a seed marker that an unseeded successor purges before its warm-cache test (seedplace.go:273, backend_exec.go:988), so a seeded instance cannot keep its data under a new record without wake-path changes.
- Restoring with claims on (R2). Production runs claims off (shelved 2026-10-25).
@@ -35,11 +35,11 @@ Anti-goals:
The create body gains `"restore": true`. The CLI flag is `carlos instances create --restore` (the CLI lives in its own repo; this repo owns the door and docs/site/cli.md). A restore runs every check a create runs today, with these changes and only when `restore` is set:
-1. **Ownership first.** Right after the body is decoded and the host validated, and before region resolution, the leftover rail or any other history-dependent check, the door evaluates the ownership proof (§4). If it fails for any reason other than an unreadable source, the answer is S1, unchanged, whatever else is wrong with the request. Only once it passes can a caller see R4 to R8. The proof is evaluated again at the mark step, under the app lock and the lifetime admission the create already holds (lifetimes_create.go:63), and that second evaluation decides.
+1. **Ownership, then eligibility.** Right after the body is decoded and the host validated, and before region resolution, the leftover rail or any other history-dependent check, the door evaluates ownership (§4, stage 1). If ownership fails for any reason other than an unreadable source, the answer is S1, unchanged, whatever else is wrong with the request. Only an owner reaches eligibility (§4, stage 2), whose failures answer R2 and R4 to R8. Both stages are evaluated again at the mark step, under the app lock and the lifetime admission the create already holds (lifetimes_create.go:63), and that second evaluation decides. Region (item 2) and staging (item 3) are part of eligibility and run only after ownership passes.
2. **Region.** The region is the stored body's `Region` (§5), which must be the console's own region (`s.cfg.Region`), else R5. A request naming a different region is refused (R5). Nearest-region and app-region placement are not consulted. `checkPlacement` and the region's other create checks still apply.
3. **Staging.** The door lists the whole prefix `moves/<host>/` in the console region's data bucket, every object of any name (the boundary promotion uses: backend_exec.go:3849 lists `MovesPrefix(host)` and mirrors all of it). Any object refuses (R6); a listing error refuses (R1). This replaces the LTX-only test of `hostHoldsReplicaData` for a restore. Staging that survives a finished move is a live hazard beyond restore and is filed separately (§10).
4. **The leftover rail** (createleftovers.go:136) does not refuse on the host's own replica prefix `instances/<host>` for a restore. Item 3 covers staging.
-5. **The mark step.** `markForCreate` (hostsused.go:631) treats a conflicting mark as a pass only when the second evaluation of the proof passes.
+5. **The mark step.** `markForCreate` (hostsused.go:631) treats a conflicting mark as a pass only when the second evaluation of both stages passes. The restore's allocation row records `restore_of` (§4 item 3).
`gateDataCreate` (S2, S4, S5) runs as today.
@@ -47,20 +47,28 @@ The restored record is a new lifetime: incarnation N+1 from `LastIncarnation`, o
The response is the create's response plus `"restore": true`: the record was accepted as a restore. It does not claim data came back; the console cannot see the box's warm file, and the wake happens later. A restore over data that turns out to be absent wakes empty, which the history spec's §1 already calls harmless for the same owner.
-When an ordinary create (no `restore`) hits S1 and the proof would pass, the refusal says how to restore (C2). C2 depends on the complete proof, so another owner never sees it.
+When an ordinary create (no `restore`) hits S1 and both stages would pass, the refusal says how to restore (C2). C2 depends on both stages, so another owner never sees it.
-## 4. Ownership proof
+## 4. Ownership and eligibility
-A restore of `<host>` by account A and app P, whose current app lifetime is L (`apps.lifetime`), passes only when all of these hold. A source that cannot be read refuses with R1, never as a pass.
+A restore of `<host>` by account A and app P, whose current app lifetime is L (`apps.lifetime`). A source that cannot be read refuses with R1, never as a pass. One function evaluates both stages (`restoreProof`, the builder's name); the door, the mark step and C2 all call it, and nothing else decides a restore.
-1. The history mode `@mode` is `active`, and lifetimes are on (`lifetimesOn`, lifetimes_cutover.go:309), and claims are off. Otherwise R2.
-2. The mark `control/hosts-used/<host>.json` has `Source` `create`, names A and P, and its `At` is later than `@mode.At`. `markHost` stamps `At` at write (hostsused.go:614); only activation and invalidation write `@mode.At` (hostsused_activate.go:468, hostsused.go:485, :536, hostsused_activate.go:496). So the mark was written by a create admitted under the current activation, when activation's inventory had already marked every hostname holding data on any examined target, and S4 refused creates on targets it had not examined. That is the provenance: no data under the hostname predates this mark. A mark written before the current activation (any `create` or `recovery` mark from the incomplete window, which `markPass` let conflict, or one from an earlier activation that was later invalidated) is refused (R8): its predecessors cannot be ruled out.
-3. Every `host_allocations` row for the host that is not `void` names A, P and L. Under item 2 the first of them is the mark's create, since S1 refuses every later create; the rest are earlier restores. A row bound to another app lifetime refuses (R4).
-4. The slot `control/host-incarnations/<host>.json` is `retired` and names A and P. No allocation or retirement for the host is pending (`hostSettling`).
-5. The newest `record_retirements` row for the host names A and P, has the slot's incarnation, and is marked restorable (§5). Any other outcome refuses (R8), and no older row is consulted.
-6. 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.
+**Stage 1, ownership.** The mark `control/hosts-used/<host>.json` names A and P, and the slot `control/host-incarnations/<host>.json` names A and P. Anything else answers S1.
-Items 2 and 3 together say the only data that can exist under the hostname was written by app P in lifetime L, under this mark's lineage.
+**Stage 2, eligibility.**
+
+1. The history mode `@mode` is `active`, lifetimes are on (`lifetimesOn`, lifetimes_cutover.go:309), and claims are off. Otherwise R2.
+2. The slot is `retired`, and no allocation or retirement for the host is pending (`hostSettling`). Otherwise R1 (try again) while pending, R8 otherwise.
+3. **The origin.** `host_allocations` gains two nullable columns, `restore_origin` and `restore_of`. The create path sets `restore_origin` on its allocation row, at `BeginAllocation` (lifetimes_create.go:146), when and only when all of these held at its own mark step: lifetimes were on, `markHost` read the mode `active`, and `MarkHostUsed` reported the mark fresh (it wrote it; provision/hostsused.go:73). A restore's own allocation row instead carries `restore_of`, the op id of the retirement it restores. No other writer sets either column; recovery (`recoveryMark`), the lifetimes-off writer, migration and seeds never do.
+
+ Eligibility requires: among the host's allocation rows that are not `void`, the lowest incarnation carries `restore_origin`; every other one carries `restore_of`; every one names A, P and L; and one of them has the slot's incarnation. A row bound to another app lifetime answers R4. Anything else (no origin, an empty history, a migrated record whose incarnation has no allocation, a row with neither flag) answers R8.
+
+ Why this is the provenance, with no timestamps: an active mode means an activation completed, and activation marks every hostname holding data on any examined target before it writes the mode (hostsused_activate.go:441-468), while S4 refuses creates on targets it did not examine. A mark this create wrote fresh after that therefore names a hostname that held no data anywhere the history could see. From then on S1 refuses every create of it except a restore, and every restore must pass this same check. So every data write under the hostname since its origin was made by app P in lifetime L. The flag records the observation at the moment it was true, so later rewrites of `@mode.At` (managed fleets, managedhistory.go:60), invalidation, reactivation or clock changes cannot move it.
+4. The newest `record_retirements` row for the host names A and P, has the slot's incarnation, and is restorable (§5). Otherwise R8, and no older row is consulted.
+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).
## 5. Retirement evidence
@@ -69,7 +77,7 @@ Items 2 and 3 together say the only data that can exist under the hostname was w
- `BeginRetirement` (lifetimes_store.go:208) stores the body whose ETag it captures, as a candidate.
- `restorable` is set only for a normal retirement, and only when the tombstone over that body is proven: either N1's own write landed (lifetimes_retire.go:317, CAS on the captured ETag), or recovery observes, before N3, a tombstone at the record key whose incarnation is the row's and whose `record_seq` is the candidate's plus one. `TombstoneBody` keeps `record_seq` and `WriteRecord` advances it by exactly one (provision/lifetime.go:151), so that pair names the tombstone written over exactly the captured body. This covers a lost N1 response.
- Every other outcome leaves `restorable` unset: a slot found already retired (lifetimes_retire.go:266), an absent record (:288), a conversion to cleanup (:294, which replaces the ETag), orphan and cleanup retirements, and any path that removes a data-kind record without a retirement row. Plan task 1 lists every writer of `record_retirements` and every remover of a data-kind record and shows each either takes this rule or leaves no restorable row.
-- The column lives in the console database. A console restored to an older snapshot loses rows; the newest row no longer matches the slot's incarnation (item 5) and restore refuses.
+- The columns live in the console database. A console restored to an older snapshot loses rows; the newest row or the origin no longer matches the slot's incarnation (§4 stage 2, items 3 and 4) and restore refuses.
## 6. Box disks
@@ -87,18 +95,18 @@ New user-facing strings, to go through copy review before they are written into
- R5: "<host> can only be restored from the console in <region>." (the stored body's region)
- R6: "<host> has a move's copy waiting, so it can't be restored. Ask an operator."
- R7: "<host> can't be restored: restore works for plain instances only."
-- R8: "<host> was deleted before restore was available, so it can't be restored."
-- Ownership failure (mark, slot, lineage or retirement names someone else, or the mark is not this owner's): the existing S1 text, unchanged.
-- C2 (S1 when the proof would pass): "<host> held this app's data before. To bring it back, create it with --restore."
+- R8: "<host> was created or deleted before restore was available, so it can't be restored."
+- Ownership failure (stage 1: the mark or the slot names someone else): the existing S1 text, unchanged.
+- C2 (S1 when both stages would pass): "<host> held this app's data before. To bring it back, create it with --restore."
- docs/site/cli.md: a short "Restoring a deleted instance" section beside the delete text at line 1230.
-R3 is gone (rev 2's pre-cutover refusal is now R8 through §4 item 2).
+R3 is gone (rev 2's pre-cutover refusal is now R8 through §4 stage 2 item 3).
## 8. Delivery
-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 and deleted after the roll 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).
+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; R2, R4 to R8; staging holding only `build-state.json`; a lost N1 response proven by `record_seq`; a mark older than `@mode.At`.
+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.
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`.
@@ -118,3 +126,11 @@ Review: AGENTS.md stopping rules (three Astra rounds at most; stop at the first
5. P2 local-file freshness: answered by scoping the guarantee to hibernation's (§6), with the check moved to plan task 1 and a separate issue if real.
6. P2 order: accepted, §3 item 1.
7. P2 `restored` boolean: accepted; the response reports acceptance only.
+
+## 10b. Round 2 dispositions
+
+Round 2 resolved round 1's staging, seed and all four P2 findings, and found two P1s in round 1's provenance family. Stopping rule 2 applied; Paul chose the cut (#658, 2026-11-08, option 1).
+
+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.