diff --git a/docs/guides/native-candidate.md b/docs/guides/native-candidate.md index c1c91776e..ca9709ba6 100644 --- a/docs/guides/native-candidate.md +++ b/docs/guides/native-candidate.md @@ -2944,7 +2944,12 @@ code 1, and what to run next, which depends on how far the start got: (`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. + command and says why: the relay cleanup marker names no ended boot of the + pool, the bridge selection the stop saved is missing or does not match, or + the runtime is too old to report it (HACK-2757). An owner that dies during + its stop while its VM keeps running (the provider still alive) is not this + case: that boot has not ended, and no command retires it yet (HACK-2763). A + provider killed with the VM counts as ended even before `runtime recover`. - 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 37b0fb275..cb59017d9 100644 --- a/packages/runtime-core/src/provider/graph/bridges/cleanup.rs +++ b/packages/runtime-core/src/provider/graph/bridges/cleanup.rs @@ -419,20 +419,75 @@ 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() - }) +/// Whether the cross-boot recovery of a stop interrupted inside its enrolled relay +/// cleanup, in `old_boot`, can prove the dead relay owner, as far as host files show +/// (HACK-2746, HACK-2757). While the bridge registry still records the run's slots, +/// `capture_previous_boot` selects them. Otherwise it reads the selection the +/// cleanup persisted (`relay-cleanup-bridges.json`) and accepts it only as +/// [`interrupted_selection_admits`] does here; an empty one then needs a settled +/// relay startup. Presentation only (`graph foreground-owner`): read without a lease +/// or the guest; an unreadable or foreign file counts as no proof, and the recovery +/// revalidates everything itself. +pub(crate) fn interrupted_stop_provable( + candidate: &Candidate, + graph_root: &std::path::Path, + owner: &crate::provider::state::Owner, + receipt: &Receipt, + old_boot: &str, +) -> bool { + if run_holds_slot(candidate, &owner.token, &receipt.run) { + return true; + } + let Ok(prior) = + selection_path(graph_root).and_then(|path| state::read_bounded::(&path, 65536)) + else { + return false; + }; + let path = root(candidate).join("state.json"); + let serial = match state::read_bounded::(&path, 65536) { + Ok(store) if store.version == 1 && store.owner == owner.token => store.next_launch_serial, + // A pool without the bridge registry reads it as empty (`load_store`). + Err(_) if owner.application_bridge.is_none() && !path.exists() => 0, + _ => return false, + }; + interrupted_selection_admits( + &prior, + receipt, + &owner.token, + old_boot, + owner.application_bridge.map_or(0, |intent| intent.slots), + serial, + ) +} + +/// The checks `capture_previous_boot` applies to the persisted selection of an +/// interrupted enrolled cleanup (`pending_interrupted`): this pool owner, captured +/// in `old_boot` with no earlier boot or predecessor proof of its own, this run and +/// plan, this bridge capacity, a serial the registry has reached, and bindings that +/// [`validate_bindings`] accepts (route assignments running on that boot). An +/// empty one also needs a settled relay startup, which its predecessor proof +/// requires ([`select_predecessor`]). +fn interrupted_selection_admits( + prior: &Selection, + receipt: &Receipt, + owner: &str, + old_boot: &str, + capacity: u8, + serial: u64, +) -> bool { + prior.version == 1 + && prior.owner == owner + && prior.boot == old_boot + && prior.previous_boot.is_none() + && prior.predecessor_owner.is_none() + && prior.predecessor_absence.is_none() + && prior.predecessor_exit.is_none() + && prior.run == receipt.run + && prior.plan == receipt.plan_id + && prior.capacity == capacity + && prior.serial <= serial + && validate_bindings(receipt, prior, None).is_ok() + && (!prior.selected.is_empty() || pinned_predecessor_eligible(receipt)) } fn run_holds_slot(candidate: &Candidate, owner: &str, run: &str) -> bool { @@ -1354,6 +1409,52 @@ mod tests { .unwrap() } + #[test] + fn an_interrupted_selection_is_admitted_only_as_capture_previous_boot_admits_it() { + // HACK-2757 (review of #1290): the advice for a Ctrl-C stop lost with its + // VM names `hack down --recover` only for a persisted selection the + // recovery's own capture accepts. + let (selected, store) = live_selection(); + let assignment = store.slots[&0].clone(); + let receipt = receipt_for_assignment(&selected, &assignment); + let boot = selected.boot.clone(); + let admits = |prior: &Selection| { + interrupted_selection_admits(prior, &receipt, &selected.owner, &boot, 3, 1) + }; + assert!(admits(&selected)); + let changed = |change: &dyn Fn(&mut Selection)| { + let mut prior = selected.clone(); + change(&mut prior); + admits(&prior) + }; + assert!(!changed(&|prior| prior.owner = "9".repeat(32))); + assert!(!changed( + &|prior| prior.boot = "22222222-2222-2222-2222-222222222222".into() + )); + assert!(!changed(&|prior| prior.previous_boot = Some("0".repeat(8)))); + assert!(!changed( + &|prior| prior.predecessor_owner = Some("4".repeat(64)) + )); + assert!(!changed(&|prior| prior.run = "9".repeat(32))); + assert!(!changed(&|prior| prior.plan = "9".repeat(64))); + assert!(!changed(&|prior| prior.capacity = 4)); + assert!(!changed(&|prior| prior.serial = 2)); + // Route assignments must be running on that boot, with their helpers. + assert!(!changed(&|prior| { + prior.selected.get_mut(&0).unwrap().assignment.phase = "stopped".into() + })); + assert!(!changed(&|prior| { + prior.selected.get_mut(&0).unwrap().assignment.boot_id = "other".into() + })); + assert!(!changed(&|prior| prior + .selected + .get_mut(&0) + .unwrap() + .helper = None)); + // An empty one needs a settled relay startup: this receipt has none. + assert!(!changed(&|prior| prior.selected.clear())); + } + #[test] fn exited_current_run_relay_is_selected_before_live_bridge_capture() { let (selected, mut store) = live_selection(); 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 6624cc06d..4fa967351 100644 --- a/packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs +++ b/packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs @@ -96,13 +96,25 @@ 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. +/// for a boot that has ended, and the bridge selection it persisted is beside it. +/// The cross-boot recovery admits that receipt once the pool boots again +/// (`interrupted_enrollment` in `execute`, and in `archive_completed_prior`; the +/// explicit cleanup's `prepare` refuses it), provided it can prove the dead relay +/// owner: by the run's slots, or by a persisted selection its capture accepts +/// (`bridges::cleanup::interrupted_stop_provable`). So a caller starts a stopped +/// pool, or names `hack down --recover`, only for one this returns. +/// +/// The ended boot is one of the pool's earlier boots, or its last recorded boot +/// unless that boot is still live: the record says `running` and its provider is +/// alive (the check `runtime status` makes, [`identity::provider_gone`]). A provider +/// killed with its VM leaves the record `running` with the dead boot until +/// `runtime recover` writes `recovered-unclean`; that boot has ended (`status` reads +/// it `process-exited`), so it counts (#1291 review). A live boot never counts +/// (HACK-2757): the cross-boot recovery never selects the current boot, so an owner +/// that died while its VM kept running is not one. A provider whose state cannot +/// be read counts as live, so nothing is promised. 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, @@ -119,17 +131,30 @@ pub(super) fn interrupted_stop( if receipt.phase != "cleanup-intent" || receipt.relay_startup.is_none() { return false; } + let current = owner.guest_boot_id.as_deref().filter(|_| live_boot(owner)); 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)) + let Some(old_boot) = boots.iter().find(|boot| { + current != Some(boot.as_str()) + && host_relay::context(&receipt.owner, boot).is_ok_and(|context| { + marker.runtime == context.runtime && marker.boot == context.boot + }) + }) else { + return false; + }; + exists(&root.join("relay-cleanup-bridges.json")).unwrap_or(false) + && bridges::cleanup::interrupted_stop_provable(candidate, root, owner, receipt, old_boot) +} + +/// Whether the pool record's boot is still live: `running`, with a provider that +/// is not proven gone. An unreadable provider state counts as live. +fn live_boot(owner: &Owner) -> bool { + owner.phase == "running" + && owner + .process + .as_ref() + .is_none_or(|process| !identity::provider_gone(process).unwrap_or(false)) } fn validate( @@ -3231,8 +3256,8 @@ mod tests { // 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`. + // (`interrupted_enrollment` in `execute`), 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(); @@ -3256,7 +3281,9 @@ mod tests { 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}) + "plan":receipt.plan_id, + "capacity":owner.application_bridge.map_or(0, |intent| intent.slots), + "serial":0,"selected":selected}) }; state::write( &root.join("relay-cleanup-bridges.json"), @@ -3279,8 +3306,10 @@ mod tests { 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. + // Without a settled relay startup, only persisted routes the recovery's + // capture accepts prove the dead relay owner (HACK-2757): none, nor a + // reserved route without its helper evidence, which that capture refuses + // (`bridges::cleanup` tests cover the accepted shape). let mut unsettled = receipt.clone(); unsettled.relay_startup.as_mut().unwrap().control_only = false; assert!(!stop(&unsettled)); @@ -3291,6 +3320,98 @@ mod tests { "container_id":"c","network_id":"n","boot_id":boot,"phase":"reserved"}}})), ) .unwrap(); - assert!(stop(&unsettled)); + assert!(!stop(&unsettled)); + // A selection of another plan, capacity or boot is refused by that capture. + for changed in [ + json!({"plan":"9".repeat(64)}), + json!({"capacity":9}), + json!({"boot":"33333333-3333-3333-3333-333333333333"}), + json!({"previous_boot":"33333333-3333-3333-3333-333333333333"}), + ] { + let mut value = selection(json!({})); + for (key, field) in changed.as_object().unwrap() { + value[key] = field.clone(); + } + state::write(&root.join("relay-cleanup-bridges.json"), &value).unwrap(); + assert!(!stop(&receipt), "{changed}"); + } + state::write( + &root.join("relay-cleanup-bridges.json"), + &selection(json!({})), + ) + .unwrap(); + assert!(stop(&receipt)); + } + + #[test] + fn an_owner_that_died_while_its_vm_kept_running_is_not_a_cross_boot_stop_but_a_killed_provider_is() + { + // HACK-2757 (review of #1290): the cross-boot recovery never selects the + // pool's current boot, so while the pool runs a marker of that boot is not a + // cross-boot stop; `hack up` and the advice do not send it to + // `hack down --recover`. Once the pool has booted again, the same marker is + // one of an earlier boot. + let fixture = super::super::retained_startup::tests::Fixture::new(); + let mut 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(); + 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()); + let context = host_relay::context(&receipt.owner, &boot).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( + &root.join("relay-cleanup-bridges.json"), + &json!({"version":1,"owner":owner.token,"boot":boot,"run":receipt.run, + "plan":receipt.plan_id, + "capacity":owner.application_bridge.map_or(0, |intent| intent.slots), + "serial":0,"selected":{}}), + ) + .unwrap(); + // The VM was lost and `runtime recover` ran: the pool is stopped with that + // boot recorded. + assert_ne!(owner.phase, "running"); + assert!(interrupted_stop( + &fixture.candidate, + &root, + &receipt, + &owner + )); + // #1291 review: the provider was killed and nothing rewrote the record, so + // it still says `running` with the dead boot (`runtime status` reads it + // `process-exited`). That boot has ended: still a cross-boot stop, so the + // lost-VM advice and `hack up` name `hack down --recover` (HACK-2746 rows). + owner.phase = "running".into(); + assert!(identity::provider_gone(owner.process.as_ref().unwrap()).unwrap()); + assert!(interrupted_stop( + &fixture.candidate, + &root, + &receipt, + &owner + )); + // The owner died while its VM kept running: a live provider, so the boot is + // still current and nothing is promised. + owner.process = Some(identity::observe(std::process::id() as i32).unwrap()); + assert!(!interrupted_stop( + &fixture.candidate, + &root, + &receipt, + &owner + )); + // The pool booted again: the run's boot is now an earlier one. + owner.previous_guest_boot_id = Some(boot.clone()); + owner.guest_boot_id = Some("44444444-4444-4444-4444-444444444444".into()); + assert!(interrupted_stop( + &fixture.candidate, + &root, + &receipt, + &owner + )); } } diff --git a/packages/runtime-core/src/provider/graph/mod.rs b/packages/runtime-core/src/provider/graph/mod.rs index d596c19ed..b97e9712f 100644 --- a/packages/runtime-core/src/provider/graph/mod.rs +++ b/packages/runtime-core/src/provider/graph/mod.rs @@ -2128,8 +2128,9 @@ pub fn foreground_owner(candidate: &Candidate, run: &str) -> Result = new Set([ * 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). + * `graph foreground-owner` reports `cross_boot_stop`: a pending relay cleanup + * marker of a boot that has ended (never a boot whose provider is still + * alive, HACK-2757), the bridge selection that stop persisted, and a relay owner the + * recovery can prove from them. */ export const NATIVE_CROSS_BOOT_STOP_PHASE = "cleanup-intent"; @@ -88,15 +89,46 @@ export function nativeCrossBootRecoverable(selection: { * same-boot recovery) keeps the down advice, whose own paths handle it. */ export function nativeReadyLossRetirable( - selection: Pick< - NativeForegroundOwnerSelection, - "phase" | "crossBootRelay" | "crossBootStop" | "deadOwnerRecovery" - > + selection: NativeReadyLossSelection ): boolean { + return nativeReadyLossWithheld(selection) === undefined; +} + +/** The selection fields a ready-stage loss reads. */ +type NativeReadyLossSelection = Pick< + NativeForegroundOwnerSelection, + | "phase" + | "crossBootRelay" + | "crossBootStop" + | "crossBootStopReported" + | "deadOwnerRecovery" +>; + +/** + * Why a run lost once ready is not retired by `hack down --recover`, so its + * message names the real reason (HACK-2757): + * - `relay`: a live receipt whose relay owner the runtime cannot prove (no + * published port and an unsettled relay startup, HACK-2731). + * - `stop`: a stop interrupted at `cleanup-intent` that the runtime reports + * it cannot finish across the boot (`cross_boot_stop` false: its relay + * cleanup marker names no ended boot of this pool, or the bridge selection + * the stop saved is missing or is not one the recovery accepts). + * - `stop-unreported`: the same receipt from a runtime too old to report + * `cross_boot_stop`, which never finished one. + * Undefined when the down retires it. + */ +export type NativeReadyLossWithheld = "relay" | "stop" | "stop-unreported"; + +export function nativeReadyLossWithheld( + selection: NativeReadyLossSelection +): NativeReadyLossWithheld | undefined { if (selection.phase === NATIVE_CROSS_BOOT_STOP_PHASE) { - return selection.crossBootStop || selection.deadOwnerRecovery !== null; + if (selection.crossBootStop || selection.deadOwnerRecovery !== null) { + return; + } + return selection.crossBootStopReported ? "stop" : "stop-unreported"; } - return !nativeLiveRelayUnprovable(selection); + return nativeLiveRelayUnprovable(selection) ? "relay" : undefined; } /** @@ -151,6 +183,8 @@ export type NativeForegroundOwnerSelection = { * which never finished one: false. */ readonly crossBootStop: boolean; + /** Whether the runtime reported `cross_boot_stop` at all (older ones do not). */ + readonly crossBootStopReported: boolean; /** * A lost-removal repair whose storage barrier has not confirmed * (`lost_removal_pending`, HACK-2719), read from its host marker. Absent @@ -218,6 +252,7 @@ export function parseNativeForegroundOwner( crossBootStart: value.cross_boot_start === true, crossBootRelay: value.cross_boot_relay !== false, crossBootStop: value.cross_boot_stop === true, + crossBootStopReported: typeof value.cross_boot_stop === "boolean", lostRemovalPending: value.lost_removal_pending === true, receiptSha256: value.receipt_sha256, foreground: diff --git a/src/backends/native-project-start.ts b/src/backends/native-project-start.ts index c415995a2..8248f8173 100644 --- a/src/backends/native-project-start.ts +++ b/src/backends/native-project-start.ts @@ -49,8 +49,9 @@ import { nativeStartOutcomeUnknown } from "../lib/native-up-refusals.ts"; import { adaptNativeAwsEnvironment } from "./native-aws-environment.ts"; import { scheduleNativeAwsExpiryWarnings } from "./native-aws-expiry.ts"; import { + type NativeReadyLossWithheld, nativeCrossBootRecoverable, - nativeReadyLossRetirable, + nativeReadyLossWithheld, parseNativeForegroundOwner, } from "./native-cross-boot-recovery.ts"; import type { NativeDependencyOwnerResolver } from "./native-dependency-owners.ts"; @@ -5362,7 +5363,7 @@ export async function nativeLostStartRetirable(opts: { if (opts.loss.stage === "ready") { return selection === undefined ? opts.loss - : { ...opts.loss, retirable: nativeReadyLossRetirable(selection) }; + : readyLoss(nativeReadyLossWithheld(selection)); } return { ...opts.loss, @@ -5370,6 +5371,16 @@ export async function nativeLostStartRetirable(opts: { }; } +/** A ready-stage loss as its selection showed it, with the reason it is not + * retired (HACK-2757). */ +function readyLoss( + withheld: NativeReadyLossWithheld | undefined +): NativeForegroundLossStage { + return withheld === undefined + ? { stage: "ready", retirable: true } + : { stage: "ready", retirable: false, withheld }; +} + /** * The loss stage of a `hack restart` lost in its preflight (HACK-2096 real-VM * row 6). An ordinary restart has saved no intent and stopped nothing yet: its diff --git a/src/backends/native-start-pool-watch.ts b/src/backends/native-start-pool-watch.ts index b64081a35..bceb9a058 100644 --- a/src/backends/native-start-pool-watch.ts +++ b/src/backends/native-start-pool-watch.ts @@ -35,7 +35,9 @@ * on a graph owner whose VM was gone and never exited. `onEnded` receives the * evidence, so a foreground start can name the lost VM before it exits. */ + import { isRecord } from "../lib/guards.ts"; +import type { NativeReadyLossWithheld } from "./native-cross-boot-recovery.ts"; import { nativeHttpsPoolBootEnded, readNativePoolRecord, @@ -85,7 +87,12 @@ export type NativeForegroundLossStage = */ readonly retirable?: boolean; } - | { readonly stage: "ready"; readonly retirable?: boolean }; + | { + readonly stage: "ready"; + readonly retirable?: boolean; + /** With `retirable` false: why no command retires it (HACK-2757). */ + readonly withheld?: NativeReadyLossWithheld; + }; /** * What a foreground start prints when its VM is lost (HACK-2096): which VM, that @@ -148,13 +155,21 @@ function lossAdvice(loss: NativeForegroundLossStage): string { return UNRECORDED_REQUESTED_ADVICE; } if (loss.stage === "ready" && loss.retirable === false) { - return UNPROVABLE_READY_ADVICE; + return WITHHELD_READY_ADVICE[loss.withheld ?? "relay"]; } return LOSS_ADVICE[loss.stage]; } -const UNPROVABLE_READY_ADVICE = - "It was lost once it was ready, but the runtime cannot prove which relay owner it had (the run publishes no port and its host relay startup had not settled), so no hack command can retire it yet. Keep this native home unchanged for inspection; hack ps --json shows what the run left."; +const KEEP_HOME = + "Keep this native home unchanged for inspection; hack ps --json shows what the run left."; + +/** Why a ready-stage loss names no command, by its selection (HACK-2757). */ +const WITHHELD_READY_ADVICE: Readonly> = + { + relay: `It was lost once it was ready, but the runtime cannot prove which relay owner it had (the run publishes no port and its host relay startup had not settled), so no hack command can retire it yet. ${KEEP_HOME}`, + stop: `It was lost during its own stop (Ctrl-C), and the runtime cannot finish that stop after the VM restarts: its relay cleanup marker names no ended boot of this pool, or the bridge selection the stop saved is missing or does not match. No hack command can retire it yet. ${KEEP_HOME}`, + "stop-unreported": `It was lost during its own stop (Ctrl-C), and this native runtime is too old to report whether it can finish that stop after the VM restarts, so no hack command is named. ${KEEP_HOME}`, + }; const UNRECORDED_REQUESTED_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; hack ps --json shows what the run left."; diff --git a/tests/models/tla/README.md b/tests/models/tla/README.md index 4d9e4a62d..a4d8c48f6 100644 --- a/tests/models/tla/README.md +++ b/tests/models/tla/README.md @@ -860,6 +860,7 @@ nothing pending. | `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`. | +| `old-stop-advice` | HACK-2757 (review of #1290): the runtime that finishes the interrupted stop, with the message that names `hack down --recover` for every stop lost at `cleanup-intent`. A stop with no persisted route and an unsettled relay startup is told the down, which the recovery refuses: `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. | diff --git a/tests/models/tla/foreground-loss-recovery/old-stop-advice.cfg b/tests/models/tla/foreground-loss-recovery/old-stop-advice.cfg new file mode 100644 index 000000000..61a8cf1d6 --- /dev/null +++ b/tests/models/tla/foreground-loss-recovery/old-stop-advice.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 = "cross-boot" + StopAdvice = FALSE +INVARIANTS TypeOK NoRefusedAdvice NoNeedlessWithholding NoFalseLoss NoMissedLoss +CHECK_DEADLOCK FALSE diff --git a/tests/native-project-start.test.ts b/tests/native-project-start.test.ts index 68df1fb92..33493c916 100644 --- a/tests/native-project-start.test.ts +++ b/tests/native-project-start.test.ts @@ -8903,7 +8903,7 @@ test.each([ foreground: "running", cross_boot_relay: false, }), - expected: { stage: "ready", retirable: false }, + expected: { stage: "ready", retirable: false, withheld: "relay" }, }, { name: "relay provable", @@ -8954,12 +8954,12 @@ test.each([ cross_boot_relay: true, cross_boot_stop: false, }), - expected: { stage: "ready", retirable: false }, + expected: { stage: "ready", retirable: false, withheld: "stop" }, }, { name: "owner's stop, cleanup-intent, older runtime", reply: foregroundOwnerReply({ phase: "cleanup-intent" }), - expected: { stage: "ready", retirable: false }, + expected: { stage: "ready", retirable: false, withheld: "stop-unreported" }, }, { name: "stopped retained", @@ -9020,6 +9020,7 @@ test.each([ name: "relay unprovable", selected: { phase: "ready-observed", cross_boot_relay: false }, retirable: false, + withheld: "relay", }, { name: "relay provable", @@ -9035,15 +9036,22 @@ test.each([ name: "cleanup-intent the runtime refuses", selected: { phase: "cleanup-intent", cross_boot_relay: false }, retirable: false, + withheld: "stop-unreported", }, { name: "stopped retained", selected: { phase: "stopped-data-retained", foreground: "absent" }, retirable: true, }, -])("a restart lost in its preflight withholds the down only for an unprovable live relay ($name)", async ({ +] as { + name: string; + selected: Record; + retirable: boolean; + withheld?: "relay" | "stop" | "stop-unreported"; +}[])("a restart lost in its preflight withholds the down only for an unprovable live relay ($name)", async ({ selected, retirable, + withheld, }) => { const loss = restartPreflightLossStage({ cleanedRetry: false, @@ -9060,7 +9068,11 @@ test.each([ typeof nativeLostStartRetirable >[0]["invoke"], }); - expect(resolved).toEqual({ stage: "ready", retirable }); + expect(resolved).toEqual( + withheld === undefined + ? { stage: "ready", retirable } + : { stage: "ready", retirable, withheld } + ); const message = nativeForegroundPoolEndMessage( { bootId: "b".repeat(32) }, resolved @@ -9124,7 +9136,11 @@ test.each([ typeof nativeLostStartRetirable >[0]["invoke"], }); - expect(loss).toEqual({ stage: "ready", retirable: crossBootStop }); + expect(loss).toEqual( + crossBootStop + ? { stage: "ready", retirable: true } + : { stage: "ready", retirable: false, withheld: "stop" } + ); 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." @@ -9135,6 +9151,32 @@ test.each([ expect(causeLine?.includes("hack down --recover")).toBe(crossBootStop); }); +// HACK-2757 (review of #1290): a ready-stage loss that names no command says +// why: an unprovable relay, a stop the runtime cannot finish across the boot, +// or a runtime too old to say. +test.each([ + { withheld: "relay", says: "publishes no port" }, + { withheld: "stop", says: "relay cleanup marker names no ended boot" }, + { withheld: "stop-unreported", says: "too old to report" }, +] as const)("a ready-stage loss that names no command gives its reason ($withheld)", ({ + withheld, + says, +}) => { + const message = nativeForegroundPoolEndMessage( + { bootId: "b".repeat(32) }, + { stage: "ready", retirable: false, withheld } + ); + expect(message).toContain(says); + expect(message).not.toContain("hack down"); + expect(message).toContain("Keep this native home unchanged"); + const reasons = [ + "publishes no port", + "relay cleanup marker names no ended boot", + "too old to report", + ]; + expect(reasons.filter((reason) => message.includes(reason))).toEqual([says]); +}); + 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" });