carlos / platform Public

spec #658 rev 2: builder check answers; refuse older deletions

Paul ruled older deletions are refused. Pre-cutover hosts refuse, the
restore region may be any region, staging relies on the move invariant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 433dfed0bed2ea7c4beacce56756617819843f9c parent 91b745c
1 file changed, +11 −14
  • docs/superpowers/specs/2026-11-07-instance-restore-658-design.md +11 −14

CI cancelled — superseded by a newer push — 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 28fc37fba..3bec01887 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 1, 2026-11-07. Branch `design-instance-restore-658`. Discussion #658 on carlos/platform (taken by Paul, 2026-11-07).
+Rev 2, 2026-11-07 (rev 1 plus the builder check and Paul's ruling on older deletions). Branch `design-instance-restore-658`. Discussion #658 on carlos/platform (taken by Paul, 2026-11-07).
## 1. Why
@@ -15,7 +15,7 @@ The history protects against a new record surfacing data that is not its own: an
Goals:
- A restore through the existing create door, for the CLI and for a service credential with the `instance` role (the same handler serves both, `handleAPIInstanceCreate`, apiinstances.go:1524).
- Delete keeps a durable note of where the instance's last copy lived, so a restore of a moved instance lands on the right copy.
-- Instances deleted before this ships are restorable when one region alone holds their data (§5.2). The live case on account oficina is one of these.
+- Instances deleted before this ships are refused (R8). Without a stored body nothing says which copy is newest, and the console cannot list other regions' buckets to look (Paul, 2026-11-07, on this spec: "Refuse older is fine"). The live case on account oficina keeps the front door's interim: a fresh address.
Non-goals:
- Reusing a hostname for a different account, app or purpose. The never-reuse rule stays exactly as it is for every create without `restore`.
@@ -53,9 +53,9 @@ A restore of `<host>` by account A, app P passes only when all of these hold. An
2. Lifetimes are on (`lifetimesOn`, lifetimes_cutover.go:309). Otherwise refuse (R2).
3. The mark `control/hosts-used/<host>.json` has `Source` `create` or `recovery` and names A and P (`HostUse`, provision/hostsused.go). An `inventory` mark (written at activation for a host already holding data, owner unknown) refuses (R3). So does a mark naming anyone else.
4. The slot `control/host-incarnations/<host>.json` is `retired` and names A and P.
-5. Every `host_allocations` row for the host that is not `void`, and every `record_retirements` row for the host, names A and P. This is the single-lineage check: before activation a mark conflict did not refuse (hostsused.go `markPass`), so a host could have passed from one owner to another while the mark kept naming the first.
+5. Every `host_allocations` row for the host that is not `void`, and every `record_retirements` row for the host, names A and P, and at least one committed allocation exists. This is the single-lineage check: before activation a mark conflict did not refuse (hostsused.go `markPass`), so a host could have passed from one owner to another while the mark kept naming the first. A host created before the lifetimes cutover has no allocation row (the lazy migration writes only `record_migrations`, store.go:501, with no body and no app lifetime), and before the cutover a hostname could change hands leaving no rows at all. So a host with no committed allocation refuses (R3). **My call** (builder check): no safe proof exists for that era.
6. The newest committed retirement's incarnation equals the slot's, and no allocation or retirement for the host is pending (`hostSettling`).
-7. The app's lifetime is the one the last allocation was bound to (`host_allocations.app_lifetime`). An app deleted and recreated under the same name is a different app: refuse (R4). **My call**, conservative; Paul may loosen it.
+7. The app's lifetime is the one the last allocation was bound to (`host_allocations.app_lifetime`). An app deleted and recreated under the same name is a different app: refuse (R4). **My call**, conservative. It does not block the front door: its uninstall deletes only the instance and keeps the app (carlos/base internal/platform/http.go:134, `DeleteInstance`).
8. The last record's shape is restorable (§2 non-goals), and so is the requested one: kind `instance`, paths derived, no HA, no runtime, no pool, no fleet placement, no replica role. Otherwise refuse (R7).
Why this is enough: once the history is active, a host whose mark came from a create had no data on any examined target at activation (activation marks every host it finds as `inventory`), and no second create of it could pass S1. Items 4 to 6 cover the window before activation and the lifetime era. Together they say the only data that can exist under the hostname was written by A's app P.
@@ -66,16 +66,13 @@ Why this is enough: once the history is active, a host whose mark came from a cr
At the delete door, `BeginRetirement` (lifetimes_store.go:208) stores the record body whose ETag it already captures, in a new column `record_retirements.record_body`. N1 tombstones only when the record still has that ETag (lifetimes_retire.go:317), so the stored body is exactly the last record. The restore region is that body's `Region`, and its shape is what §4 item 8 checks.
-The column lives in the console database. A console restored to an older snapshot loses rows; restore then finds no body and falls to §5.2, which refuses rather than guesses when it cannot be sure.
+The restore region may be any region, not only the console's own: the record is all the console writes, and the region's box restores from its own bucket on wake. The console cannot read another region's data bucket (IAM, by design: apidb.go:40 `ErrResidency`), so it checks staging (R6) only when the restore region is its own, through the leftover rail's listing. Elsewhere it relies on the move invariant: a staged copy exists only while an inbound move is landing (backend_exec.go:1013), and delete is refused while a move is live (`refuseDeleteDuringMove`, M-C19), so no staged copy can outlive the record. Plan task 1 confirms that invariant holds for aborted and finished moves alike; if it does not, restore refuses outside the console's region.
-### 5.2 Instances deleted earlier, or with no stored body
+The column lives in the console database. A console restored to an older snapshot loses rows; restore then finds no body and refuses (R8) rather than guessing.
-The restore region is found by looking. Across every region the history examined (the targets `console hosts-used roster` lists), list current objects under `instances/<host>` and `moves/<host>` in each region's data bucket. The restore proceeds only when:
-- exactly one region holds any, and
-- that region equals the `Region` of the host's last allocation body (`host_allocations.body`, the create-time record), and
-- that region holds nothing under `moves/<host>`.
+### 5.2 Instances deleted earlier, or with no stored body
-Otherwise it refuses (R8). A moved instance usually fails the first test, because a move keeps the source's replica (offline moves spec, "kept so an operator's return has it"), and that is the point: without a stored body nothing says which copy is newest. If no region holds anything, the restore region is the allocation body's region and the response says `"restored": false`.
+Refused (R8): the newest committed retirement for the host has no `record_body`. This covers every delete before the release that adds the column, and any row lost to a console restore. No fallback looks for the data: a move keeps the source's replica (offline moves spec, "kept so an operator's return has it"), so finding data in a region does not show it is the newest copy, and the console cannot list other regions' buckets in any case (§5.1).
### 5.3 Box disks
@@ -94,14 +91,14 @@ New user-facing strings, to go through copy review before they are written into
- R5: "<host> can only be restored in <region>, where its data is."
- R6: "<host> has a move's copy waiting in <region>, so it can't be restored. Ask an operator."
- R7: "<host> can't be restored: restore works for plain instances only."
-- R8: "<host> has copies of its data in more than one place, so it isn't clear which is newest. Ask an operator."
+- R8: "<host> was deleted before restore was available, so it can't be restored."
- Ownership refusal (mark, slot or lineage names someone else): the existing S1 text, unchanged. A restore attempt by another owner learns nothing new.
- C2 (S1 when the proof 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.
## 7. Delivery
-One plan, first merge visible (AGENTS.md rule 6): the door with §4 and §5.2 lets the live oficina case restore, and §5.1 rides in the same merge. No switch: restore is a request field, on from the release that carries it (rule 5). Who asks: the front door app (#658). The witness: on dev, create a data-kind instance, write a row, delete it, restore it, read the row back; then the refusal cases R3 to R8 and the other-owner S1.
+One plan, one merge (AGENTS.md rule 6): the door, §4 and §5.1 together, since restore needs a stored body to do anything. What Paul can see: on dev, an instance 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). The witness: on dev, create a data-kind instance, write a row, delete it, restore it, read the row back; then the refusal cases R2 to R8 and the other-owner S1.
Review: specs and plans per 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, so no census card is expected; the plan confirms with `make census-card`.
@@ -110,5 +107,5 @@ Review: specs and plans per AGENTS.md stopping rules (three Astra rounds at most
- Where in `handleAPIInstanceCreate` and `createRecordWithLifetimeLocked` the restore flag travels, and how the proof's reads are shared with the mark step.
- The SQLite migration for `record_body` (nullable; older rows stay null).
- Whether the mark's `Account` and the allocation's `account` use the same identifier (sqid or id), and normalising if not.
-- How §5.2 reuses the roster's region list and the leftover rail's listing (`hostHoldsReplicaData`).
+- How the R6 staging check reuses the leftover rail's listing (`hostHoldsReplicaData`).
- Test shape: production-wired witnesses through the real door, plus a table of the refusals.