Skip to content

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

Merged
roodboi merged 7 commits into
nextfrom
claude-lead/vm-loss-followups
Nov 27, 2026
Merged

roodboi merged 7 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


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 27, 2026 5:48pm 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-27T16:20:06.797090Z 2aba1fd Manual request
🔒 Security Review ✅ Completed 2026-11-27T16:22:41.810128Z 2aba1fd 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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
roodboi added a commit that referenced this pull request Nov 27, 2026
…ad/ctrl-c-loss-recover

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

roodboi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2aba1fd92b

ℹ️ 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: 2aba1fd92b

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.

Resolved to the tree tested in batch run m3:z497 (lead train sync).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roodboi
roodboi merged commit 986b7e9 into next Nov 27, 2026
9 of 10 checks passed
@roodboi
roodboi deleted the claude-lead/vm-loss-followups branch November 27, 2026 17:48
roodboi added a commit that referenced this pull request Nov 27, 2026
next holds #1279 squashed (986b7e9); its tree equals this branch's #1279 base (2aba1fd) plus #1280, so each conflict resolves to this branch's side.

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

# Conflicts:
#	docs/diagrams/foreground-loss-recovery.png
#	docs/diagrams/foreground-loss-recovery.svg
#	docs/guides/native-candidate.md
#	packages/runtime-core/src/provider/graph/bridges/cleanup.rs
#	packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs
#	packages/runtime-core/src/provider/graph/mod.rs
#	scripts/lib/tla-runtime-models.ts
#	src/backends/native-cross-boot-recovery.ts
#	src/backends/native-project-start.ts
#	tests/models/tla/README.md
#	tests/models/tla/foreground-loss-recovery/ForegroundLossRecovery.tla
#	tests/models/tla/foreground-loss-recovery/code-without-veto.cfg
#	tests/models/tla/foreground-loss-recovery/failed-only.cfg
#	tests/models/tla/foreground-loss-recovery/generic-error.cfg
#	tests/models/tla/foreground-loss-recovery/intent-message.cfg
#	tests/models/tla/foreground-loss-recovery/keep-intent.cfg
#	tests/models/tla/foreground-loss-recovery/keep-leftover.cfg
#	tests/models/tla/foreground-loss-recovery/leak-lock.cfg
#	tests/models/tla/foreground-loss-recovery/live-relay.cfg
#	tests/models/tla/foreground-loss-recovery/negative.cfg
#	tests/models/tla/foreground-loss-recovery/no-cross-boot.cfg
#	tests/models/tla/foreground-loss-recovery/pinned-relay.cfg
#	tests/models/tla/foreground-loss-recovery/positive.cfg
#	tests/models/tla/foreground-loss-recovery/restart-recovers.cfg
#	tests/models/tla/foreground-loss-recovery/transitional-veto.cfg
#	tests/models/tla/foreground-loss-recovery/withhold-preparing.cfg
#	tests/models/tla/foreground-loss-recovery/withhold-requested.cfg
#	tests/native-project-down.test.ts
#	tests/native-project-start.test.ts
roodboi added a commit that referenced this pull request Nov 27, 2026
…--recover (HACK-2746) (#1290)

Fixes HACK-2746. When the VM is lost during a Ctrl-C stop, `hack down
--recover` now finishes that stop with data kept, and `hack up` then
starts the run.

## The bug

On a real VM, a foreground `hack up` reached ready and was stopped with
Ctrl-C. About 50 ms later, while the receipt read `cleanup-intent`, the
provider was killed. This failed 3 of 3 times on #1279 and 1 of 1 on
`next`:
- The advice named `hack down --recover`, which answered
`runtime_not_running`.
- `hack up` refused with `graph_foreground_owner_exited_unadmitted`.
- `runtime recover` changed nothing.

No command got the run back.

## Cause

In the kept evidence home, the receipt is at `cleanup-intent`. The
owner's enrolled relay cleanup marker is still `pending` for the run's
boot, and its bridge selection (`relay-cleanup-bridges.json`, one route)
is beside it. The run's slots were already released.

The runtime's cross-boot dead-owner recovery already admits exactly this
receipt (`interrupted_enrollment` in `prepare`) once the pool boots
again. But nothing in the host-file selection showed it, so `hack down
--recover` never started the stopped pool.

## Fix

- `graph foreground-owner` reports a new field, `cross_boot_stop`
(`dead_owner_cleanup::interrupted_stop`). It is true when the receipt is
at `cleanup-intent` with all of the following:
- a valid `pending` relay cleanup marker for one of the pool's recorded
boots;
  - the persisted bridge selection;
- a provable dead relay owner, by that selection's routes or by a
settled relay startup.
- `nativeCrossBootRecoverable` admits that receipt, so `hack down
--recover` starts the stopped pool and the runtime finishes the stop.
- The ready-stage advice (`nativeReadyLossRetirable`) names the down for
`cleanup-intent` only with `cross_boot_stop` or a selected dead-owner
recovery. Otherwise it names no command, and with #1279's cause-line
fix, neither does the cause line.
- The retained-start preflight reports such a run as
`graph_foreground_owner_exited`, naming `hack down --recover`, then
`hack up`. `hack up` then recovers it itself, as for a ready run
(HACK-2456).

## Model

`ForegroundLossRecovery.tla` gains a `Stopping` stage (Ctrl-C while
serving) and two rules, `StopRecovery` and `StopAdvice`. `positive`
holds across 752 states. The new `no-cross-boot-stop` negative control
is the runtime and message before this fix, and it fails
`NoRefusedAdvice` at `Stopping`, as the VM did. The README and state
chart are updated:

![Foreground loss recovery state
chart](https://github.com/hack-dance/hack/blob/claude-lead/ctrl-c-loss-recover/docs/diagrams/foreground-loss-recovery.png?raw=1)

## Real VM (at `35bc2f3e`)

Apple Silicon, pinned SmolVM 1.35.4, fresh isolated homes. The scenario:
on a web and database project, a foreground `hack up` reaches ready,
Ctrl-C goes to the process group, and the provider is SIGKILLed about 50
ms later while the receipt reads `cleanup-intent`.

| Row | Observed | Result |
| --- | --- | --- |
| 1. Ctrl-C stop lost at `cleanup-intent`, then `hack down --recover` (3
runs) | The foreground exits 1 in 0.13 to 0.36 s, and the advice names
`hack down --recover`. `down --recover` exits 0 in 2.9, 4.1 and 2.8 s:
it starts the pool, stops the services with data retained, and `ps`
shows `stopped-data-retained`. `hack up` is then ready in 1.6 to 2.5 s,
with the web page served and the database row kept. 3 of 3 | PASS |
| 2. The same, then a plain `hack up` with no `down` | Ready in 7.8 s,
with the "runtime had stopped under this run … recovered with data
retained" note. The page is served, the row is kept, and a clean `down`
follows | PASS |
| 3. The home kept from #1279 at `93af4083`, driven by this binary |
`down --recover` exits 0 in 4.5 s, then `up -d` works with the row kept,
and the cleanup is clean. The old receipt shape recovers | PASS |
| 4a. #1279: a no-port run with an unsettled relay | No command is
named, and a plain `down` does not start the pool. Unchanged | PASS |
| 4b. #1279: brought-back containers from a pre-#1273 run | `down
--recover` starts the pool and removes them, then `up` works. Unchanged
| PASS |
| 5. smoke | | PASS |

The commits after `35bc2f3e` change only message text (the lost-VM cause
line, from #1279), add a test, or merge `next`. The VM rows therefore
still apply to this head.

## Validation

- Tests that fail on the old behaviour:
- Rust:
`a_stop_interrupted_inside_its_enrolled_relay_cleanup_is_a_cross_boot_stop`
and the HACK-2746 case in
`a_remaining_publication_names_its_owner_state_without_effects`.
- TS: the `cleanup-intent` row of `down --recover starts a stopped pool
for a start lost before ready`, the interrupted-stop rows of
`nativeLostStartRetirable`, and the ready-stage and restart-preflight
`cleanup-intent` rows. Removing the TS fix fails 5 of them. `a Ctrl-C
stop lost with its VM names the down in advice and cause only when the
runtime finishes it` checks the advice and the cause line together.
- `git diff origin/next...HEAD` is this change only. `next` holds #1279
as a squash, and the merge resolves to this branch's side.
- Mac:
- Focused bun tests pass, root `typecheck` passes, and `check` passes
with 111 warnings, the same as `next`.
- `cargo +1.97.1 fmt --check` passes, and clippy `-D warnings` passes
with default features and with `--all-features`.
  - `provider::graph` tests under the native-bench lock pass.
  - `test:models`, `privacy:check` and gitleaks pass.
- Linux (the repo's toolchain image, `--init`): fmt, both clippy runs,
`test-runtime-core.sh` with default features and with `--all-features`,
and `test:models` pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- codesmith:footer -->
---
<a
href="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1798395182&installation_model_id=17053&pr_number=1290&ref=codesmith_pr_footer&repository=hack-dance%2Fhack&return_to=https%3A%2F%2Fgithub.com%2Fhack-dance%2Fhack%2Fpull%2F1290&variant=start_proof&signature=91c4275f624fa04f2a52bb42366cf9d00c3f2ea8d60ce92b8dd96d5586e5200b"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-start-proof-v2-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-start-proof-v2-light.svg"><img
alt="Start Proof"
src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-start-proof-v2-dark-3x.png"
width="108" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/hack-dance/codesmith/hack/pr/1290?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

---------

Co-authored-by: Dimitri Kennedy <344842+roodboi@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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