plan #658 rev 4: plan round 3 fixes (Paul's go, no fourth round)
Deciding proof before admit and planCreateLocked; restore bypasses the leftover rail; nice value normalised; -test.short forwarded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+12
−5
docs/superpowers/plans/2026-11-08-instance-restore-658.md+12 −5
CI failed — run details
diff --git a/docs/superpowers/plans/2026-11-08-instance-restore-658.md b/docs/superpowers/plans/2026-11-08-instance-restore-658.md| index 2d2da2d40..35c7b6e87 100644 |
| --- a/docs/superpowers/plans/2026-11-08-instance-restore-658.md |
| +++ b/docs/superpowers/plans/2026-11-08-instance-restore-658.md |
| @@ -10,7 +10,7 @@ |
| **Spec:** `docs/superpowers/specs/2026-11-07-instance-restore-658-design.md` (rev 5, approved by Paul 2026-11-08). Read it first; this plan argues from it and does not repeat its reasoning. |
| -**Plan rev 3** (2026-11-08). Rev 2 answered Astra plan round 1; round 2 (`CODEX-FINDINGS-instance-restore-658-plan-R2.md`, NOT READY) triggered stopping rule 2 in the refusal-precedence family, and Paul chose the cut on #658 (2026-11-08): the admission rule is stated once, as the precedence table below, enforced in `restoreProof` alone and checked against an independent oracle. Dispositions at the end. |
| +**Plan rev 4** (2026-11-08; rev 3 plus plan round 3's fixes, applied without a fourth round by Paul's go on #658). Rev 2 answered Astra plan round 1; round 2 (`CODEX-FINDINGS-instance-restore-658-plan-R2.md`, NOT READY) triggered stopping rule 2 in the refusal-precedence family, and Paul chose the cut on #658 (2026-11-08): the admission rule is stated once, as the precedence table below, enforced in `restoreProof` alone and checked against an independent oracle. Dispositions at the end. |
| ## Global Constraints |
| @@ -178,13 +178,13 @@ Tasks 3, 4, 5 and 6 touch a security gate (the hostname history and the create d |
| - Produces: |
| - Body field `Restore bool` with tag `json:"restore"`. |
| - The restore intent travels to the core as `withRestore(ctx, restoreAsk) context.Context` / `restoreFrom(ctx) (restoreAsk, bool)`, set only by `handleAPIInstanceCreate`. |
| - - In `createRecordWithLifetimeLocked`, under the locks it holds, before and independent of the `rec.DataKind()` mark block (so a static or service record cannot skip it): if `restoreFrom(ctx)`, re-run `restoreProof` with `Shape: &rec` (the record about to be written) and act on that verdict alone: eligible makes a `markConflict` a pass and sets `a.RestoreOf = verdict.RetirementOp`; `Duplicate` returns `release.ErrCASConflict` (the core's existing duplicate answer); any other verdict returns its refusal as a `hostsUsedError`. |
| + - In `createRecordWithLifetimeLocked`, under the locks it holds, as its first restore-aware step: right after `regionalRecheck` and before `s.admit` (:99) and `planCreateLocked` (:103), and independent of the `rec.DataKind()` mark block (so a static or service record cannot skip it). If `restoreFrom(ctx)`, run the deciding `restoreProof` there with `Shape: &rec` (the record about to be written) and keep its verdict for the rest of this hold; nothing between it and the mark step may answer for a restore except a store or bucket error. Act on that verdict alone: eligible makes a `markConflict` a pass and sets `a.RestoreOf = verdict.RetirementOp`; `Duplicate` returns `release.ErrCASConflict` (the core's existing duplicate answer); any other verdict returns its refusal as a `hostsUsedError`. |
| - C2: in the same core, when an ordinary create's mark step answers S1, run `restoreProof` with `Shape: &rec`; if eligible, the refusal message is C2 instead of S1. (`markForCreate` only sees `HostUse`, so the hint is decided here, where the record is.) |
| - Response gains `"restore": true` on a restore. |
| -- [ ] **Step 1: Write the failing door tests** through the real door (production-wired: real handler, store, `ltStore` bucket): `TestRestoreRoundTrip` (create, write a row to the replica prefix, delete, restore: 201 with `restore: true`, the record's host and region match, incarnation is N+1, the allocation carries `RestoreOf`), `TestRestoreTwice` (Review Focus 4), `TestRestoreRetriedAfterSuccess` (Review Focus 2: the first restore's response is dropped, the retry answers `instance <host> already exists`, no second allocation), `TestRestoreRecordAppearsBetweenEvaluations` (a record lands after the early proof, paused with `pauseGate`: the locked evaluation answers the duplicate), `TestRestoreRegion` (Review Focus 5: none, the home region named explicitly, and the console's own region all pass; another region is R5; with the app's default region set to another region, a restore still writes the stored body's region), `TestRestoreRefusesPlacedApp` (after the delete, the app gains a fleet placement written with `s.store.SetAppPlacement` directly, since the placement door refuses changes under an active history, fleets.go:816-828: R7; and separately a manifest pool: R7), `TestRestoreKeepsRegionPolicy` (after the delete, the manifest's `Regions` no longer includes the home region: the ordinary region refusal, as an ordinary create gets), `TestRestoreStaticKindRefused` (a restore request with kind static or service: R7, and no record written), `TestRestoreStagingRefused` (any object under `moves/<host>/`, including only `build-state.json`: R6; a listing error: R1; staging appearing between the evaluations, via `pauseGate`: R6 from the locked one), `TestRestoreSkipsLeftoverRailOnlyForOwnReplica` (a restore over `instances/<host>` passes; an ordinary create over the same leftovers still gets the rail's refusal), `TestRestoreForeignOwnerSeesOnlyS1` (another account, and another app, each with a conflicting region, staging, missing body and older app lifetime: the response bytes equal an ordinary create's S1), `TestRestoreOwnerSeesDetail` (the rightful owner gets R2, R4, R5, R6, R7, R8 for the same setups), `TestOrdinaryCreateHintsRestore` (C2 for the owner; S1 for anyone else; S1, not C2, for the owner when staging holds only `build-state.json` or the staging list fails), `TestRestoreRacesOrdinaryCreate` (Review Focus 1), `TestRestoreAfterLegacyLineageRefused` (spec §8: create with lifetimes off after activation, cut over, delete, purge the app and recreate it under the same name, restore: R4 or R8, never 201), `TestRestoreAfterManagedEnrolment` (create, run `admitManagedHistory` so `@mode.At` moves, delete, restore: 201), `TestCreateWithoutRestoreUnchanged` (existing S1, S4, S5, leftover-rail and lock-order witnesses still pass unmodified; run them by name in Step 4). |
| +- [ ] **Step 1: Write the failing door tests** through the real door (production-wired: real handler, store, `ltStore` bucket): `TestRestoreRoundTrip` (create, write a row to the replica prefix, delete, restore: 201 with `restore: true`, the record's host and region match, incarnation is N+1, the allocation carries `RestoreOf`), `TestRestoreTwice` (Review Focus 4), `TestRestoreRetriedAfterSuccess` (Review Focus 2: the first restore's response is dropped, the retry answers `instance <host> already exists`, no second allocation), `TestRestoreRecordAppearsBetweenEvaluations` (a record lands after the early proof, paused with `pauseGate`: the locked evaluation answers the duplicate), `TestRestorePendingAppearsBetweenEvaluations` (two traces, each paused after the early proof: another restore's allocation is left pending with no record; and a completed restore whose delete is left pending before N1. Each resumed restore answers R1, 503, with R1's body, and writes no allocation), `TestRestoreRegion` (Review Focus 5: none, the home region named explicitly, and the console's own region all pass; another region is R5; with the app's default region set to another region, a restore still writes the stored body's region), `TestRestoreRefusesPlacedApp` (after the delete, the app gains a fleet placement written with `s.store.SetAppPlacement` directly, since the placement door refuses changes under an active history, fleets.go:816-828: R7; and separately a manifest pool: R7), `TestRestoreKeepsRegionPolicy` (after the delete, the manifest's `Regions` no longer includes the home region: the ordinary region refusal, as an ordinary create gets), `TestRestoreStaticKindRefused` (a restore request with kind static or service: R7, and no record written), `TestRestoreStagingRefused` (any object under `moves/<host>/`, including only `build-state.json`: R6; a listing error: R1; staging appearing between the evaluations, via `pauseGate`: R6 from the locked one), `TestRestoreSkipsLeftoverRailOnlyForOwnReplica` (a restore over `instances/<host>` passes; an ordinary create over the same leftovers still gets the rail's refusal), `TestRestoreForeignOwnerSeesOnlyS1` (another account, and another app, each with a conflicting region, staging, missing body and older app lifetime: the response bytes equal an ordinary create's S1), `TestRestoreOwnerSeesDetail` (the rightful owner gets R2, R4, R5, R6, R7, R8 for the same setups), `TestOrdinaryCreateHintsRestore` (C2 for the owner; S1 for anyone else; S1, not C2, for the owner when staging holds only `build-state.json` or the staging list fails), `TestRestoreRacesOrdinaryCreate` (Review Focus 1), `TestRestoreAfterLegacyLineageRefused` (spec §8: create with lifetimes off after activation, cut over, delete, purge the app and recreate it under the same name, restore: R4 or R8, never 201), `TestRestoreAfterManagedEnrolment` (create, run `admitManagedHistory` so `@mode.At` moves, delete, restore: 201), `TestCreateWithoutRestoreUnchanged` (existing S1, S4, S5, leftover-rail and lock-order witnesses still pass unmodified; run them by name in Step 4). |
| - [ ] **Step 2:** Run `go test ./internal/console -run 'TestRestore|TestOrdinaryCreateHintsRestore'`. Expected: FAIL. |
| -- [ ] **Step 3:** Implement. Order inside the handler: decode, validate host, read `appPlacement` (:1796) and the manifest pool, then if `Restore`: the early `restoreProof` with `Shape: nil` (S1, R1, duplicate or detail; a placed app is R7 there). In the region block, a restore chooses but does not skip: `raw` is the verdict's region name (the stored body's), the app-region default branch (:1815-1826) is not taken, and everything after it runs unchanged: home-name normalization, `checkReplicaCreate`, the `ValidRegion` and manifest `Regions` allow-list check (:1923-1929), the armed-placement gate and `checkPlacement`. The leftover rail skips its `instances/<host>` test for a restore only. Then the existing path to the core, where the deciding evaluation runs. |
| +- [ ] **Step 3:** Implement. Order inside the handler: decode, validate host, read `appPlacement` (:1796) and the manifest pool, then if `Restore`: the early `restoreProof` with `Shape: nil` (S1, R1, duplicate or detail; a placed app is R7 there). In the region block, a restore chooses but does not skip: `raw` is the verdict's region name (the stored body's), the app-region default branch (:1815-1826) is not taken, and everything after it runs unchanged: home-name normalization, `checkReplicaCreate`, the `ValidRegion` and manifest `Regions` allow-list check (:1923-1929), the armed-placement gate and `checkPlacement`. A restore does not call `leftoverReplicaRefusal` at all (its duplicate, replica and staging answers are the admission table's rows 4 and 12); an ordinary create calls it exactly as today. Then the existing path to the core, where the deciding evaluation runs. |
| - [ ] **Step 4:** Run the Step 2 tests, then `go test ./internal/console -run 'HostsUsed|Leftover|LifetimeCreate|InstanceCreate|LockOrder'`. Expected: PASS. |
| - [ ] **Step 5:** Commit `console: restore a deleted instance through the create door (#658)`. |
| @@ -199,7 +199,7 @@ Tasks 3, 4, 5 and 6 touch a security gate (the hostname history and the create d |
| - [ ] **Step 1: Write `TestRestoreRefusesUnmarkedPredecessor`** (spec §4 Guard's fixed trace) on `stampStore`: fixture with app Q's warm database at the host's derived path on an inventoried box and no mark, slot or allocation, Q recorded as the writer in the data oracle; P creates the host with lifetimes on in incomplete mode without a wake (mark stamped T=110); activation runs with a listing that includes Q's file (stamped T=100); P deletes normally; P restores: R8. Before the restore, assert the stored stamps (mark 110, mode 100), P's surviving mark, P's slot, and no origin on P's allocation. Then evaluate rev 3's rule (mark `Source == "create"`, names P, `At > @mode.At`) on that state and assert it would admit P, so the trace discriminates. |
| - [ ] **Step 2: Write `TestRestoreProvenanceSimulation`:** a seeded generator over the actions of spec §4 Guard (including `stampStore` steps backwards and forwards, and managed enrolment), starting each seed from either an empty store or the Q fixture of Step 1. A data oracle records which (account, app, app lifetime) wrote each hostname's data, and its own model of the admission table (re-encoded in the test from its own state, never by calling `restoreProof`, the store accessors or the bucket). Assertions: (a) safety, a restore answers 201 only when every write under that hostname came from the restoring triple; (b) agreement, every restore's answer equals the oracle's row, which covers liveness: when the oracle's model says eligible (mode active now, lifetimes on, claims off, no pending work, origin and lineage clean, a restorable newest retirement, plain, home region, no staging), the answer is 201, and after an invalidation it is R2. Add the deterministic trace activation, create, delete, invalidate, restore (R2), reactivate, restore (201). Bounds: `-short` 50 seeds x 30 steps; otherwise 200 x 40, under 60 s on one core. Print the seed on failure. |
| -- [ ] **Step 2b: Reduced priority in CI.** The simulation test re-executes its own test binary as a child (`os.Args[0] -test.run '^TestRestoreProvenanceSimulation$' -test.v` with `RESTORE_SIM_CHILD=1`) under `nice -n 10`, streams its output, and fails with the child's exit status; when `RESTORE_SIM_CHILD=1` it runs the simulation directly. If `nice` is not on PATH the parent fails rather than running un-niced. The child asserts its own priority with `syscall.Getpriority` (linux; skip the assertion on other GOOS) and fails if it is not at least 10. Nothing else in the shard changes. |
| +- [ ] **Step 2b: Reduced priority in CI.** The simulation test re-executes its own test binary as a child (`os.Args[0] -test.run '^TestRestoreProvenanceSimulation$' -test.v` with `RESTORE_SIM_CHILD=1`) under `nice -n 10`, streams its output, and fails with the child's exit status; when `RESTORE_SIM_CHILD=1` it runs the simulation directly. If `nice` is not on PATH the parent fails rather than running un-niced. The child asserts its own priority on linux (skip on other GOOS) in a helper `niceValue() (int, error)` that returns `20 - raw` from `syscall.Getpriority(syscall.PRIO_PROCESS, 0)` (Linux returns 20 minus nice), and fails unless the nice value is at least 10. The parent forwards `-test.short=true` when `testing.Short()`, and `-test.timeout` equal to the parent's remaining deadline (or 5m with none); the child logs its seed and step counts. Verify: a normal parent and a parent run under `nice` both pass; a child launched without `nice` fails the priority check. Nothing else in the shard changes. |
| - [ ] **Step 3:** Run `nice go test ./internal/console -run 'TestRestoreRefusesUnmarkedPredecessor|TestRestoreProvenanceSimulation'` and time it. Expected: PASS within the bound. Then break `restoreProof` locally three ways and confirm each fails: drop the origin requirement (fixed trace or safety fails); refuse whenever `@mode.At` moved after the origin (agreement fails on the managed-enrolment case); swap table rows 3 and 4 (agreement and `TestRestoreProofPrecedence` fail). Restore them. |
| - [ ] **Step 4:** Commit `console: simulate restore provenance (#658)`. |
| @@ -235,3 +235,10 @@ Stopping rule 2 applied (refusal precedence, rounds 1 and 2); Paul chose the cut |
| 3. P2 region block: a restore chooses the region but keeps every validation; placement and pool are row 10 inputs; the deciding call runs outside the `DataKind()` block; static and service are refused. |
| 4. P2 CI priority: Task 7 Step 2b's niced child process with a priority assertion. |
| 5. P2 tie-break: `rowid` after `created_at`. |
| + |
| +## Plan round 3 dispositions |
| + |
| +Paul's go on #658 (2026-11-08): apply without a fourth round; Task 6's own Astra review checks the placement in code. |
| +1. P1 gates before the deciding proof: it now runs before `admit` and `planCreateLocked` inside the hold, and a restore bypasses the leftover rail entirely (Task 6), with the two paused traces as witnesses. |
| +2. P1 priority inverted: `niceValue` normalizes `20 - raw` (Task 7 Step 2b). |
| +3. P2 `-test.short` lost: forwarded, with a child timeout and logged bounds. |