Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/diagrams/foreground-loss-recovery.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ stateDiagram-v2
state advice <<choice>>
Lost --> advice
advice --> Inspect : [fresh up, Requested]
advice --> Down : [run recorded]
advice --> Inspect : [relay unproven]
advice --> Down : [recorded, relay proven]
advice --> Up : [fresh up, Preparing]
Down --> Up : down --recover
Up --> Recovered : hack up
Expand All @@ -40,8 +41,10 @@ stateDiagram-v2
end note
note left of Inspect
A fresh up has no record
for down to retire yet:
none named.
for down to retire yet, and
a run with no port whose
relay never settled has no
owner proof: none named.
INV NoNeedlessWithholding
end note
note right of Down
Expand Down
Binary file modified docs/diagrams/foreground-loss-recovery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/diagrams/foreground-loss-recovery.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion docs/guides/native-candidate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,21 @@ list the run's containers again, stopped. `hack up` then refuses with nothing
started and data kept, and says to run `hack down --recover`, which removes them
again on the running pool, then `hack up`. An earlier `hack down --recover` of that
kind that ended before it confirmed the removal is durable makes `hack up` refuse at
once (`graph_lost_removal_pending`) and name the same two commands.
once (`graph_lost_removal_pending`) and name the same two commands. The pool that
`hack up` booted may go idle and stop before you run that down. `hack down
--recover` then starts the pool again for the repair (HACK-2731): the refused
`hack up` leaves a marker for that run beside its run mapping, and the runtime
reports an unconfirmed repair from its own marker. Earlier versions answered that
the runtime was not running, and the next `hack up` printed the same refusal
again. The marker grants nothing: the runtime still checks the receipt and every
container, and a verified stop removes it. A plain `hack down` does not start the
pool for it.

A cleanup that removed containers or networks reports a storage flush that did not
confirm, by its deadline or with a failed guest command, as `graph_cleanup_uncertain`
("Run hack down again"). Any other failure keeps its own code: a VM that was
replaced meanwhile is `guest_identity_mismatch` and a changed runtime is
`runtime_changed` (HACK-2731), not a slow flush.

A foreground `hack up` (or `hack restart`) watches its pool the same way
(HACK-2096). When its provider VM dies or the pool stops under it, it prints which
Expand All @@ -2916,6 +2930,11 @@ code 1, and what to run next, which depends on how far the start got:
pool), then `hack up`, which starts it again. This holds with or without a
published port: a run with no port has no bridge routes, and the runtime
then proves its dead owner's relay by that relay's clean exit (HACK-2711).
That proof needs a settled relay startup: a run with no published port whose
host dependency services never released their startup is refused
(`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.
- 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
Expand Down
21 changes: 21 additions & 0 deletions packages/runtime-core/src/provider/graph/bridges/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,27 @@ fn pinned_predecessor_eligible(receipt: &Receipt) -> bool {
})
}

/// Whether a cross-boot dead-owner recovery of `receipt` can prove its dead relay
/// owner, as far as host files show (HACK-2731): the host bridge registry records
/// a slot for the run, so its routes prove it, or the run's relay startup settled,
/// which a selection without routes needs for either predecessor proof
/// ([`select_predecessor`]). Presentation only (`graph foreground-owner`): read
/// without a lease or the guest. An unreadable registry, one of another version,
/// or one another pool owner wrote (`owner`, the pool's owner token, which the
/// recovery's registry check also requires) counts as no slot, and the recovery
/// revalidates everything itself.
pub(crate) fn relay_owner_provable(candidate: &Candidate, owner: &str, receipt: &Receipt) -> bool {
pinned_predecessor_eligible(receipt) || run_holds_slot(candidate, owner, &receipt.run)
}

fn run_holds_slot(candidate: &Candidate, owner: &str, run: &str) -> bool {
state::read_bounded::<Store>(&root(candidate).join("state.json"), 65536).is_ok_and(|store| {
store.version == 1
&& store.owner == owner
&& store.slots.values().any(|slot| slot.run == run)
})
}

fn predecessor_owner(
receipt: &Receipt,
previous: &str,
Expand Down
69 changes: 69 additions & 0 deletions packages/runtime-core/src/provider/graph/dead_owner_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3116,4 +3116,73 @@ mod tests {
fs::remove_file(fixture.0.join("restore-history.json")).unwrap();
assert!(require_historical_recovery(&fixture.0, &current).is_err());
}

#[test]
fn a_live_run_relay_owner_is_provable_by_its_bridge_slot_or_a_settled_relay() {
// HACK-2731: a run with no published port proves its dead relay owner only
// through a settled relay startup (`select_predecessor`), so
// `graph foreground-owner` reports `cross_boot_relay` false for one with
// neither a bridge slot nor a settled relay, and the CLI names no
// `hack down --recover` for it.
let fixture = super::super::retained_startup::tests::Fixture::new();
let token = Owner::load(&fixture.candidate).unwrap().token;
let provable = |receipt: &Receipt| {
bridges::cleanup::relay_owner_provable(&fixture.candidate, &token, receipt)
};
let mut receipt = fixture.receipt();
receipt.phase = "ready-observed".into();
assert!(!provable(&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());
assert!(provable(&receipt));
let mut unsettled = receipt.clone();
unsettled.relay_startup.as_mut().unwrap().control_only = false;
assert!(!provable(&unsettled));
assert_eq!(
foreground_owner(&fixture.candidate, &fixture.run).unwrap()["cross_boot_relay"],
false
);
// A bridge slot of this run proves it through the run's routes, whatever
// the relay startup; another run's slot or a foreign registry does not.
let registry = fixture.candidate.state_root.join("run/bridge-assignments");
state::private_directory(&registry).unwrap();
let store = |run: &str, version: u32, owner: &str| {
json!({"version":version,"owner":owner,"next_launch_serial":0,"slots":{"1":{
"reservation":"r","run":run,"service":"web","generation":"g",
"container_id":"c","network_id":"n","boot_id":"b","phase":"reserved"}}})
};
let write = |value: serde_json::Value| {
state::write(&registry.join("state.json"), &value).unwrap();
};
write(store(&receipt.run, 1, &token));
assert!(provable(&unsettled));
assert_eq!(
foreground_owner(&fixture.candidate, &fixture.run).unwrap()["cross_boot_relay"],
true
);
write(store(&"f".repeat(32), 1, &token));
assert!(!provable(&unsettled));
write(store(&receipt.run, 2, &token));
assert!(!provable(&unsettled));
// #1279 review: a registry another pool owner wrote is foreign.
write(store(&receipt.run, 1, &"9".repeat(32)));
assert!(!provable(&unsettled));
}

#[test]
fn foreground_owner_reports_an_unconfirmed_lost_removal_repair() {
// HACK-2731: read from the repair's host marker, so `hack down --recover`
// starts a stopped pool to finish it.
let fixture = super::super::retained_startup::tests::Fixture::new();
let pending = |fixture: &super::super::retained_startup::tests::Fixture| {
foreground_owner(&fixture.candidate, &fixture.run).unwrap()["lost_removal_pending"]
.clone()
};
assert_eq!(pending(&fixture), false);
fs::write(
fixture.graph().join(super::super::LOST_REMOVAL_REPAIR),
b"{}",
)
.unwrap();
assert_eq!(pending(&fixture), true);
}
}
64 changes: 59 additions & 5 deletions packages/runtime-core/src/provider/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,16 @@ pub fn foreground_owner(candidate: &Candidate, run: &str) -> Result<Value, Candi
// receipt alone: a caller also requires the owner exited (`foreground`).
// Selection only, like the fields around it.
"cross_boot_start": dead_owner_cleanup::unconfirmed_start(&receipt),
// Whether that recovery can prove the dead owner's relay (HACK-2731): the
// run holds a bridge slot, or its relay startup settled. A run with no
// published port and an unsettled relay startup is refused
// (`relay_owner_refused`), so a caller names `hack down --recover` for
// a live phase only with this. Selection only, like the fields around it.
"cross_boot_relay": bridges::cleanup::relay_owner_provable(candidate, &owner.token, &receipt),
// A lost-removal repair whose storage barrier has not confirmed (HACK-2719),
// read from its host marker: only `hack down --recover` on a running pool
// finishes it, so a down finding the pool stopped starts it (HACK-2731).
"lost_removal_pending": fs::symlink_metadata(root.join(LOST_REMOVAL_REPAIR)).is_ok(),
"dead_owner_recovery": predecessor,
"dead_owner_recovery_complete": predecessor_complete,
"dead_owner_recovery_error": predecessor_error,
Expand Down Expand Up @@ -2777,13 +2787,32 @@ const STORAGE_BARRIER_TIMEOUT: Duration = Duration::from_secs(10);
/// which a repeated `hack down` (and every recovery) resumes by reinspection.
pub(super) fn storage_barrier(engine: &Engine<'_>) -> Result<(), CandidateError> {
let deadline = std::time::Instant::now() + STORAGE_BARRIER_TIMEOUT;
let output = engine
.guest()
.execute_cleanup_until(STORAGE_BARRIER, &[], deadline)
.map_err(|_| storage_barrier_refused())?;
storage_barrier_confirmed(&output)
storage_barrier_outcome(
engine
.guest()
.execute_cleanup_until(STORAGE_BARRIER, &[], deadline),
)
}

/// Only a barrier that did not confirm is reported as one: the exec's deadline
/// or a lost reply (`agent_protocol_uncertain`), or a guest command that did not
/// complete with exit 0 (`guest_command_failed`). Every other error keeps its
/// own code and message, so a replaced VM (`guest_identity_mismatch`) or a
/// changed runtime (`runtime_changed`) is not reported as a slow flush
/// (HACK-2731).
fn storage_barrier_outcome(result: Result<String, CandidateError>) -> Result<(), CandidateError> {
match result {
Ok(output) => storage_barrier_confirmed(&output),
Err(error) if STORAGE_BARRIER_UNCONFIRMED.contains(&error.code) => {
Err(storage_barrier_refused())
}
Err(error) => Err(error),
}
}

/// The exec errors of a barrier that did not confirm ([`storage_barrier_outcome`]).
const STORAGE_BARRIER_UNCONFIRMED: [&str; 2] = ["agent_protocol_uncertain", "guest_command_failed"];

fn storage_barrier_refused() -> CandidateError {
error(
"graph_cleanup_uncertain",
Expand Down Expand Up @@ -2819,6 +2848,31 @@ mod storage_barrier_tests {
assert!(refused.message.contains("Run hack down again."));
}
}

#[test]
fn only_an_unconfirmed_barrier_reports_the_barrier_refusal() {
// A deadline or lost reply, and a guest command that did not exit 0, did
// not confirm the flush: they report the barrier's own refusal.
for code in STORAGE_BARRIER_UNCONFIRMED {
let refused =
storage_barrier_outcome(Err(CandidateError::new(code, "failed"))).unwrap_err();
assert_eq!(refused.code, "graph_cleanup_uncertain");
}
// A replaced VM or a changed runtime keeps its own code and message.
let kept_codes = [
"guest_identity_mismatch",
"runtime_changed",
"provider_busy",
];
for code in kept_codes {
let kept = storage_barrier_outcome(Err(CandidateError::new(code, "kept"))).unwrap_err();
assert_eq!(kept.code, code);
assert_eq!(kept.message, "kept");
}
storage_barrier_outcome(Ok(STORAGE_BARRIER_DONE.into())).unwrap();
let unconfirmed = storage_barrier_outcome(Ok(String::new())).unwrap_err();
assert_eq!(unconfirmed.code, "graph_cleanup_uncertain");
}
}

/// The compiled `Healthcheck` to compare with a container's, accepting one created before
Expand Down
22 changes: 20 additions & 2 deletions scripts/lib/tla-runtime-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3984,11 +3984,12 @@ const contracts: readonly ModelContract[] = [
// pinned-relay (HACK-2711), no-cross-boot (HACK-2714), failed-only
// (01ab67fa: only a `failed-retained` lost start) and withhold-requested
// (#1253's message on the fixed runtime) restore one rule of the runtime or
// message before the VM-loss recovery fix.
// message before the VM-loss recovery fix. live-relay (HACK-2731) is
// #1273's message once ready, which ignored an unsettled relay startup.
// restart-recovers is the reachability witness of a recovered restart.
name: "foreground-loss-recovery",
module: "ForegroundLossRecovery",
states: 416,
states: 596,
invariant: "NoRefusedAdvice",
fields: ['outcome = "refused"', 'lostAt = "Preparing"'],
alternativeWitnesses: [['outcome = "refused"', 'lostAt = "Requested"']],
Expand Down Expand Up @@ -4092,6 +4093,23 @@ const contracts: readonly ModelContract[] = [
],
],
},
{
// HACK-2731 (#1273 review): the message once ready names
// `hack down --recover` for a run with no published port whose relay
// startup had not settled; the runtime refuses it
// (`relay_owner_refused`), since its no-route proof needs a settled
// relay.
name: "live-relay",
negative: true,
invariant: "NoRefusedAdvice",
fields: [
'outcome = "refused"',
"ports = FALSE",
"settled = FALSE",
'msg = "downUp"',
'lostAt = "GraphReady"',
],
},
{
// HACK-2714 (real VM, row 2): no cross-boot retirement of a start lost
// before ready, so the down keeps `runtime_not_running`.
Expand Down
Loading
Loading