diff --git a/docs/diagrams/foreground-loss-recovery.mmd b/docs/diagrams/foreground-loss-recovery.mmd index 59361a22d..2128aecbb 100644 --- a/docs/diagrams/foreground-loss-recovery.mmd +++ b/docs/diagrams/foreground-loss-recovery.mmd @@ -7,10 +7,12 @@ stateDiagram-v2 Preparing --> Requested : Request Requested --> GraphReady : GraphReady [mapped] GraphReady --> Serving : Serve / retire intent, lock + Serving --> Stopping : Ctrl-C Preparing --> Dead : Die Requested --> Dead : Die GraphReady --> Dead : Die Serving --> Dead : Die + Stopping --> Dead : Die Dead --> Lost : Watch / release lock Dead --> Lost : StartFails / same message state advice <> @@ -34,6 +36,12 @@ stateDiagram-v2 still holds its cleaned intent and its lock. end note + note right of Stopping + The owner's enrolled stop: + a pending relay cleanup + marker and its bridge + selection (cross_boot_stop). + end note note right of Dead The watch and the start's own error race; both print @@ -50,8 +58,9 @@ stateDiagram-v2 note right of Down Starts the pool; retires a lost start (failed-retained - or restoring) or a ready - run, port or none, data kept. + or restoring), a ready run, + port or none, or a stop lost + at cleanup-intent, data kept. Removes containers a lost VM brought back. end note @@ -68,6 +77,7 @@ stateDiagram-v2 classDef idle stroke-width:1.6px class Preparing,Requested,GraphReady wait class Serving live + class Stopping wait class Dead,Lost fail class Down,Up wait class Recovered ok diff --git a/docs/diagrams/foreground-loss-recovery.png b/docs/diagrams/foreground-loss-recovery.png index 3ce7351b5..b9774e7e2 100644 Binary files a/docs/diagrams/foreground-loss-recovery.png and b/docs/diagrams/foreground-loss-recovery.png differ diff --git a/docs/diagrams/foreground-loss-recovery.svg b/docs/diagrams/foreground-loss-recovery.svg index 3b0bb0a25..69619a1f1 100644 --- a/docs/diagrams/foreground-loss-recovery.svg +++ b/docs/diagrams/foreground-loss-recovery.svg @@ -1,4 +1,4 @@ -ForegroundLossRecoveryRequestGraphReady [mapped]Serve / retire intent, lockDieDieDieDieWatch / release lockStartFails / same message[fresh up, Requested][relay unproven][recorded, relay proven][fresh up, Preparing]down --recoverhack upRequestedServingLostUpPreparingGraphReadyDeadInspectDownRecoveredImages, review, restoreselection; nothing requested.A restart holds its lock.Ready and mapped. A restartstill holds its cleanedintent and its lock.The watch and the start'sown error race; both printthe stage message.A fresh up has no recordfor down to retire yet, anda run with no port whoserelay never settled has noowner proof: none named.INV NoNeedlessWithholdingStarts the pool; retires alost start (failed-retainedor restoring) or a readyrun, port or none, data kept.Removes containers a lostVM brought back.INV NoRefusedAdviceEvery named command isaccepted, for up and restart. \ No newline at end of file +]]>ForegroundLossRecoveryRequestGraphReady [mapped]Serve / retire intent, lockCtrl-CDieDieDieDieDieWatch / release lockStartFails / same message[fresh up, Requested][relay unproven][recorded, relay proven][fresh up, Preparing]down --recoverhack upRequestedServingLostUpPreparingGraphReadyStoppingDeadInspectDownRecoveredImages, review, restoreselection; nothing requested.A restart holds its lock.Ready and mapped. A restartstill holds its cleanedintent and its lock.The owner's enrolled stop:a pending relay cleanupmarker and its bridgeselection (cross_boot_stop).The watch and the start'sown error race; both printthe stage message.A fresh up has no recordfor down to retire yet, anda run with no port whoserelay never settled has noowner proof: none named.INV NoNeedlessWithholdingStarts the pool; retires alost start (failed-retainedor restoring), a ready run,port or none, or a stop lostat cleanup-intent, data kept.Removes containers a lostVM brought back.INV NoRefusedAdviceEvery named command isaccepted, for up and restart. \ No newline at end of file diff --git a/docs/guides/native-candidate.md b/docs/guides/native-candidate.md index fe427c173..c1c91776e 100644 --- a/docs/guides/native-candidate.md +++ b/docs/guides/native-candidate.md @@ -2935,6 +2935,16 @@ code 1, and what to run next, which depends on how far the start got: (`relay_owner_refused`). The start asks the runtime once the VM is gone, and for such a run it names no command and says to keep the native home for inspection (HACK-2731); `hack down --recover` does not start the pool for it. +- During its own stop (you pressed Ctrl-C and the VM was lost before the stop + was confirmed, with the receipt at `cleanup-intent`): `hack down --recover`, + then `hack up` (HACK-2746). The stop runs inside the owner's enrolled relay + cleanup, and the runtime finishes it across the boot with data kept, once the + down has started the pool. `graph foreground-owner` reports it as + `cross_boot_stop`; a `hack up` run first names the same down + (`graph_foreground_owner_exited`) and runs it for you as for a ready run. + Earlier versions named the down, which answered `runtime_not_running`, and + `hack up` refused the run. A stop the runtime cannot finish this way names no + command. - Before any service was requested (while it resolved, reviewed, built or pulled images, or selected the restore): for a run with a record (a resumed stopped run, or a restart's old run), the same `hack down --recover`, then diff --git a/packages/runtime-core/src/provider/graph/bridges/cleanup.rs b/packages/runtime-core/src/provider/graph/bridges/cleanup.rs index d63e0cf9f..37b0fb275 100644 --- a/packages/runtime-core/src/provider/graph/bridges/cleanup.rs +++ b/packages/runtime-core/src/provider/graph/bridges/cleanup.rs @@ -419,6 +419,22 @@ pub(crate) fn relay_owner_provable(candidate: &Candidate, owner: &str, receipt: pinned_predecessor_eligible(receipt) || run_holds_slot(candidate, owner, &receipt.run) } +/// Whether the bridge selection an interrupted enrolled cleanup persisted +/// (`relay-cleanup-bridges.json`, for this run and pool owner) names any route +/// of the run, so a cross-boot recovery proves the dead relay owner by them +/// although the cleanup already released the slots (HACK-2746). Presentation +/// only; unreadable or foreign counts as none. +pub(crate) fn interrupted_selection_routes(root: &std::path::Path, owner: &str, run: &str) -> bool { + selection_path(root) + .and_then(|path| state::read_bounded::(&path, 65536)) + .is_ok_and(|selection| { + selection.version == 1 + && selection.owner == owner + && selection.run == run + && !selection.selected.is_empty() + }) +} + fn run_holds_slot(candidate: &Candidate, owner: &str, run: &str) -> bool { state::read_bounded::(&root(candidate).join("state.json"), 65536).is_ok_and(|store| { store.version == 1 diff --git a/packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs b/packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs index 7453db8da..6624cc06d 100644 --- a/packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs +++ b/packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs @@ -93,6 +93,45 @@ pub(super) fn unconfirmed_start(receipt: &Receipt) -> bool { }) } +/// A stop its owner left inside its enrolled relay cleanup, at `cleanup-intent`, +/// when its VM was lost (HACK-2746, real VM: Ctrl-C, then the provider killed while +/// the receipt read `cleanup-intent`). The relay cleanup marker is still `pending` +/// for one of the pool's recorded boots and the bridge selection it persisted is +/// beside it. The cross-boot recovery admits that receipt once the pool boots again +/// (`interrupted_enrollment` in `prepare`), provided it can prove the dead relay +/// owner: by the routes that selection names, or by a settled relay startup. So a +/// caller starts a stopped pool, or names `hack down --recover`, only for one this +/// returns. Selection only, read from host files; the recovery revalidates the dead +/// owner, the ended boot and every inventory. +pub(super) fn interrupted_stop( + candidate: &Candidate, + root: &std::path::Path, + receipt: &Receipt, + owner: &Owner, +) -> bool { + let Some(marker) = receipt + .relay_cleanup + .as_ref() + .filter(|marker| marker.valid() && marker.phase == cleanup_enrollment::Phase::Pending) + else { + return false; + }; + if receipt.phase != "cleanup-intent" || receipt.relay_startup.is_none() { + return false; + } + let mut boots: Vec = owner.guest_boot_id.iter().cloned().collect(); + boots + .extend(crate::provider::boot_history::earlier_boots(candidate, owner).unwrap_or_default()); + let enrolled_boot = boots.iter().any(|boot| { + host_relay::context(&receipt.owner, boot) + .is_ok_and(|context| marker.runtime == context.runtime && marker.boot == context.boot) + }); + enrolled_boot + && exists(&root.join("relay-cleanup-bridges.json")).unwrap_or(false) + && (bridges::cleanup::relay_owner_provable(candidate, &owner.token, receipt) + || bridges::cleanup::interrupted_selection_routes(root, &owner.token, &receipt.run)) +} + fn validate( intent: &Intent, receipt: &Receipt, @@ -3185,4 +3224,73 @@ mod tests { .unwrap(); assert_eq!(pending(&fixture), true); } + + #[test] + fn a_stop_interrupted_inside_its_enrolled_relay_cleanup_is_a_cross_boot_stop() { + // HACK-2746 (real VM, 3 of 3): Ctrl-C, then the provider killed while the + // receipt read `cleanup-intent`. The enrolled cleanup's marker is pending for + // the run's boot, its bridge selection is persisted beside it, and its slots + // were already released. The cross-boot recovery admits that receipt + // (`interrupted_enrollment`), so `graph foreground-owner` reports + // `cross_boot_stop` and `hack up` names `hack down --recover`. + let fixture = super::super::retained_startup::tests::Fixture::new(); + let owner = Owner::load(&fixture.candidate).unwrap(); + let boot = owner.guest_boot_id.clone().unwrap(); + let root = fixture.graph(); + let mut receipt = fixture.receipt(); + receipt.phase = "cleanup-intent".into(); + let stop = |receipt: &Receipt| interrupted_stop(&fixture.candidate, &root, receipt, &owner); + let marker = |boot: &str, phase: &str| { + let context = host_relay::context(&receipt.owner, boot).unwrap(); + serde_json::from_value::(json!({ + "version":1,"runtime":context.runtime,"boot":context.boot,"operation":([3;16]), + "effect":([4;32]),"control_root":"/private/owned","phase":phase + })) + .unwrap() + }; + // Before HACK-2746 nothing reported it: no relay startup or marker. + assert!(!stop(&receipt)); + receipt.relay_startup = Some(serde_json::from_value(json!({"control_only":true,"guest_root":null,"control_root":"/private/owned","control_generation":"a".repeat(32),"artifact":"e".repeat(64),"services":{}})).unwrap()); + receipt.relay_cleanup = Some(marker(&boot, "pending")); + // The persisted selection is required. + assert!(!stop(&receipt)); + let selection = |selected: serde_json::Value| { + json!({"version":1,"owner":owner.token,"boot":boot,"run":receipt.run, + "plan":receipt.plan_id,"capacity":2,"serial":1,"selected":selected}) + }; + state::write( + &root.join("relay-cleanup-bridges.json"), + &selection(json!({})), + ) + .unwrap(); + assert!(stop(&receipt)); + state::write(&root.join("state.json"), &receipt).unwrap(); + assert_eq!( + foreground_owner(&fixture.candidate, &fixture.run).unwrap()["cross_boot_stop"], + true + ); + // A confirmed marker, one of another boot, or another phase is not one. + let mut confirmed = receipt.clone(); + confirmed.relay_cleanup = Some(marker(&boot, "confirmed")); + assert!(!stop(&confirmed)); + let mut foreign = receipt.clone(); + foreign.relay_cleanup = Some(marker("33333333-3333-3333-3333-333333333333", "pending")); + assert!(!stop(&foreign)); + let mut ready = receipt.clone(); + ready.phase = "ready-observed".into(); + assert!(!stop(&ready)); + // Without a settled relay startup, only the persisted routes prove the dead + // relay owner: none, then one. + let mut unsettled = receipt.clone(); + unsettled.relay_startup.as_mut().unwrap().control_only = false; + assert!(!stop(&unsettled)); + state::write( + &root.join("relay-cleanup-bridges.json"), + &selection(json!({"1":{"assignment":{ + "reservation":"r","run":receipt.run,"service":"web","generation":"g", + "container_id":"c","network_id":"n","boot_id":boot,"phase":"reserved"}}})), + ) + .unwrap(); + assert!(stop(&unsettled)); + } } diff --git a/packages/runtime-core/src/provider/graph/mod.rs b/packages/runtime-core/src/provider/graph/mod.rs index 5948f3729..d596c19ed 100644 --- a/packages/runtime-core/src/provider/graph/mod.rs +++ b/packages/runtime-core/src/provider/graph/mod.rs @@ -2127,6 +2127,11 @@ pub fn foreground_owner(candidate: &Candidate, run: &str) -> Result CandidateError { "graph_foreground_owner_exited", "The previous foreground owner of this run exited while its services were running and did not retire its publication. Run hack down --recover to stop the orphaned services with data retained, then hack up.", ), + // HACK-2746: the owner died during its own stop with its VM, inside its + // enrolled relay cleanup. Its services may still be listed; the same + // cross-boot recovery as for a ready run finishes that stop. + Ok(PublishedOwner::Exited) if exited_interrupted_stop(candidate, run) => error( + "graph_foreground_owner_exited", + "The previous foreground owner of this run exited during its own stop, before that stop was confirmed, and did not retire its publication. Run hack down --recover to finish that stop with data retained, then hack up.", + ), Ok(PublishedOwner::Exited) if exited_unadmitted_retained(candidate, run) => error( "graph_foreground_owner_exited_unadmitted", "The previous foreground owner of this run exited before its restore was admitted and did not retire its publication. Data is retained. Run hack down --recover to retire that attempt, then hack up.", @@ -72,6 +79,20 @@ fn exited_unadmitted_retained(candidate: &Candidate, run: &str) -> bool { .is_some_and(|(receipt, _)| receipt.phase == "stopped-data-retained") } +/// A stop interrupted inside its enrolled relay cleanup that the cross-boot +/// dead-owner recovery finishes (`dead_owner_cleanup::interrupted_stop`). +/// Presentation only, as above. +fn exited_interrupted_stop(candidate: &Candidate, run: &str) -> bool { + Owner::load(candidate).ok().is_some_and(|owner| { + directory(candidate, run) + .ok() + .and_then(|root| load_at(root, run, &owner.token).ok()) + .is_some_and(|(receipt, root)| { + super::dead_owner_cleanup::interrupted_stop(candidate, &root, &receipt, &owner) + }) + }) +} + /// A start the cross-boot dead-owner recovery admits (`failed-retained`, /// `preparing` or `restoring`, with a settled relay startup). Presentation only, /// as above. @@ -935,6 +956,45 @@ pub(in crate::provider::graph) mod tests { assert_eq!(error.code, "graph_foreground_owner_exited"); assert!(error.message.contains("hack down --recover")); assert_eq!(state(&fixture), before); + // HACK-2746 (real VM): an owner whose VM was lost during its own stop, inside + // its enrolled relay cleanup, has the code of an exited ready owner, so + // `hack up` and its message name `hack down --recover`, then `hack up`. + // Before, it named no command ("no supported command can prove ..."). + let fixture = Fixture::new(); + let owner = Owner::load(&fixture.candidate).unwrap(); + let mut receipt = fixture.receipt(); + receipt.phase = "cleanup-intent".into(); + receipt.relay_startup = Some( + serde_json::from_value(json!({"control_only":true,"guest_root":null, + "control_root":"/private/owned","artifact":"e".repeat(64),"services":{}})) + .unwrap(), + ); + let context = super::super::host_relay::context( + &receipt.owner, + owner.guest_boot_id.as_deref().unwrap(), + ) + .unwrap(); + receipt.relay_cleanup = Some( + serde_json::from_value(json!({ + "version":1,"runtime":context.runtime,"boot":context.boot,"operation":([3;16]), + "effect":([4;32]),"control_root":"/private/owned","phase":"pending" + })) + .unwrap(), + ); + state::write(&fixture.graph().join("state.json"), &receipt).unwrap(); + state::write( + &fixture.graph().join("relay-cleanup-bridges.json"), + &json!({"version":1}), + ) + .unwrap(); + foreground::transport::fixture_exited_publication(&fixture.candidate, &fixture.run); + let before = state(&fixture); + let error = preflight(&fixture.candidate, &fixture.run).unwrap_err(); + assert_eq!(error.code, "graph_foreground_owner_exited"); + assert!(error.message.contains("during its own stop")); + assert!(error.message.contains("hack down --recover")); + assert!(error.message.contains("then hack up")); + assert_eq!(state(&fixture), before); } #[test] diff --git a/scripts/lib/tla-runtime-models.ts b/scripts/lib/tla-runtime-models.ts index f912bccfc..3d4b9468a 100644 --- a/scripts/lib/tla-runtime-models.ts +++ b/scripts/lib/tla-runtime-models.ts @@ -3986,10 +3986,12 @@ const contracts: readonly ModelContract[] = [ // (#1253's message on the fixed runtime) restore one rule of the runtime or // message before the VM-loss recovery fix. live-relay (HACK-2731) is // #1273's message once ready, which ignored an unsettled relay startup. + // no-cross-boot-stop (HACK-2746) is the runtime and message before a stop + // interrupted at `cleanup-intent` was finished across the boot. // restart-recovers is the reachability witness of a recovered restart. name: "foreground-loss-recovery", module: "ForegroundLossRecovery", - states: 596, + states: 752, invariant: "NoRefusedAdvice", fields: ['outcome = "refused"', 'lostAt = "Preparing"'], alternativeWitnesses: [['outcome = "refused"', 'lostAt = "Requested"']], @@ -4110,6 +4112,20 @@ const contracts: readonly ModelContract[] = [ 'lostAt = "GraphReady"', ], }, + { + // HACK-2746 (real VM, 3 of 3): Ctrl-C, then the VM lost while the + // receipt read `cleanup-intent`. The message named + // `hack down --recover`, which kept `runtime_not_running`, and + // `hack up` refused: no command got the run back. + name: "no-cross-boot-stop", + negative: true, + invariant: "NoRefusedAdvice", + fields: [ + 'outcome = "refused"', + 'msg = "downUp"', + 'lostAt = "Stopping"', + ], + }, { // HACK-2714 (real VM, row 2): no cross-boot retirement of a start lost // before ready, so the down keeps `runtime_not_running`. diff --git a/src/backends/native-cross-boot-recovery.ts b/src/backends/native-cross-boot-recovery.ts index a57a813cd..d04dcf170 100644 --- a/src/backends/native-cross-boot-recovery.ts +++ b/src/backends/native-cross-boot-recovery.ts @@ -38,20 +38,32 @@ export const NATIVE_CROSS_BOOT_START_PHASES: ReadonlySet = new Set([ "restoring", ]); +/** + * The phase of a stop its owner left inside its enrolled relay cleanup when + * its VM was lost (HACK-2746: Ctrl-C, then the provider killed). The runtime's + * cross-boot recovery finishes it once the pool boots again, when + * `graph foreground-owner` reports `cross_boot_stop` (a pending relay cleanup + * marker of the run's boot, its persisted bridge selection, and a provable + * relay owner). + */ +export const NATIVE_CROSS_BOOT_STOP_PHASE = "cleanup-intent"; + /** * Whether the cross-boot recovery admits a receipt as `graph foreground-owner` * reported it: a live phase whose dead relay owner the runtime can prove * (`cross_boot_relay`: the run holds a bridge slot, or its relay startup * settled; a run with no published port and an unsettled relay startup is - * refused with `relay_owner_refused`, HACK-2731), or a lost start the runtime - * itself admits. A pending same-boot recovery (`live_owner_recovery`) resumes - * only in its own boot, so it is never one. Whether the owner exited is the - * caller's check. + * refused with `relay_owner_refused`, HACK-2731), a lost start the runtime + * itself admits, or a stop interrupted inside its enrolled relay cleanup + * (`cross_boot_stop`, HACK-2746). A pending same-boot recovery + * (`live_owner_recovery`) resumes only in its own boot, so it is never one. + * Whether the owner exited is the caller's check. */ export function nativeCrossBootRecoverable(selection: { readonly phase: string; readonly crossBootStart: boolean; readonly crossBootRelay: boolean; + readonly crossBootStop: boolean; readonly liveOwnerRecovery: string | null; }): boolean { return ( @@ -59,10 +71,34 @@ export function nativeCrossBootRecoverable(selection: { ((NATIVE_RECOVERABLE_LIVE_PHASES.has(selection.phase) && selection.crossBootRelay) || (NATIVE_CROSS_BOOT_START_PHASES.has(selection.phase) && - selection.crossBootStart)) + selection.crossBootStart) || + (selection.phase === NATIVE_CROSS_BOOT_STOP_PHASE && + selection.crossBootStop)) ); } +/** + * Whether a run lost once ready is retired by `hack down --recover`, as the + * selection read once its VM was lost shows (HACK-2731, HACK-2746). A live + * receipt is, unless the runtime cannot prove its relay owner + * (`nativeLiveRelayUnprovable`). A stop its owner left at `cleanup-intent` + * (Ctrl-C, then the VM lost) is only with `cross_boot_stop`, or once a + * dead-owner recovery of it is selected; the runtime refuses any other one. + * Any other phase (`stopped-data-retained` after a completed stop, a pending + * same-boot recovery) keeps the down advice, whose own paths handle it. + */ +export function nativeReadyLossRetirable( + selection: Pick< + NativeForegroundOwnerSelection, + "phase" | "crossBootRelay" | "crossBootStop" | "deadOwnerRecovery" + > +): boolean { + if (selection.phase === NATIVE_CROSS_BOOT_STOP_PHASE) { + return selection.crossBootStop || selection.deadOwnerRecovery !== null; + } + return !nativeLiveRelayUnprovable(selection); +} + /** * Whether the cross-boot recovery refuses a live receipt only because it cannot * prove the dead relay owner (`cross_boot_relay` false: no published port and @@ -109,6 +145,12 @@ export type NativeForegroundOwnerSelection = { * from an older runtime, which did not report it: true, as before. */ readonly crossBootRelay: boolean; + /** + * That recovery finishes a stop its owner left inside its enrolled relay + * cleanup (`cross_boot_stop`, HACK-2746). Absent from an older runtime, + * which never finished one: false. + */ + readonly crossBootStop: boolean; /** * A lost-removal repair whose storage barrier has not confirmed * (`lost_removal_pending`, HACK-2719), read from its host marker. Absent @@ -133,6 +175,7 @@ export function parseNativeForegroundOwner( !optionalBoolean(value.failed_start_recoverable) || !optionalBoolean(value.cross_boot_start) || !optionalBoolean(value.cross_boot_relay) || + !optionalBoolean(value.cross_boot_stop) || !optionalBoolean(value.lost_removal_pending) || value.run !== run.run || value.owner !== run.owner || @@ -174,6 +217,7 @@ export function parseNativeForegroundOwner( failedStartRecoverable: value.failed_start_recoverable === true, crossBootStart: value.cross_boot_start === true, crossBootRelay: value.cross_boot_relay !== false, + crossBootStop: value.cross_boot_stop === true, lostRemovalPending: value.lost_removal_pending === true, receiptSha256: value.receipt_sha256, foreground: diff --git a/src/backends/native-project-down.ts b/src/backends/native-project-down.ts index cc97e190b..9e026eb70 100644 --- a/src/backends/native-project-down.ts +++ b/src/backends/native-project-down.ts @@ -736,9 +736,10 @@ export const NATIVE_RESTART_INTENT_UNREADABLE_NOTE = * boot can still recover. Starting the pool begins a new boot, so only the * cross-boot dead-owner recovery applies: a ready run, a start lost before it * was ready (`failed-retained` after the owner's own unwind, or `preparing` or - * `restoring` without one; HACK-2714), or an interrupted dead-owner recovery - * resuming by its own - * selection. The runtime admits a lost start only with a settled relay startup + * `restoring` without one; HACK-2714), a stop its owner left at `cleanup-intent` + * inside its enrolled relay cleanup when the VM was lost (Ctrl-C, then the + * provider killed; `crossBootStop`, HACK-2746), or an interrupted dead-owner + * recovery resuming by its own selection. The runtime admits a lost start only with a settled relay startup * and no cleanup marker (`crossBootStart`, read from the receipt before the pool * is started), and revalidates the dead owner and the ended boot. The * same-boot recoveries (`recover-live-owner`, which an interrupted live-owner diff --git a/src/backends/native-project-start.ts b/src/backends/native-project-start.ts index 5536adc86..c415995a2 100644 --- a/src/backends/native-project-start.ts +++ b/src/backends/native-project-start.ts @@ -50,7 +50,7 @@ import { adaptNativeAwsEnvironment } from "./native-aws-environment.ts"; import { scheduleNativeAwsExpiryWarnings } from "./native-aws-expiry.ts"; import { nativeCrossBootRecoverable, - nativeLiveRelayUnprovable, + nativeReadyLossRetirable, parseNativeForegroundOwner, } from "./native-cross-boot-recovery.ts"; import type { NativeDependencyOwnerResolver } from "./native-dependency-owners.ts"; @@ -5316,12 +5316,12 @@ async function lostVmFailure(opts: { * with `cross_boot_start` (settled relay and host dependency startup, no * cleanup marker). No run, or a failed or foreign selection, leaves it not * retirable, so no refused command is named (#1273 review). - * - A ready run: retirable unless the selection shows a live receipt whose - * relay owner the runtime cannot prove (`nativeLiveRelayUnprovable`: - * `cross_boot_relay` false, no published port and an unsettled host relay - * startup, HACK-2731). Any other phase (a VM lost during the owner's own - * stop leaves `cleanup-intent` or `stopped-data-retained`), an unknown run - * or a failed read keeps the down advice it always had (#1279 review). + * - A ready run: as `nativeReadyLossRetirable` reads the selection. A live + * receipt is retirable unless its relay owner is unprovable (HACK-2731). A + * stop the owner left at `cleanup-intent` (Ctrl-C, then the VM lost) is + * only when the runtime finishes it across the boot (`cross_boot_stop`, + * HACK-2746). Any other phase, an unknown run or a failed read keeps the + * down advice it always had (#1279 review). * * Any other stage is returned as it is. */ @@ -5362,7 +5362,7 @@ export async function nativeLostStartRetirable(opts: { if (opts.loss.stage === "ready") { return selection === undefined ? opts.loss - : { ...opts.loss, retirable: !nativeLiveRelayUnprovable(selection) }; + : { ...opts.loss, retirable: nativeReadyLossRetirable(selection) }; } return { ...opts.loss, diff --git a/tests/models/tla/README.md b/tests/models/tla/README.md index 4c68c2e30..4d9e4a62d 100644 --- a/tests/models/tla/README.md +++ b/tests/models/tla/README.md @@ -830,12 +830,14 @@ exit (`RouteProof = "exit"`, HACK-2711), which needs a settled relay startup `Unsettled` lets a relay startup be left unsettled when the VM dies after services were requested, and `LiveRelayAdvice` makes the message once ready check it, as `graph foreground-owner`'s `cross_boot_relay` lets the CLI do. -Out of scope: once ready, the model's receipt is always the ready one. A VM lost -during the owner's own stop (a Ctrl-C), with the receipt at `cleanup-intent` or -`stopped-data-retained`, is not modelled. The CLI withholds the command there -only for a live receipt whose relay is unprovable (`nativeLiveRelayUnprovable`); -any other phase keeps the down advice, and the unit tests cover those phases -(#1279 review). +`Stopping` (HACK-2746) is a Ctrl-C while serving: the owner's own stop runs +inside its enrolled relay cleanup and the receipt reads `cleanup-intent`. With +`StopRecovery = "cross-boot"` the runtime finishes that stop across the boot +when its persisted routes or a settled relay startup prove the dead relay owner +(`cross_boot_stop`), and `hack down --recover` starts the stopped pool for it; +with `StopAdvice` the message names the down only then. Out of scope: a stop +whose owner finished it (`stopped-data-retained`) ends with exit 130 and no +loss advice, and is not modelled. It refuses brought-back containers it does not remove. `hack up` refuses a pending restart and an unconfirmed cleanup; `hack restart` refuses while its lock is held and a stopped run with @@ -847,7 +849,7 @@ nothing pending. | Control | Result | | --- | --- | -| `positive` | `NoRefusedAdvice`, `NoNeedlessWithholding`, `NoFalseLoss` and `NoMissedLoss` hold across 596 reachable states, with and without a published port, with a relay startup settled or not when the VM dies, whether a lost start's owner unwound or not, whichever of the watch and the start error ends the start, whether the record still says `running` or is stuck mid-stop when the VM dies, and when an ordinary failure on a live VM ends it. A recorded run lost after its services were requested is told `hack down --recover`, then `hack up`, when its relay startup settled; a run lost once ready is told the same unless it publishes no port and its relay startup had not settled (HACK-2731), where it is told no command. | +| `positive` | `NoRefusedAdvice`, `NoNeedlessWithholding`, `NoFalseLoss` and `NoMissedLoss` hold across 752 reachable states, with and without a published port, through a Ctrl-C stop lost at `cleanup-intent`, with a relay startup settled or not when the VM dies, whether a lost start's owner unwound or not, whichever of the watch and the start error ends the start, whether the record still says `running` or is stuck mid-stop when the VM dies, and when an ordinary failure on a live VM ends it. A recorded run lost after its services were requested is told `hack down --recover`, then `hack up`, when its relay startup settled; a run lost once ready is told the same unless it publishes no port and its relay startup had not settled (HACK-2731), where it is told no command. | | `negative` | PR #1253 at `cd0ebff10`: the message names `hack restart` while an intent is pending and `hack down --recover` otherwise, at every stage; the lost start leaves the restart lock held; `hack down --recover` keeps the intent and the brought-back containers; a start error keeps its own text. `NoRefusedAdvice` fails. | | `keep-intent` | Only `hack down --recover` keeps the cleaned intent: a lost restart is sent to `hack up`, which refuses the pending restart. | | `leak-lock` | Only the lock stays held after the watch's exit: `hack down --recover` cannot retire the intent under it, and `hack up` refuses. | @@ -857,6 +859,7 @@ nothing pending. | `keep-leftover` | Real-VM row 8 before HACK-2719: no storage barrier, and `hack down --recover` does not remove the brought-back containers, so it cannot confirm the cleanup, and the named sequence stops there. | | `pinned-relay` | HACK-2711 (the runtime before this fix): a run with no published port proves its dead owner's relay only by a published endpoint, which the owner's unwind removed. `hack down --recover` refuses (`relay_owner_refused`) once the run was requested: `NoRefusedAdvice` fails. | | `live-relay` | #1273's message (HACK-2731): it checks relay settlement only for a start lost before ready. A run lost once ready with no published port and an unsettled relay startup is told `hack down --recover`, which the runtime refuses (`relay_owner_refused`: its no-route proof needs a settled relay): `NoRefusedAdvice` fails. | +| `no-cross-boot-stop` | HACK-2746 (real VM, 3 of 3): before the cross-boot recovery finished a stop interrupted at `cleanup-intent` (Ctrl-C, then the VM lost), the message once ready named `hack down --recover`, which kept `runtime_not_running`, and `hack up` refused. `NoRefusedAdvice` fails at `Stopping`. | | `no-cross-boot` | HACK-2714 (the runtime before this fix): no cross-boot retirement of a start lost before ready, so a recorded run lost at `Requested` and told down, then up, is refused (`runtime_not_running`): `NoRefusedAdvice` fails. | | `failed-only` | `01ab67fa` (review of #1273): the runtime admits only a `failed-retained` lost start. An owner that died mid-restore without its unwind leaves `restoring`, and the `hack down --recover` the message names is refused: `NoRefusedAdvice` fails. | | `withhold-requested` | PR #1253's message on the fixed runtime: a recorded run lost at `Requested` is told no command, though `hack down --recover` and `hack up` now work: `NoNeedlessWithholding` fails. | @@ -870,6 +873,7 @@ nothing pending. | `Request` | `graph.onRequested` where `servicesRequested` is set, just before the serve request. | | `GraphReady` | `graph.onReady` in the serve `onReady` handler, after `ensureMapping` saved the run mapping (the runtime's `graph_foreground_ready` frame, or the started line of a started return). | | `Serve` | The restart's `onReady` (`removeNativeRestartIntent`, lock release) runs inside the start's readiness work, before `ready` progress sets `serving`. | +| `Stop` | Ctrl-C to the foreground owner: its enrolled cleanup (`host_relay` `cleanup`) writes the pending relay cleanup marker and `relay-cleanup-bridges.json`, releases the run's slots, then the receipt's `cleanup-intent`. `graph foreground-owner` reports `cross_boot_stop` from those files (`dead_owner_cleanup::interrupted_stop`); `nativeCrossBootRecoverable` and `nativeReadyLossRetirable` read it. | | `Die` | The provider VM dies; `leftover` only for a recorded run lost while preparing, and never once `cleanup_owned_fenced` runs `storage_barrier` before the receipt records the removal; `stale` when the record is stuck in a transitional phase that still names the boot. | | `OrdinaryFail` | A start error on a healthy VM: the watched boot is still recorded with a live provider, so `classifyNativeLostProvider` returns nothing and the error keeps its own message, whatever code it carries. | | `Watch` | `onEnded` in `startNativeProject`: `nativeForegroundPoolEndMessage(end, loss)`, then `beforeLostExit` (the restart passes `releaseLock`), then exit 1. | diff --git a/tests/models/tla/foreground-loss-recovery/ForegroundLossRecovery.tla b/tests/models/tla/foreground-loss-recovery/ForegroundLossRecovery.tla index e40838c06..c17de76e6 100644 --- a/tests/models/tla/foreground-loss-recovery/ForegroundLossRecovery.tla +++ b/tests/models/tla/foreground-loss-recovery/ForegroundLossRecovery.tla @@ -11,7 +11,10 @@ \* GraphReady: ready and mapped, the rest of the frontend's readiness work \* (HTTPS, `up.after`, and for a restart the retirement of its pending \* intent and its operation lock) still running; -\* Serving. +\* Serving; +\* Stopping: Ctrl-C while serving; the owner's own stop is under way, inside +\* its enrolled relay cleanup, and the receipt reads `cleanup-intent` +\* (HACK-2746, real VM: the provider killed about 50 ms after Ctrl-C). \* Two things then race to end the start: the pool watch (it prints the \* message, releases the restart lock and exits 1), or the start's own error \* path (a request, image preparation or the foreground unwind fails first; @@ -71,6 +74,13 @@ \* Either proof needs a settled relay startup; routes do not. \* Unsettled: a relay startup may be left unsettled when the VM dies after \* services were requested (HACK-2731). +\* StopRecovery = "cross-boot": the runtime's cross-boot recovery finishes a +\* stop interrupted at `cleanup-intent` once the pool boots again, and +\* `hack down --recover` starts the stopped pool for it (`cross_boot_stop`, +\* HACK-2746); "none": before, the down kept `runtime_not_running`. +\* StopAdvice: the message for a run lost while stopping names +\* `hack down --recover` only when the runtime finishes that stop (this +\* fix); FALSE names it always, as the ready-stage message did. \* LiveRelayAdvice: the message once ready names `hack down --recover` only \* when the runtime can prove the dead owner's relay (`cross_boot_relay`: \* routes, or a settled relay startup; this fix). FALSE is #1273, which @@ -92,7 +102,7 @@ EXTENDS Naturals, Sequences CONSTANTS MessageRule, ErrorRule, ReleaseLock, RetireIntent, RepairLeftover, ClassifyRule, StorageBarrier, CrossBootStart, RouteProof, Unsettled, - LiveRelayAdvice + LiveRelayAdvice, StopRecovery, StopAdvice VARIABLES kind, recorded, ports, start, lostAt, endedBy, leftover, stale, left, settled, receipt, intent, lock, msg, todo, outcome @@ -100,7 +110,9 @@ vars == <> Commands == {"down", "up", "restart"} -Stages == {"Preparing", "Requested", "GraphReady", "Serving"} +Stages == {"Preparing", "Requested", "GraphReady", "Serving", "Stopping"} +\* Stages once the graph was ready and mapped. +ReadyStages == {"GraphReady", "Serving", "Stopping"} TypeOK == /\ kind \in {"up", "restart"} @@ -113,7 +125,7 @@ TypeOK == /\ stale \in BOOLEAN /\ left \in {"none", "failed", "restoring"} /\ settled \in BOOLEAN - /\ receipt \in {"none", "stopped", "unready", "ready"} + /\ receipt \in {"none", "stopped", "unready", "ready", "stopping"} /\ intent \in {"none", "cleaned"} /\ lock \in BOOLEAN /\ msg \in {"none", "up", "downUp", "downRestart", "inspect", @@ -162,6 +174,13 @@ Serve == /\ intent' = "none" /\ lock' = FALSE /\ UNCHANGED <> /\ UNCHANGED Frozen +\* Ctrl-C while serving: the owner starts its own stop, enrolled in its relay +\* cleanup, and the receipt reads `cleanup-intent`. +Stop == + /\ start = "Serving" + /\ start' = "Stopping" /\ receipt' = "stopping" + /\ UNCHANGED <> /\ UNCHANGED Frozen + \* The provider VM dies under the start. A recorded run lost before any \* service was requested may get its removed containers back (row 8), unless \* the down that removed them flushed the guest disk first. The record may @@ -180,6 +199,15 @@ Die == /\ UNCHANGED <> +\* The dead owner's relay is proved by the run's routes, or with no published +\* port by the relay's clean exit (RouteProof, HACK-2711), which needs a +\* settled relay startup (HACK-2731). +RelayProved == ports \/ (settled /\ RouteProof = "exit") +\* The cross-boot recovery finishes a stop interrupted at `cleanup-intent`: its +\* persisted bridge selection (the run's routes) or a settled relay startup +\* proves the dead relay owner (HACK-2746). +StopFinished == StopRecovery = "cross-boot" /\ RelayProved + ByIntent == IF intent = "cleaned" THEN "downRestart" ELSE "downUp" StageMessage(at) == @@ -197,15 +225,17 @@ RecoverMessage(at) == IF settled THEN "downUp" ELSE "inspect" [] at \in {"GraphReady", "Serving"} /\ LiveRelayAdvice /\ ~ports /\ ~settled -> "inspect" + [] at = "Stopping" /\ StopAdvice -> + IF StopFinished THEN "downUp" ELSE "inspect" [] OTHER -> StageMessage(at) Message(at) == CASE MessageRule = "recover" -> RecoverMessage(at) [] MessageRule = "stage" -> StageMessage(at) [] MessageRule = "graph" -> - IF at \in {"GraphReady", "Serving"} THEN "downUp" ELSE "inspect" + IF at \in ReadyStages THEN "downUp" ELSE "inspect" [] MessageRule = "intent" -> - IF at \in {"GraphReady", "Serving"} THEN ByIntent + IF at \in ReadyStages THEN ByIntent ELSE StageMessage(at) [] OTHER -> ByIntent @@ -273,7 +303,7 @@ OrdinaryFail == \* settled whatever its ports (`cross_boot_start`). \* Containers a lost VM brought back fail the confirmation unless the down \* removes them again. -RelayProved == ports \/ (settled /\ RouteProof = "exit") +\* (RelayProved and StopFinished are defined before the messages.) LostStartAdmitted == \/ CrossBootStart = "restoring" \/ CrossBootStart = "failed" /\ left = "failed" @@ -281,6 +311,7 @@ Retirable == CASE lostAt = "Preparing" -> TRUE [] lostAt = "Requested" -> recorded /\ LostStartAdmitted /\ settled /\ RelayProved + [] lostAt = "Stopping" -> StopFinished [] OTHER -> RelayProved DownAccepts == /\ Retirable @@ -316,7 +347,7 @@ Step == settled, lock, msg>> -Next == Request \/ GraphReady \/ Serve \/ Die \/ Watch \/ StartFails +Next == Request \/ GraphReady \/ Serve \/ Stop \/ Die \/ Watch \/ StartFails \/ OrdinaryFail \/ Step Spec == Init /\ [][Next]_vars @@ -333,6 +364,7 @@ NoNeedlessWithholding == \/ lostAt = "Requested" /\ ~(recorded /\ CrossBootStart # "none" /\ settled) \/ lostAt \in {"GraphReady", "Serving"} /\ ~ports /\ ~settled + \/ lostAt = "Stopping" /\ ~StopFinished \* Reachability witness (expected to fail): a lost restart is recovered by \* following its message. NoRestartRecovery == diff --git a/tests/models/tla/foreground-loss-recovery/code-without-veto.cfg b/tests/models/tla/foreground-loss-recovery/code-without-veto.cfg index 69376029a..2793b48e7 100644 --- a/tests/models/tla/foreground-loss-recovery/code-without-veto.cfg +++ b/tests/models/tla/foreground-loss-recovery/code-without-veto.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/failed-only.cfg b/tests/models/tla/foreground-loss-recovery/failed-only.cfg index 62e4a2615..f2465fa2c 100644 --- a/tests/models/tla/foreground-loss-recovery/failed-only.cfg +++ b/tests/models/tla/foreground-loss-recovery/failed-only.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/generic-error.cfg b/tests/models/tla/foreground-loss-recovery/generic-error.cfg index 15a7f66cc..421a1ef7c 100644 --- a/tests/models/tla/foreground-loss-recovery/generic-error.cfg +++ b/tests/models/tla/foreground-loss-recovery/generic-error.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/intent-message.cfg b/tests/models/tla/foreground-loss-recovery/intent-message.cfg index 1f9520245..48a42b3b9 100644 --- a/tests/models/tla/foreground-loss-recovery/intent-message.cfg +++ b/tests/models/tla/foreground-loss-recovery/intent-message.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/keep-intent.cfg b/tests/models/tla/foreground-loss-recovery/keep-intent.cfg index e10b5f44c..781abac1b 100644 --- a/tests/models/tla/foreground-loss-recovery/keep-intent.cfg +++ b/tests/models/tla/foreground-loss-recovery/keep-intent.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/keep-leftover.cfg b/tests/models/tla/foreground-loss-recovery/keep-leftover.cfg index 242dd5253..76d69ff1c 100644 --- a/tests/models/tla/foreground-loss-recovery/keep-leftover.cfg +++ b/tests/models/tla/foreground-loss-recovery/keep-leftover.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/leak-lock.cfg b/tests/models/tla/foreground-loss-recovery/leak-lock.cfg index 12e827ad9..a2de6f891 100644 --- a/tests/models/tla/foreground-loss-recovery/leak-lock.cfg +++ b/tests/models/tla/foreground-loss-recovery/leak-lock.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/live-relay.cfg b/tests/models/tla/foreground-loss-recovery/live-relay.cfg index ce6477cae..a339659ff 100644 --- a/tests/models/tla/foreground-loss-recovery/live-relay.cfg +++ b/tests/models/tla/foreground-loss-recovery/live-relay.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = TRUE LiveRelayAdvice = FALSE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/negative.cfg b/tests/models/tla/foreground-loss-recovery/negative.cfg index 803206fe0..e6e9a92b2 100644 --- a/tests/models/tla/foreground-loss-recovery/negative.cfg +++ b/tests/models/tla/foreground-loss-recovery/negative.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/no-cross-boot-stop.cfg b/tests/models/tla/foreground-loss-recovery/no-cross-boot-stop.cfg new file mode 100644 index 000000000..c68870c70 --- /dev/null +++ b/tests/models/tla/foreground-loss-recovery/no-cross-boot-stop.cfg @@ -0,0 +1,17 @@ +SPECIFICATION Spec +CONSTANTS + MessageRule = "recover" + ErrorRule = "stage" + ReleaseLock = TRUE + RetireIntent = TRUE + RepairLeftover = TRUE + ClassifyRule = "veto" + StorageBarrier = TRUE + CrossBootStart = "restoring" + RouteProof = "exit" + Unsettled = TRUE + LiveRelayAdvice = TRUE + StopRecovery = "none" + StopAdvice = FALSE +INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss +CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/no-cross-boot.cfg b/tests/models/tla/foreground-loss-recovery/no-cross-boot.cfg index 27563d7eb..cc0efb177 100644 --- a/tests/models/tla/foreground-loss-recovery/no-cross-boot.cfg +++ b/tests/models/tla/foreground-loss-recovery/no-cross-boot.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/pinned-relay.cfg b/tests/models/tla/foreground-loss-recovery/pinned-relay.cfg index c1e3ec923..43a827c26 100644 --- a/tests/models/tla/foreground-loss-recovery/pinned-relay.cfg +++ b/tests/models/tla/foreground-loss-recovery/pinned-relay.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "pinned" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/positive.cfg b/tests/models/tla/foreground-loss-recovery/positive.cfg index 229af526a..32fad987a 100644 --- a/tests/models/tla/foreground-loss-recovery/positive.cfg +++ b/tests/models/tla/foreground-loss-recovery/positive.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = TRUE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/restart-recovers.cfg b/tests/models/tla/foreground-loss-recovery/restart-recovers.cfg index 18f2dc218..3d5062e59 100644 --- a/tests/models/tla/foreground-loss-recovery/restart-recovers.cfg +++ b/tests/models/tla/foreground-loss-recovery/restart-recovers.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRestartRecovery CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/transitional-veto.cfg b/tests/models/tla/foreground-loss-recovery/transitional-veto.cfg index 28a51abd3..5cc46d58e 100644 --- a/tests/models/tla/foreground-loss-recovery/transitional-veto.cfg +++ b/tests/models/tla/foreground-loss-recovery/transitional-veto.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/withhold-preparing.cfg b/tests/models/tla/foreground-loss-recovery/withhold-preparing.cfg index c4e00b64d..1249addcc 100644 --- a/tests/models/tla/foreground-loss-recovery/withhold-preparing.cfg +++ b/tests/models/tla/foreground-loss-recovery/withhold-preparing.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/models/tla/foreground-loss-recovery/withhold-requested.cfg b/tests/models/tla/foreground-loss-recovery/withhold-requested.cfg index cb3759c1d..1876d697a 100644 --- a/tests/models/tla/foreground-loss-recovery/withhold-requested.cfg +++ b/tests/models/tla/foreground-loss-recovery/withhold-requested.cfg @@ -11,5 +11,7 @@ CONSTANTS RouteProof = "exit" Unsettled = FALSE LiveRelayAdvice = TRUE + StopRecovery = "cross-boot" + StopAdvice = TRUE INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss CHECK_DEADLOCK FALSE diff --git a/tests/native-project-down.test.ts b/tests/native-project-down.test.ts index c22e53c24..7c16a163e 100644 --- a/tests/native-project-down.test.ts +++ b/tests/native-project-down.test.ts @@ -2811,6 +2811,14 @@ test.each([ phase: "ready-observed", extra: { live_owner_recovery: "a".repeat(64) }, }, + // A stop at `cleanup-intent` the runtime does not finish across the boot + // (no `cross_boot_stop`; HACK-2746). + { foreground: "exited", phase: "cleanup-intent" }, + { + foreground: "exited", + phase: "cleanup-intent", + extra: { cross_boot_stop: false, cross_boot_relay: true }, + }, // HACK-2731: a live run with no published port and an unsettled relay // startup, whose dead relay owner the runtime cannot prove // (`relay_owner_refused` once the pool is started). @@ -2863,6 +2871,10 @@ test.each([ test.each([ { phase: "failed-retained" }, { phase: "preparing" }, + // HACK-2746 (real VM, 3 of 3): Ctrl-C, then the VM lost while the receipt + // read `cleanup-intent`, inside the owner's enrolled relay cleanup. Before, + // the down kept `runtime_not_running` and the run was stuck. + { phase: "cleanup-intent", extra: { cross_boot_stop: true } }, // An owner killed mid-restore, without its unwind (reviewer finding). { phase: "restoring" }, // The same-boot hint does not matter once the boot has ended. diff --git a/tests/native-project-start.test.ts b/tests/native-project-start.test.ts index c8d5a601b..68df1fb92 100644 --- a/tests/native-project-start.test.ts +++ b/tests/native-project-start.test.ts @@ -8805,6 +8805,17 @@ test.each([ retirable: true, }, { name: "ready", selected: { phase: "ready-observed" }, retirable: true }, + // HACK-2746: a stop interrupted inside its enrolled relay cleanup. + { + name: "interrupted stop", + selected: { phase: "cleanup-intent", cross_boot_stop: true }, + retirable: true, + }, + { + name: "cleanup-intent without cross_boot_stop", + selected: { phase: "cleanup-intent", cross_boot_stop: false }, + retirable: false, + }, // HACK-2731: a live run with no published port and an unsettled relay // startup, which the runtime refuses (`relay_owner_refused`). { @@ -8912,9 +8923,12 @@ test.each([ }), expected: { stage: "ready", retirable: true }, }, - // #1279 review: a ready-stage loss whose receipt is not live (a VM lost - // during the owner's own stop) is not refused for its relay, so it keeps the - // down advice, whatever `cross_boot_relay` says. + // #1279 review: a ready-stage loss whose receipt is not live is not refused + // for `cross_boot_relay`. HACK-2746 (real VM, 3 of 3): a VM lost during the + // owner's own stop leaves `cleanup-intent`, which the runtime finishes across + // the boot only with `cross_boot_stop` (or once a dead-owner recovery of it + // is selected); without it the down was refused (`runtime_not_running`), so + // no command is named for it. { name: "owner's stop, cleanup-intent with a dead-owner hint", reply: foregroundOwnerReply({ @@ -8925,13 +8939,28 @@ test.each([ expected: { stage: "ready", retirable: true }, }, { - name: "owner's stop, cleanup-intent, relay unprovable", + name: "owner's stop, cleanup-intent finished across the boot", reply: foregroundOwnerReply({ phase: "cleanup-intent", cross_boot_relay: false, + cross_boot_stop: true, }), expected: { stage: "ready", retirable: true }, }, + { + name: "owner's stop, cleanup-intent the runtime refuses", + reply: foregroundOwnerReply({ + phase: "cleanup-intent", + cross_boot_relay: true, + cross_boot_stop: false, + }), + expected: { stage: "ready", retirable: false }, + }, + { + name: "owner's stop, cleanup-intent, older runtime", + reply: foregroundOwnerReply({ phase: "cleanup-intent" }), + expected: { stage: "ready", retirable: false }, + }, { name: "stopped retained", reply: foregroundOwnerReply({ @@ -8998,10 +9027,15 @@ test.each([ retirable: true, }, { - name: "cleanup-intent", - selected: { phase: "cleanup-intent", cross_boot_relay: false }, + name: "cleanup-intent finished across the boot", + selected: { phase: "cleanup-intent", cross_boot_stop: true }, retirable: true, }, + { + name: "cleanup-intent the runtime refuses", + selected: { phase: "cleanup-intent", cross_boot_relay: false }, + retirable: false, + }, { name: "stopped retained", selected: { phase: "stopped-data-retained", foreground: "absent" }, @@ -9067,6 +9101,40 @@ test.each([ expect(lost.message.includes("hack down --recover")).toBe(!withheld); }); +// HACK-2746 with the #1279 cause-line fix: a VM lost during the owner's own +// stop at `cleanup-intent` names `hack down --recover` in both the advice and +// the cause line only with `cross_boot_stop`; without it, neither names it. +test.each([ + { name: "finished across the boot", crossBootStop: true }, + { name: "not finished", crossBootStop: false }, +])("a Ctrl-C stop lost with its VM names the down in advice and cause only when the runtime finishes it ($name)", async ({ + crossBootStop, +}) => { + const loss = await nativeLostStartRetirable({ + loss: { stage: "ready" }, + runtime: lostRuntime, + projectRoot: "/unused", + run: lostRun, + invoke: (async () => + foregroundOwnerReply({ + phase: "cleanup-intent", + cross_boot_relay: true, + cross_boot_stop: crossBootStop, + })) as unknown as Parameters< + typeof nativeLostStartRetirable + >[0]["invoke"], + }); + expect(loss).toEqual({ stage: "ready", retirable: crossBootStop }); + const end = { bootId: "b".repeat(32), providerPid: 4242 }; + const cause = new Error( + "Native foreground exit cleanup is unconfirmed; runtime and bridge state may be retained. Run hack down --recover to resume this run's confirmed cleanup with data retained." + ); + const lost = new NativeForegroundVmLostError({ end, loss, cause }); + const [, , advice, causeLine] = lost.message.split("\n"); + expect(advice?.includes("hack down --recover")).toBe(crossBootStop); + expect(causeLine?.includes("hack down --recover")).toBe(crossBootStop); +}); + test("a ready run whose relay owner is unprovable is told no command", () => { const end = { bootId: "b".repeat(32) }; const named = nativeForegroundPoolEndMessage(end, { stage: "ready" });