Skip to content

fix(native): name only recoveries the runtime accepts after a lost VM (HACK-2731) - #1279

Open
roodboi wants to merge 5 commits into
nextfrom
claude-lead/vm-loss-followups
Open

roodboi wants to merge 5 commits into
nextfrom
claude-lead/vm-loss-followups

Conversation

@roodboi

@roodboi roodboi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the low follow-ups in HACK-2731 (from the #1273 and #1274 reviews). After a lost VM, the CLI now names only recovery commands the runtime accepts.

What changes

Item Outcome
1. Storage barrier misreports its cause Fixed. storage_barrier_outcome (packages/runtime-core/src/provider/graph/mod.rs) reports graph_cleanup_uncertain only for a flush that did not confirm: the exec's deadline or a lost reply (agent_protocol_uncertain), or a guest command that did not exit 0 (guest_command_failed). guest_identity_mismatch, runtime_changed and every other error keep their own code and message.
2. Lost restore or preparing run with unsettled host dependency services Already fixed on next by #1273. nativeCrossBootRecoverable admits a lost-start phase only with cross_boot_start, which the runtime sets only for a settled relay and dependency startup with no cleanup marker (dead_owner_cleanup::unconfirmed_start). The unsettled row of the existing nativeLostStartRetirable test covers it. The gap that was left is the live phases, which is item 4.
3. nativeLostStartRetirable parses the reply loosely Fixed. The parser moved out of selectForegroundOwner into parseNativeForegroundOwner (src/backends/native-cross-boot-recovery.ts). The down and the lost-start advice now share it, so version, run, owner, receipt digest and live_owner_recovery digest are checked the same way in both.
4. No-port live run with an unsettled relay Fixed. graph foreground-owner now reports cross_boot_relay: the run holds a bridge slot (its routes prove the dead owner), or its relay startup settled (bridges::cleanup::relay_owner_provable). A live phase counts as recoverable only with it, so hack down --recover no longer starts the pool for such a run. A ready-stage loss, including a restart lost in its preflight, asks the runtime first and names no command when the relay is unprovable. If the field is missing (an older runtime), the result is true, as before. If the read fails at the ready stage, the existing advice stays.
5. hack up / down --recover loop after the pool idles Fixed with the first option in the ticket. When a retained start finds containers that a lost VM brought back, it now records a marker for that exact run beside its run mapping (recordNativeLostRemoval). graph foreground-owner also reports the runtime's own marker of a repair whose barrier never confirmed (lost_removal_pending). When the pool is stopped, hack down --recover on that stopped run starts the pool, and the repair then runs as before. A verified stop clears the marker. A plain hack down does not start the pool for it. The marker is advisory: the runtime still revalidates the receipt and each container, and a stale marker costs one pool start. I preferred this to keeping the pool from going idle: that would hold a VM up for as long as the user takes, and would still loop if the pool stopped for any other reason.
flowchart TD
  L[VM lost under hack up] --> S{graph foreground-owner}
  S -->|live phase, slot or settled relay| D[hack down --recover, then hack up]
  S -->|live phase, no port, unsettled relay| K[No command: keep the native home]
  S -->|lost start, cross_boot_start| D
  S -->|lost start, not admitted| K
  R[hack up finds containers brought back] --> M[marker for this run]
  M --> P{pool stopped?}
  P -->|yes, down --recover| U[start the pool] --> X[repair, verify, clear marker]
  P -->|no| X
Loading

Updated state chart (Pele 1.9.0, label check PASS ... 0 findings): docs/diagrams/foreground-loss-recovery.png

Model

tests/models/tla/foreground-loss-recovery: adds settled (relay startup settled when the VM died), Unsettled and LiveRelayAdvice. No-route proofs and lost starts now need a settled relay. positive holds across 596 states. The new live-relay negative control is #1273's message rule, which named hack down --recover once ready for a run with no port and an unsettled relay. It fails NoRefusedAdvice with exactly that witness. The other controls keep Unsettled = FALSE, so their witnesses do not change.

Validation

  • Tests that fail on the old behaviour (checked by mutating each fix back):
    • Item 1: only_an_unconfirmed_barrier_reports_the_barrier_refusal.
    • Item 3: five foreign or malformed reply rows (another version, another owner, a non-string pending recovery, no receipt digest, a foreign ready selection).
    • Item 4: two down refusal rows, the started, relay unprovable row and the ready-stage relay unprovable row.
    • Item 5: two down --recover starts a stopped pool for an owed lost-removal repair rows.
    • New Rust tests: a_live_run_relay_owner_is_provable_by_its_bridge_slot_or_a_settled_relay and foreground_owner_reports_an_unconfirmed_lost_removal_repair.
  • Mac: bun install --frozen-lockfile; focused bun tests (native-project-start, native-project-down, native-project-retained-startup, native-start-pool-watch: 428 pass, plus the new rows); root bun run typecheck; bun run check (the 111 warnings match next); bun run test:models; bun run docs:check; bun run privacy:check; gitleaks; cargo +1.97.1 fmt --check; clippy -D warnings with default features and with --all-features; runtime-core provider::graph tests under the native-bench lock (723 pass).
  • Linux (the repo's toolchain image, --init, scratch clone at e4dedc2c):
    • cargo fmt --check passes, and clippy -D warnings passes with default features and with --all-features.
    • test-runtime-core.sh passes with default features.
    • bun run test:models passes (live-relay verified).
    • test-runtime-core.sh --all-features passes every target except one lib test, hostname_authority::managed::tests::serving_loop_exits_soon_after_its_owner_fifo_closes ("kept serving after its owner's pipe closed: Timeout"). That test fails the same way on the base 682a02964f, passes alone 5 times out of 5, and this PR does not touch that module. It is a timing failure under load that predates this PR.
  • No VM, local Docker or full-suite run.

Mac rows worth running

  • A no-port project with a host dependency service: kill the provider while the dependency startup is still Prepared, then after ready. Expect no hack down --recover advice, and the down does not start the pool.
  • The item 5 loop: provider killed seconds after hack down on a pre-HACK-2719 receipt, then hack up (brought-back containers refusal). Let the pool idle-stop, then hack down --recover. Expect the pool to start, the repair, the note, then hack up succeeds.

🤖 Generated with Claude Code


See it in action
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

… (HACK-2731)

Low follow-ups from the #1273 and #1274 reviews:

- The storage barrier reports `graph_cleanup_uncertain` only for a flush
  that did not confirm (deadline, lost reply or a failed guest command).
  `guest_identity_mismatch`, `runtime_changed` and every other error keep
  their own code.
- `graph foreground-owner` reports `cross_boot_relay`: whether the
  cross-boot recovery can prove the dead relay owner (a bridge slot, or a
  settled relay startup). A live run with no published port and an
  unsettled relay is no longer advised `hack down --recover`, and the down
  no longer starts the pool for it; the ready-stage message (and a
  restart's preflight loss) asks the runtime first.
- A lost start's advice parses the reply with the down's own parser
  (`parseNativeForegroundOwner`), so version, owner and digest checks
  cannot drift apart.
- `hack down --recover` starts a stopped pool for a stopped run whose
  lost-removal repair is owed: the refused `hack up` leaves a marker beside
  the run mapping, and the runtime reports an unconfirmed repair
  (`lost_removal_pending`). A verified stop clears the marker. This ends
  the `hack up` / `down --recover` loop after the pool goes idle.

The ForegroundLossRecovery model gains relay settlement (`settled`,
`Unsettled`, `LiveRelayAdvice`) and the `live-relay` negative control,
which fails on #1273's message rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hack-docs Ready Ready Preview Nov 26, 2026 11:09pm UTC

Request Review

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@linear-code

linear-code Bot commented Nov 26, 2026

Copy link
Copy Markdown

HACK-2731

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T23:11:18.506694Z 5b6d401 Manual request
🔒 Security Review ✅ Completed 2026-11-26T23:13:20.662876Z 5b6d401 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: e4dedc2c8c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: e4dedc2c8c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

…e relay (HACK-2731)

#1279 review:

- A ready-stage loss now withholds `hack down --recover` only when the
  receipt is live and its relay owner is unprovable
  (`nativeLiveRelayUnprovable`). A VM lost during the owner's own stop
  (`cleanup-intent`, `stopped-data-retained`) or with a pending same-boot
  recovery keeps the down advice it had before, for `hack up` and for a
  restart lost in its preflight.
- `cross_boot_relay` counts a bridge registry as holding the run's slot
  only when the current pool owner wrote it, as its doc says.
- Removing a run mapping removes its lost-removal marker and a temporary
  file an interrupted marker write left beside it.

The ForegroundLossRecovery README says the receipt phase at ready is out
of the model's scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Review round 1 fixes are in 93af4083.

  1. Medium: a ready-stage loss no longer blames the relay whenever the run is not recoverable. The ready stage now withholds the command only when nativeLiveRelayUnprovable holds: the receipt is in a live phase and cross_boot_relay is false (src/backends/native-cross-boot-recovery.ts). In any other phase, the advice is "Run hack down --recover", as before this PR. That covers a VM lost during the owner's own stop (cleanup-intent, stopped-data-retained) and a pending same-boot recovery. A restart lost in its preflight takes the same path.
    • New ready-stage rows: cleanup-intent with a dead-owner hint, cleanup-intent with cross_boot_relay: false, stopped-data-retained, and a pending same-boot recovery.
    • New restart-preflight rows: unprovable relay, provable relay, cleanup-intent, stopped-data-retained. These also check the printed message.
    • Putting the old nativeCrossBootRecoverable(selection) back fails 6 of these rows.
    • The TLA+ model does not represent the receipt phase at ready, so its README now says that case is out of scope and is covered by the unit tests.
  2. Low: registry owner check. run_holds_slot now also requires store.owner to be the current pool owner's token, which the recovery's registry check also requires. The doc says so, and the Rust test has a foreign-owner case.
  3. Low: marker cleanup. removeNativeProjectRun now also removes the lost-removal marker (best effort, so it never refuses the removal). The marker's temporary file is now named after the marker, so clearNativeLostRemoval also removes a leftover from an interrupted write. It leaves other files alone, including other .tmp files in that folder. New test: removing a run mapping removes its lost-removal marker and leftovers.

Gates at 93af4083:

  • Mac:
    • Focused bun tests: 463 pass across native-project-run, -start, -down, -retained-startup and native-start-pool-watch.
    • Root typecheck passes. check passes with 111 warnings, the same as next.
    • privacy:check and gitleaks are clean, and test:models passes.
    • cargo +1.97.1 fmt --check passes, and clippy -D warnings passes with default features and with --all-features.
    • provider::graph tests under the lock: 723 pass.
  • Linux (toolchain image, --init, fresh scratch clone at 93af4083):
    • fmt and both clippy runs pass.
    • test-runtime-core.sh passes with default features.
    • test:models passes (live-relay verified).
    • --all-features (keep going) passes every target except serving_loop_exits_soon_after_its_owner_fifo_closes, the timing test that fails the same way on next (HACK-2743).

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 93af40832c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 93af40832c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Real-VM results at e4dedc2c and 93af4083 (Apple Silicon, pinned SmolVM 1.35.4, fresh isolated homes)

Controls: next 682a0296 (this PR's base); a pre-HACK-2719 next build c62f4350 for row 2.

Verdict: FAIL on the new Ctrl-C row. The VM lost during a Ctrl-C stop at cleanup-intent is advised hack down --recover, but that command refuses. It is the same on next, filed as HACK-2746. Rows 1 (unsettled relay), 2, 4 and smoke PASS. Row 3 was not run.

Row Head Observed Result Evidence
1. No-port project whose app has a host dependency (fixed host_pid listener). Provider SIGKILLed while relay_startup.services.app.phase reads prepared (polled from the graph's state.json; seen prepared → released) 93af4083 killed 365 ms into the start, before ready, relay still prepared. Advice: "It was lost before its services were ready, and no hack command can retire a run lost at that point yet. Keep this native home unchanged for inspection…": no down --recover, no command named. A plain hack down refuses runtime_not_running and does not start the pool PASS 20261126-162945-93af4083-p1279-dep2-s0
1. The same, after ready both not reachable here: with a fixed-pid listener the relay is already released before ready. My e4dedc2c kills (one before, one after ready) both landed on a released relay; there the advice names hack down --recover, and the plain down starts the pool, which is correct for a settled relay n/a 20261126-161111-e4dedc2c-p1279-dep-s0
2. A run started on a pre-HACK-2719 binary (next c62f4350, which predates #1273; no next.27 or earlier release was cached), hack down, provider killed 2 s later, then this head's hack up e4dedc2c and 93af4083 up refuses: "…stopped containers that its last hack down had removed are listed again… Nothing was started. Run hack down --recover to remove them again (data kept), then hack up." (web listed as exited). The pool did not stop on its own within 120 s, so I stopped it with runtime down. Then hack down --recover starts the pool and prints "Stopped containers of this run that a lost VM had brought back were removed again; the run's data is kept." After that: hack up ready in 1.6 s, web 200, row kept; a further down/up -d cycle works, so no loop PASS 20261126-160118-e4dedc2c-p1279-old-s0, 20261126-163046-93af4083-p1279-old-s0
3. Barrier error passthrough no way to trigger a non-timeout barrier error (such as a guest identity mismatch) on a real VM from outside; skipped NOT RUN
4. #1273 VM-loss rows: provider killed under a live run (no port), then down --recover and up; plus killed before ready, and the restoring variant both up exits 1 within 0.4 s; down --recover exit 0 in 2.7 to 3.6 s; up ready; data kept; restoring advice names down --recover then up and both work PASS …160532-e4dedc2c-p1253-s, …160651/160755-e4dedc2c-p1253-row2c, …163432-93af4083-p1253-s
New. VM lost during a Ctrl-C stop, receipt at cleanup-intent (foreground up ready, Ctrl-C, provider SIGKILLed 50 ms later) 93af4083 3 of 3, e4dedc2c 1 of 1, next 1 of 1 exit 1 in 0.14 s with "Run hack down --recover to retire this run with its data kept, then hack up to start it again." But hack down --recover → runtime_not_running; hack ps → runtime_not_running; hack up → graph_foreground_owner_exited_unadmitted. runtime status says the pool is recovered-unclean with no live runs; runtime recover leaves it so; down --recover still refuses. Dead end FAIL (HACK-2746) 20261126-164742-93af4083-p1279-ctrlc-s0 (.keep), next 20261126-164656-682a0296-p1279-ctrlc-s0 (.keep)
New. The same at stopped-data-retained (kill 3.1 to 3.6 s after Ctrl-C) both the stop had already finished: foreground exit 130, no lost-VM advice; a plain hack up works (ready 4.0 s, web 200, row kept) no loss case reached 20261126-164005-93af4083-p1279-ctrlc-s0
5. smoke both PASS …160900-e4dedc2c-smoke, …163543-93af4083-smoke

Harness false failures, fixed and rerun: the host-dependency fixture first lacked the share grant and used the python3 shim's pid instead of the listener's. The first "Prepared" detector matched binary files. Two row 2 checks looked for "brought back", but the message says "listed again".

Nothing was merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Merged origin/next (cc8db3a, #1277) as merge commit 0439aa5a, with no conflicts. Both sides survive: docs/guides/native-candidate.md differs from next only by this PR's lines. Gates at the merge: root typecheck, check (111 warnings, as on next), focused tests (477 pass, including #1277's native-interactive-exec and native-project-one-off), cargo +1.97.1 fmt --check, clippy -D warnings with default features and with --all-features, privacy:check and gitleaks.

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0439aa5a45

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/backends/native-start-pool-watch.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0439aa5a45

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

roodboi and others added 2 commits November 26, 2026 17:43
…HACK-2731)

#1279 review (Codex P2): a ready-stage loss the runtime cannot retire (`retirable` false) names no command, but the start's own error (the final inspection's unconfirmed cleanup) kept its "Run hack down --recover" sentence in the `(cause: …)` line. The cause's recovery sentence is now dropped for that stage too, as it already was for a requested loss.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Head 5b6d4014:

Gates at 5b6d4014:

  • Mac:
  • Linux (toolchain image, --init, on the build volume):

@roodboi

roodboi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 5b6d401479

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 5b6d401479

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

roodboi added a commit that referenced this pull request Nov 26, 2026
…ad/ctrl-c-loss-recover

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi roodboi added the ci:mac Run macOS checks for this pull request label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:mac Run macOS checks for this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant