carlos / platform Public

plan #658: Astra plan round 2 findings (NOT READY)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev dfcd7af6f4ce7e75b40d4f71000fe94289ea9c95 parent 4152736
1 file changed, +90 −0
  • docs/superpowers/plans/CODEX-FINDINGS-instance-restore-658-plan-R2.md +90 −0

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/plans/CODEX-FINDINGS-instance-restore-658-plan-R2.md b/docs/superpowers/plans/CODEX-FINDINGS-instance-restore-658-plan-R2.md
new file mode 100644
index 000000000..df5091c0c
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-FINDINGS-instance-restore-658-plan-R2.md
@@ -0,0 +1,90 @@
+# Instance restore #658: implementation-plan review, round 2
+
+1. **R1 P1-1 — resolved.** Task 5 uses non-locking `PendingForHost`; the lock contract and bounded witness are explicit (plan:23, :130, :140).
+2. **R1 P1-2 — partly resolved.** A completed restore's retry now gets the duplicate answer, but placing that answer before pending-operation detection breaks the required pending-delete response. Carried forward as P1 finding 1 below.
+3. **R1 P1-3 — resolved.** Task 4 excludes both nil-body cases and stops before N2 when persisting evidence fails (plan:111-117).
+4. **R1 P2-4 — resolved.** Staging is inside the shared proof, with locked-evaluation and C2 witnesses (plan:138, :162).
+5. **R1 P2-5 — partly resolved.** The deciding call receives the constructed record and home-region defaulting is bypassed, but the replacement instruction also removes placement evidence and required region validation. Carried forward at P2 as finding 3.
+6. **R1 P2-6 — resolved.** Conversion clears both evidence columns atomically, with a post-mark corruption witness (plan:115, :117).
+7. **R1 P2-7 — resolved.** `stampStore` controls the persisted mark and mode timestamps while preserving conditional writes; the fixed trace asserts the discriminating timestamps (plan:175-177).
+8. **R1 P2-8 — partly resolved.** Both deterministic delivery traces and the generator's Q fixture are present. CI niceness remains missing, carried forward at P2 as finding 4. The newly added unconditional liveness assertion introduces the separate failure in finding 2.
+
+Reviewed `design-instance-restore-658` at `41527362cf2b962ae31d39baab8d27d48d89918e`, as requested. The brief names `d50195c6a39413e5706b3a19a80eefc2f565e860`; only the brief differs between those commits. Here, **plan** means `docs/superpowers/plans/2026-11-08-instance-restore-658.md`, and **spec** means the approved rev 5 `docs/superpowers/specs/2026-11-07-instance-restore-658-design.md`. The implementation matches the amadan remote's local `origin/main`, `f864af5efe6ad301a3e507e99c5c07589c24a186`; the branch diff contains only design, plan and review documents. No subagents or tests were run. Only this findings file was written.
+
+The spec's completed reviews remain closed. This is plan round 2 of 3.
+
+## P1
+
+### 1. The duplicate check hides a retirement that is still pending before N1
+
+**Tasks:** 5 and 6. **Fault family:** restore response precedence; repeats R1 P1-2, whose fix explicitly required preserving R1 for pending work.
+
+**Problem and evidence:** Task 5 checks for an owned valid record immediately after ownership, before any eligibility item (`docs/superpowers/plans/2026-11-08-instance-restore-658.md:136`, :138). Its own pending-retirement witness requires R1 while deletion is pending (:140), as does spec §4 item 2 (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:61`). These states overlap: retirement persists its row before attempting N1 (`internal/console/lifetimes_retire.go:171`, :173, :323). A failed N1 write returns pending without changing the live record (:324-325). The existing `pendingRetire("begin")` fixture constructs precisely this state (`internal/console/lifetimes_retire_test.go:707`, :715-716).
+
+**Failure scenario:** Create an eligible instance, begin deletion, and fail the tombstone write before it lands. Restore while that retirement is pending. The mark and live slot name the owner, and `s.readRecord` still returns the valid record. The planned proof returns `Duplicate` and the door answers 409 `already exists`; it never reaches `PendingForHost` and the required R1/503 answer. The pending-retirement witness fails for this ordinary crash point.
+
+**Concrete fix:** After ownership, check pending work before returning the duplicate result, using the non-locking store accessor. Preserve the completed-create duplicate response when no work is pending. Exercise pending deletion before N1, after N1 and after N2, then recovery and successful restore; retain the completed-restore lost-response test.
+
+**Invariant:** An owned hostname undergoing retirement gets the pending response until that retirement settles; a completed existing create gets the ordinary duplicate response.
+
+### 2. The new liveness assertion requires success after history invalidation
+
+**Task:** 7. **Fault family:** simulation eligibility oracle; related to R1 P2-8, but this is a new contradictory assertion introduced by its fix, rather than the earlier missing success assertion.
+
+**Problem and evidence:** The new assertion requires 201 whenever the restoring triple is the sole data writer, its plain create occurred after activation with lifetimes on, and normal deletion has finished with no pending work (`docs/superpowers/plans/2026-11-08-instance-restore-658.md:178`). It does not require the history to be active at the restore. The generator explicitly includes invalidation through the spec's action set (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:71`). The approved rule requires R2 when the current mode is not active (:60), and Task 5 implements that rule (plan:138, :140). Invalidation changes the mode without changing the hostname's writer, origin or completed retirement (`internal/console/hostsused.go:462`, :468).
+
+**Failure scenario:** Activate → plain create with lifetimes on → write P's data → normal delete → invalidate history → restore as P. Every stated liveness precondition holds. A correct implementation returns R2, but Task 7 demands 201. The simulation therefore reports correct refusal as a regression whenever it generates this trace.
+
+**Concrete fix:** Make success conditional on an independently tracked eligible current state, including active mode and the remaining admission conditions. Keep provenance safety unconditional. Add the trace above as a deterministic refusal witness, followed by reactivation and an eligible success. Keep managed enrollment as a success case so the oracle still detects the rejected timestamp dependency. Do not derive expected success from `restoreProof` itself.
+
+**Invariant:** The simulation must require success for eligible states and allow the spec's required refusals for ineligible states.
+
+## P2
+
+### 3. Skipping the entire region block removes checks as well as region selection
+
+**Tasks:** 5 and 6. **Fault family:** authorization of the effective shape and region; repeats R1 P2-5, retained at P2.
+
+**Problem and evidence:** Task 6 says to skip `apiinstances.go:1796-1933` entirely and consult no fleet placement (`docs/superpowers/plans/2026-11-08-instance-restore-658.md:164`). That range includes the app-placement read (`internal/console/apiinstances.go:1796`), replica validation (:1904-1907), and the manifest region allow-list check (:1923-1929). Keeping `checkPlacement` does not preserve those checks: that closure checks capacity and available infrastructure, and skips the home region (:1953-1954). The spec preserves the region's other create checks (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:36`, :39).
+
+The plan also requires `TestRestoreIgnoresPlacement` to observe a newly fleet-placed app and return R7 (plan:162). With the placement read skipped, the record retains the restored home region and no fleet label; neither the early `Shape: nil` call nor the final record reveals that app policy. `appPlacement` reads that policy separately from the record (`internal/console/fleets.go:723-737`).
+
+**Failure scenarios:** A manifest now excludes home from `Regions`, but restoring a formerly home instance bypasses the ordinary allow-list refusal. In the plan's fleet-placement fixture, the required R7 cannot be produced from the constructed record alone. If that fixture uses the real placement mutation door, it fails earlier because changing placement under active history is already refused (`internal/console/fleets.go:816-828`); the plan must state how it installs the intended policy state.
+
+**Concrete fix:** Separate choosing a region from validating the chosen region. Pin restore to the stored home region, retain the applicable ordinary validation, and read fleet policy solely to refuse unsupported placement, without using it to select the destination. Name the fixture setup and add a home-excluded-by-manifest witness. Also make the final proof explicitly unconditional on record kind and test the rejected shape matrix through the real door: the existing mark block runs only for `rec.DataKind()` (`internal/console/lifetimes_create.go:138`), which excludes static and service (`internal/provision/hostsused.go:112-117`). The plan's nil early shape must not leave those requests without a deciding shape check.
+
+**Invariant:** A restore fixes its destination without discarding create policy, and its proof sees every fact needed to reject an unsupported effective shape.
+
+### 4. CI still does not run the simulation niced
+
+**Task:** 7 and global constraints. **Fault family:** simulation execution budget; repeats the outstanding CI portion of R1 P2-8, retained at P2.
+
+**Problem and evidence:** The spec requires the guard to run niced and bounded in CI (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:71`). The revision explicitly limits niceness to local runs (`docs/superpowers/plans/2026-11-08-instance-restore-658.md:22`, :179). CI still starts ordinary `go test` (`.amadan/test-gate.sh:225`), and no task supplies a CI launcher or test subprocess with reduced priority. A seed/time bound does not set scheduling priority.
+
+**Failure scenario:** The full simulation runs at the CI process's normal priority even when it meets the 60-second bound. This leaves an explicit delivery condition unimplemented.
+
+**Concrete fix:** Specify a CI-compatible way to execute this simulation at reduced priority, with its exit status preserved and without silently changing the rest of the test shard. Include any required file in the task's scope and verify the effective priority in that execution path.
+
+**Invariant:** The guard obeys both parts of its shared-machine execution contract: bounded work and reduced scheduling priority.
+
+### 5. Newest-retirement ordering has no tie-breaker within one second
+
+**Task:** 2. **Fault family:** deterministic selection of retirement evidence; new finding.
+
+**Problem and evidence:** `NewestRetirement` orders by incarnation and then `created_at` (`docs/superpowers/plans/2026-11-08-instance-restore-658.md:72`). Existing retirement inserts timestamp rows with `time.Now().Unix()`, which has one-second resolution (`internal/console/lifetimes_store.go:219-220`). Multiple retirement attempts can occur at the same incarnation: an intervening record update leaves a refused retirement and the record and slot live (`internal/console/lifetimes_retire_test.go:406-428`), allowing a later delete attempt. The spec requires the newest retirement, without falling back to an older one (`docs/superpowers/specs/2026-11-07-instance-restore-658-design.md:67`).
+
+**Failure scenario:** A retirement is refused after an update races its captured ETag. The next delete succeeds within the same second. Both rows have the same incarnation and `created_at`, but only the second is restorable. The specified ordering cannot distinguish them and can select the older refusal, returning R8 for an eligible restore.
+
+**Concrete fix:** Add a deterministic insertion-order tie-breaker, such as descending `rowid` after incarnation and timestamp, consistent with the existing table's insertion ordering. Test two rows with the same incarnation and timestamp and opposite restorable values; the later row must win in both insertion orders.
+
+**Invariant:** Restore eligibility uses the latest retirement attempt at the slot's incarnation, never an arbitrary earlier row tied on timestamp.
+
+## P3
+
+None.
+
+The non-locking proof, complete staging check, captured-body guard and atomic cleanup conversion resolve their earlier findings. Task 7's fixed Q/P trace now has a usable timestamp mechanism and discriminates the rejected timestamp rule; Task 6 names the legacy-lineage and managed-enrollment delivery traces. Those fixes do not resolve the findings above.
+
+The response-precedence, effective-shape and simulation families recur across plan rounds 1 and 2. Under stopping rule 2, the controller should stop another patch-by-patch cycle and present the prescribed choice. The recommended option is to state and enforce the admission invariant in one place, with a precedence table and an independent simulation model covering the concrete traces above. This review does not authorize a third fix cycle or reopen the approved spec.
+
+**NOT READY**