diff --git a/core/continuum-core/src/test_env/module_wiring_guard.rs b/core/continuum-core/src/test_env/module_wiring_guard.rs index 5c54a0438f..11f4a9e8cf 100644 --- a/core/continuum-core/src/test_env/module_wiring_guard.rs +++ b/core/continuum-core/src/test_env/module_wiring_guard.rs @@ -64,18 +64,10 @@ const UNWIRED: &[Unwired] = &[ module: "OptedInModule", why: "fixture: sibling of DefaultsModule, opts into every hook", }, - Unwired { - module: "PageFaultOnly", - why: "fixture: genome bus subscriber asserting fault-only delivery", - }, Unwired { module: "ReadyModule", why: "fixture: runtime readiness-gate test", }, - Unwired { - module: "RecorderModule", - why: "fixture: genome local_manager call recorder", - }, Unwired { module: "SlowJoiner", why: "fixture: a module that saves and then cannot be joined inside the phase bound — drives ModuleStopOutcome::JoinTimedOut, which before it existed only as a literal in assertions", diff --git a/core/continuum-engine/src/inference/llama_server/adopted_retirement.rs b/core/continuum-engine/src/inference/llama_server/adopted_retirement.rs index 329cf37a7a..f80d84efdf 100644 --- a/core/continuum-engine/src/inference/llama_server/adopted_retirement.rs +++ b/core/continuum-engine/src/inference/llama_server/adopted_retirement.rs @@ -23,23 +23,39 @@ impl LlamaServerProcess { return Err(LlamaServerError::Spawn("recorded live lane belongs to another endpoint".into())); } let incarnation = lane.incarnation(); + use crate::inference::slots::DiscardReason; + let endpoint = crate::inference::slots::directory().endpoint(&self.root); match incarnation.liveness() { - Liveness::Dead => return Ok(()), + Liveness::Dead => { + // Its residents' KV died with it; their next turns name this (card 6b28a445). + endpoint.pending_discard(DiscardReason::AdoptedEngineDead).commit(); + return Ok(()); + } Liveness::Unknown => return Err(LlamaServerError::Spawn("adopted engine identity is unverified; refusing retirement".into())), Liveness::Alive => {} } - let endpoint = crate::inference::slots::directory().endpoint(&self.root); - if !endpoint.paging_recovery_required() { + // Quarantined paging cannot save: its residents are captured now and recorded only + // when the engine is seen dead, so a superseded, refused or still-waiting retirement + // never reports a loss (card 6b28a445). + let unsaved = if endpoint.paging_recovery_required() { + Some(endpoint.pending_discard(DiscardReason::PagingUncertain)) + } else { transition.checkpoint_adopted_before_replacement( &self.client, &self.root, incarnation, current, ).await.map_err(LlamaServerError::Spawn)?; - } + None + }; if !current() { return Err(LlamaServerError::Superseded); } // A completed checkpoint is not authority to signal a reused PID. match incarnation.liveness() { - Liveness::Dead => return Ok(()), + Liveness::Dead => { + if let Some(unsaved) = unsaved { + unsaved.because(DiscardReason::AdoptedEngineDead).commit(); + } + return Ok(()); + } Liveness::Unknown => return Err(LlamaServerError::Spawn("adopted engine identity became unverified after checkpoint".into())), Liveness::Alive => {} } @@ -50,8 +66,10 @@ impl LlamaServerProcess { }, ).map_err(LlamaServerError::Spawn)?; // No await between signalling and retaining custody. Cancellation of the - // wait cannot turn this predecessor back into a serving candidate. + // wait cannot turn this predecessor back into a serving candidate. A signal is + // not a death: the residents' loss is recorded when the exit is observed. *self.retiring_adopted.lock() = Some(incarnation); + *self.retiring_discard.lock() = unsaved; self.await_adopted_exit(incarnation, Duration::from_secs(10)).await } @@ -78,6 +96,11 @@ impl LlamaServerProcess { and verifies readiness before reopening admission", incarnation.pid, incarnation.started_s )))??; *self.retiring_adopted.lock() = None; + // Its death is observed: the residents it held unsaved are now lost. + let discarded = self.retiring_discard.lock().take(); + if let Some(discarded) = discarded { + discarded.commit(); + } Ok(()) } } @@ -88,7 +111,9 @@ mod tests { use crate::inference::engine_residency::{EngineIncarnation, ProcessProbe, probe_process}; // Exercise the wait against a real isolated process. Cancellation and timeout - // retain custody; only its observed exit permits the next launch to proceed. + // retain custody; only its observed exit permits the next launch to proceed. The + // residents it held unsaved are recorded as lost at that observed exit, never while a + // cancelled or timed-out wait still holds custody (card 6b28a445). #[tokio::test] async fn adopted_exit_wait_retains_custody_until_observed_exit() -> Result<(), Box> { const CHILD: &str = "CONTINUUM_ADOPTED_EXIT_FIXTURE"; @@ -109,8 +134,14 @@ mod tests { return Err("fixture process identity unavailable".into()); }; let incarnation = EngineIncarnation { pid: child.id(), started_s, port: 0 }; - let process = LlamaServerProcess::with_root(format!("http://exit-fixture-{}", uuid::Uuid::new_v4())); + let root = format!("http://exit-fixture-{}", uuid::Uuid::new_v4()); + let process = LlamaServerProcess::with_root(root.clone()); *process.retiring_adopted.lock() = Some(incarnation); + let endpoint = crate::inference::slots::directory().endpoint(&root); + let resident = crate::inference::slots::PageKey::mind(uuid::Uuid::new_v4()).ok_or("non-nil id")?; + let lost = crate::inference::slots::DiscardReason::PagingUncertain; + *process.retiring_discard.lock() = + Some(crate::inference::slots::PendingDiscard::for_test(endpoint.clone(), vec![resident], lost)); { use std::future::Future; let wait = process.await_adopted_exit(incarnation, Duration::from_secs(10)); @@ -123,10 +154,14 @@ mod tests { assert_eq!(*process.retiring_adopted.lock(), Some(incarnation)); assert!(process.await_adopted_exit(incarnation, Duration::ZERO).await.is_err()); assert_eq!(*process.retiring_adopted.lock(), Some(incarnation)); + assert_eq!(endpoint.admit().await?.take_relaunch_discard(&resident), None, + "no loss is recorded while the wait still holds custody"); drop(child.stdin.take()); child.wait()?; process.await_adopted_exit(incarnation, Duration::from_secs(1)).await?; assert_eq!(*process.retiring_adopted.lock(), None); + assert_eq!(endpoint.admit().await?.take_relaunch_discard(&resident), Some(lost), + "the observed exit records the loss"); Ok(()) } } diff --git a/core/continuum-engine/src/inference/llama_server/process.rs b/core/continuum-engine/src/inference/llama_server/process.rs index 11eee9eff1..07064e04ca 100644 --- a/core/continuum-engine/src/inference/llama_server/process.rs +++ b/core/continuum-engine/src/inference/llama_server/process.rs @@ -30,6 +30,9 @@ pub struct LlamaServerProcess { pub(super) last_started: parking_lot::Mutex>, /// A signalled adopted predecessor stays fenced across timeout/cancellation. pub(super) retiring_adopted: parking_lot::Mutex>, + /// The residents that predecessor loses unsaved, recorded only once its exit is observed + /// (card 6b28a445). Held with `retiring_adopted`, so a re-entered wait still records it. + pub(super) retiring_discard: parking_lot::Mutex>, /// The LoRA genome set (sorted paths) the CURRENT child was launched with — /// the truthful record of what `/lora-adapters` holds, since llama.cpp has no /// API to query it. `ensure_model_serving` compares this against the desired @@ -133,6 +136,7 @@ impl LlamaServerProcess { pending_resource_reservation: parking_lot::Mutex::new(None), last_started: parking_lot::Mutex::new(None), retiring_adopted: parking_lot::Mutex::new(None), + retiring_discard: parking_lot::Mutex::new(None), served_adapters: Arc::new(StdMutex::new(Vec::new())), retained_page_dir: Arc::new(parking_lot::Mutex::new(None)), // THE host's live lane — pins the canonical port, owns the reclaim @@ -166,6 +170,7 @@ impl LlamaServerProcess { pending_resource_reservation: parking_lot::Mutex::new(None), last_started: parking_lot::Mutex::new(None), retiring_adopted: parking_lot::Mutex::new(None), + retiring_discard: parking_lot::Mutex::new(None), served_adapters: Arc::new(StdMutex::new(Vec::new())), retained_page_dir: Arc::new(parking_lot::Mutex::new(None)), // Ephemeral lane on its OWN scanned port: NOT the canonical live lane. diff --git a/core/continuum-engine/src/inference/slots.rs b/core/continuum-engine/src/inference/slots.rs index 10ea03cbea..8ff85da0a9 100644 --- a/core/continuum-engine/src/inference/slots.rs +++ b/core/continuum-engine/src/inference/slots.rs @@ -52,6 +52,9 @@ use saved_ledger::{LedgerSnapshot, LoadedLedger}; #[cfg(test)] use saved_ledger::{SavedLedgerFile, LEDGER_FORMAT, SAVED_LEDGER_FILE}; mod engine_generation; +mod relaunch_discard; +pub(crate) use relaunch_discard::{DiscardReason, PendingDiscard}; +use relaunch_discard::DiscardLog; pub use engine_generation::*; mod placement; pub use placement::*; diff --git a/core/continuum-engine/src/inference/slots/engine_generation.rs b/core/continuum-engine/src/inference/slots/engine_generation.rs index a531b7fbfa..84cb8bce49 100644 --- a/core/continuum-engine/src/inference/slots/engine_generation.rs +++ b/core/continuum-engine/src/inference/slots/engine_generation.rs @@ -31,6 +31,9 @@ impl EngineGeneration { // Do not mutate a ledger while an old HTTP future can still write // it. Replacement readiness drains admissions and replaces it. } + drop(state); + // A relaunch that could not save waited for this death to record its loss. + endpoint.relaunch_exit_observed(self.id); } } } @@ -275,7 +278,9 @@ impl EndpointTransition { /// Planned replacement cannot discard a healthy engine's unsaved residents. /// A terminal refusal resumes the exact original ledger; an uncertain write - /// stays quarantined. Dead engines and quarantined paging use recovery instead. + /// stays quarantined. Dead engines and quarantined paging use recovery instead: + /// nothing can be saved, so their unsaved residents are recorded as lost when this + /// generation's exit is observed, at once if it already was (card 6b28a445). pub(crate) async fn checkpoint_before_replacement( &mut self, client: &reqwest::Client, @@ -284,6 +289,12 @@ impl EndpointTransition { ) -> Result<(), String> { let generation = self.previous_generation().ok_or("replacement requires a known generation")?; if generation.has_exited() || self.endpoint.paging_recovery_required() { + let reason = if generation.has_exited() { + DiscardReason::EngineExited + } else { + DiscardReason::PagingUncertain + }; + self.endpoint.pending_discard(reason).on_exit_of(&generation); return Ok(()); } let original = self.capture_suspension(&generation)?; @@ -558,6 +569,7 @@ impl SlotDirectory { gate: Arc::new(tokio::sync::RwLock::new(())), paging_tasks: Mutex::new(tokio::task::JoinSet::new()), ready_rx, + discarded: Mutex::new(DiscardLog::default()), state: Mutex::new(EndpointState { ready, paging_uncertain: false, diff --git a/core/continuum-engine/src/inference/slots/kv_slot_pool.rs b/core/continuum-engine/src/inference/slots/kv_slot_pool.rs index bf0aeb0a0e..98826d24c0 100644 --- a/core/continuum-engine/src/inference/slots/kv_slot_pool.rs +++ b/core/continuum-engine/src/inference/slots/kv_slot_pool.rs @@ -459,6 +459,10 @@ pub struct EndpointSlots { pub(super) paging_tasks: Mutex>, /// The read side of `EndpointState::ready`, for turns that hold through a transition. pub(super) ready_rx: tokio::sync::watch::Receiver, + /// Residents a relaunch discarded unsaved, until their next turn takes the record + /// (card 6b28a445). On the endpoint because the pool does not outlive the engine; + /// retention is bounded by [`DiscardLog`]. + pub(super) discarded: Mutex, } pub struct EndpointAdmission { diff --git a/core/continuum-engine/src/inference/slots/relaunch_discard.rs b/core/continuum-engine/src/inference/slots/relaunch_discard.rs new file mode 100644 index 0000000000..f29e0f6253 --- /dev/null +++ b/core/continuum-engine/src/inference/slots/relaunch_discard.rs @@ -0,0 +1,196 @@ +//! Residents an engine relaunch discards, remembered until their next turn (card 6b28a445). +//! +//! A replacement saves residents first (#5348), but three paths cannot: the engine already +//! exited, paging is quarantined (a save could not be trusted), or an adopted engine is +//! already dead. Their slots' KV goes with the engine. The pool is rebuilt for the next +//! generation, so the record lives on the endpoint, and the resident's next turn takes it: +//! a cold turn then names the relaunch, instead of reading as a lost page or a ledger defect. +//! +//! Two steps, so a retirement that is superseded, refused, or still waiting never reports a +//! loss: the candidates are captured while the old pool is still installed +//! ([`PendingDiscard`]), and recorded only when the engine's death is OBSERVED. A sent +//! signal is not a death. An owned engine's capture waits on the endpoint for that +//! generation's [`EngineGeneration::observed_exit`]; an adopted engine's waits in the +//! process owner's retirement custody until its exact process is seen gone. + +use super::*; + +/// Why a relaunch discarded residents' unsaved KV. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum DiscardReason { + /// The owned engine exited before its replacement could save anything. + EngineExited, + /// Paging completion was uncertain, so the endpoint was quarantined and no save ran. + PagingUncertain, + /// The adopted engine's process was already gone when retirement looked. + AdoptedEngineDead, +} + +impl DiscardReason { + pub(crate) fn as_str(self) -> &'static str { + match self { + Self::EngineExited => "engine_exited", + Self::PagingUncertain => "paging_uncertain", + Self::AdoptedEngineDead => "adopted_engine_dead", + } + } +} + +/// The residents one relaunch loses, and why. +#[derive(Debug)] +struct Capture { + keys: Vec, + retain: usize, + reason: DiscardReason, +} + +impl Capture { + fn report(&self) { + continuum_base::probe!( + class = "inference.kv_page.discarded_by_relaunch", + reason = self.reason.as_str(), + residents = self.keys.len() as u64, + "an engine relaunch discarded residents' unsaved KV: their next turns prefill in full" + ); + } +} + +/// An owned generation's capture: waiting for its exit, or already recorded. +#[derive(Debug)] +enum Watch { + Awaiting(Capture), + Settled, +} + +/// The endpoint's discard records, oldest first. Retention is at most one pool's worth of +/// slots (the most recent discarding pool's count): one relaunch can discard no more minds +/// than it had slots, so the latest relaunch is always kept whole, and an older record is +/// evicted, oldest first, only by newer ones. An evicted mind's cold turn then reads as the +/// page store's answer, never as a relaunch it cannot be tied to. +#[derive(Debug, Default)] +pub(super) struct DiscardLog { + entries: std::collections::VecDeque<(PageKey, DiscardReason)>, + /// The owned generation whose relaunch captured residents, until its exit is observed. + /// One per endpoint: the next generation cannot start before this one's exit is verified. + watch: Option<(Uuid, Watch)>, +} + +impl DiscardLog { + fn record(&mut self, capture: &Capture) { + // Nothing lost records nothing: an empty capture never evicts older records. + if capture.keys.is_empty() { + return; + } + for key in &capture.keys { + self.entries.retain(|(held, _)| held != key); + self.entries.push_back((*key, capture.reason)); + } + while self.entries.len() > capture.retain.max(capture.keys.len()) { + self.entries.pop_front(); + } + } + + pub(super) fn take(&mut self, key: &PageKey) -> Option { + let at = self.entries.iter().position(|(held, _)| held == key)?; + self.entries.remove(at).map(|(_, reason)| reason) + } + + /// Hold `capture` until `generation`'s exit is observed. A generation already watched + /// (awaiting or settled) keeps its first capture, so a re-entered retirement never + /// records twice. + fn await_exit(&mut self, generation: Uuid, capture: Capture) { + if self.watch.as_ref().is_some_and(|(watched, _)| *watched == generation) { + return; + } + self.watch = Some((generation, Watch::Awaiting(capture))); + } + + /// `generation` was seen gone: record what its relaunch captured, once. + fn exit_observed(&mut self, generation: Uuid) -> Option { + match self.watch.take() { + Some((watched, Watch::Awaiting(capture))) if watched == generation => { + self.record(&capture); + self.watch = Some((generation, Watch::Settled)); + Some(capture) + } + other => { + self.watch = other; + None + } + } + } +} + +/// Residents a relaunch is about to discard, captured from the pool being replaced. Dropped +/// without being recorded (a superseded or refused retirement), it records nothing. +#[must_use = "a discard is recorded only when the engine's death is observed"] +pub(crate) struct PendingDiscard { + endpoint: Arc, + capture: Capture, +} + +impl PendingDiscard { + /// The same residents, lost for a different reason (the engine died before the signal). + pub(crate) fn because(mut self, reason: DiscardReason) -> Self { + self.capture.reason = reason; + self + } + + /// The engine's death was observed: record the loss and say so. + pub(crate) fn commit(self) { + self.capture.report(); + self.endpoint.discarded.lock().record(&self.capture); + } + + /// An owned engine: record once `generation`'s exit is observed, now if it already was. + pub(crate) fn on_exit_of(self, generation: &EngineGeneration) { + self.endpoint.discarded.lock().await_exit(generation.id, self.capture); + if generation.has_exited() { + self.endpoint.relaunch_exit_observed(generation.id); + } + } + + /// A test's capture of `keys` without a pool. + #[cfg(test)] + pub(crate) fn for_test(endpoint: Arc, keys: Vec, reason: DiscardReason) -> Self { + let retain = keys.len(); + Self { endpoint, capture: Capture { keys, retain, reason } } + } +} + +impl KvSlotPool { + /// The minds held in a slot without a confirmed save: what a relaunch now loses. A fork + /// dies with the core that ran it, so only minds, as in the ledger. + pub(super) fn unsaved_residents(&self) -> Vec { + // Lock order: `saved`, then `holders` (see `ledger_snapshot`). + let saved = self.saved.lock(); + let holders = self.holders.lock(); + holders.values().filter(|key| key.as_mind().is_some() && !saved.contains(key)).copied().collect() + } +} + +impl EndpointSlots { + /// Capture the residents the installed pool would lose if its engine went now. Nothing is + /// recorded until the caller commits, once the engine is actually gone. + pub(crate) fn pending_discard(self: &Arc, reason: DiscardReason) -> PendingDiscard { + let pool = self.state.lock().pool.as_ref().and_then(Clone::clone); + let (keys, retain) = pool.map_or((Vec::new(), 0), |pool| (pool.unsaved_residents(), pool.n_slots() as usize)); + PendingDiscard { endpoint: Arc::clone(self), capture: Capture { keys, retain, reason } } + } + + /// An owned generation's exit was observed: record what its relaunch captured, if any. + pub(super) fn relaunch_exit_observed(&self, generation: Uuid) { + let recorded = self.discarded.lock().exit_observed(generation); + if let Some(capture) = recorded { + capture.report(); + } + } +} + +impl EndpointAdmission { + /// Why a relaunch discarded `key`'s KV, if one did since its last turn. Taken once, so a + /// later cold turn is never blamed on an old relaunch. + pub(crate) fn take_relaunch_discard(&self, key: &PageKey) -> Option { + self.endpoint.discarded.lock().take(key) + } +} diff --git a/core/continuum-engine/src/inference/slots/tests.rs b/core/continuum-engine/src/inference/slots/tests.rs index c9888b2310..728247bfea 100644 --- a/core/continuum-engine/src/inference/slots/tests.rs +++ b/core/continuum-engine/src/inference/slots/tests.rs @@ -184,6 +184,91 @@ mod adopted_checkpoint; PageKey::mind(Uuid::from_u128(p)).expect("non-nil test id") } + // what this catches (card 6b28a445): a relaunch that cannot save (here, quarantined + // paging) lost residents' KV with no record, so their next cold turn read as a lost page; + // and, per Codex's review, a record made when the kill was SENT reports a loss that may + // not have happened. Through the real replacement path: nothing is recorded while the + // engine is only quarantined, even on re-entry; its observed exit records only the + // minds held without a confirmed save, once; a re-entry after the exit records nothing + // more; the record survives the pool's replacement and is taken exactly once. + #[tokio::test] + async fn a_relaunch_records_unsaved_residents_only_at_the_observed_exit_and_once() { + let dir = SlotDirectory { endpoints: dashmap::DashMap::new() }; + let endpoint = dir.endpoint("test://relaunch"); + let mut transition = endpoint.transition().await; + let generation = transition.start_generation().expect("first generation"); + let pool = Arc::new(KvSlotPool::new("test://relaunch", 4)); + pool.holders.lock().insert(0, mind(1)); + pool.holders.lock().insert(1, mind(2)); + pool.holders.lock().insert(2, key(3, 4)); + pool.note_saved(mind(2)); + endpoint.state.lock().pool = Some(Some(pool)); + endpoint.quarantine_paging(); + let client = reqwest::Client::new(); + + for _attempt in 0..2 { + transition + .checkpoint_before_replacement(&client, "test://relaunch", &|| true) + .await + .expect("quarantined paging has nothing to save"); + assert_eq!(endpoint.discarded.lock().take(&mind(1)), None, "the kill is not the death"); + } + generation.observed_exit(); + transition + .checkpoint_before_replacement(&client, "test://relaunch", &|| true) + .await + .expect("an exited engine has nothing to save"); + drop(transition); + // The next generation's pool replaces this one; the record is the endpoint's. + endpoint.state.lock().pool = Some(Some(Arc::new(KvSlotPool::new("test://relaunch", 4)))); + endpoint.state.lock().ready.send_replace(true); // the replacement verified ready + + let admission = endpoint.admit().await.expect("an open endpoint admits"); + assert_eq!(admission.take_relaunch_discard(&mind(1)), Some(DiscardReason::PagingUncertain)); + assert_eq!(admission.take_relaunch_discard(&mind(1)), None, "recorded once, taken once"); + assert_eq!(admission.take_relaunch_discard(&mind(2)), None, "a saved page restores; nothing was lost"); + assert_eq!(admission.take_relaunch_discard(&key(3, 4)), None, "a fork dies with its core anyway"); + } + + // what this catches (card 6b28a445, Codex's review): minds discarded by one relaunch that + // never return stayed recorded forever, across every later generation. Retention is one + // pool's worth of slots: the latest relaunch is kept whole, older records are evicted + // oldest first, and an empty capture evicts nothing. + #[tokio::test] + async fn discard_records_keep_one_pool_of_slots_across_generations() { + let dir = SlotDirectory { endpoints: dashmap::DashMap::new() }; + let endpoint = dir.endpoint("test://retention"); + let relaunch = |minds: &[u128]| { + let pool = Arc::new(KvSlotPool::new("test://retention", 3)); + for (slot, m) in minds.iter().enumerate() { + pool.holders.lock().insert(slot as u32, mind(*m)); + } + endpoint.state.lock().pool = Some(Some(pool)); + endpoint.pending_discard(DiscardReason::PagingUncertain).commit(); + }; + // One mind per relaunch, so "oldest" is defined: the first is evicted by the fourth. + for m in [1, 2, 3, 4] { + relaunch(&[m]); + } + { + let mut log = endpoint.discarded.lock(); + assert_eq!(log.take(&mind(1)), None, "oldest evicted first"); + for kept in [2, 3, 4] { + assert_eq!(log.take(&mind(kept)), Some(DiscardReason::PagingUncertain), "mind {kept} kept"); + } + } + relaunch(&[5, 6]); + relaunch(&[7, 8, 9]); // a whole pool of slots: the latest relaunch is kept whole + relaunch(&[]); // nothing lost evicts nothing + let mut log = endpoint.discarded.lock(); + for evicted in [5, 6] { + assert_eq!(log.take(&mind(evicted)), None, "mind {evicted} evicted by a newer relaunch"); + } + for kept in [7, 8, 9] { + assert_eq!(log.take(&mind(kept)), Some(DiscardReason::PagingUncertain), "mind {kept} kept"); + } + } + // regression for card 6102ac09 (BigMama, 2026-09-26 12:28Z): a turn that reached a // loading engine was refused instantly — 16 of Kimi's 26 requests in 90 min failed // inside a 90 s launch window, half of them on the cross-grid fallback. diff --git a/core/continuum-engine/src/inference/turn_admission.rs b/core/continuum-engine/src/inference/turn_admission.rs index c60a7ebe76..3cbb362774 100644 --- a/core/continuum-engine/src/inference/turn_admission.rs +++ b/core/continuum-engine/src/inference/turn_admission.rs @@ -390,22 +390,28 @@ async fn admit( admission.page_in = PageIn::Resident; } admission.uncommitted = Some((Arc::clone(pool), k, pg.slot)); + // Taken on every admission, so only the first turn after a relaunch is blamed on it. + let discarded = admission._endpoint.take_relaunch_discard(&k); if !pg.already_resident && !pg.restore { // Every fast-path miss is loud: this turn prefills from its first token. // With no page on disk that is a first visit; a page on disk the ledger does // not confirm (lost before a save finished, or a ledger that did not load) // is the defect class, never a quiet slower path. + // A relaunch that discarded this resident unsaved is the cause, whatever + // is on disk (card 6b28a445); otherwise the page store answers. let on_disk = pool.page_on_disk(&k); continuum_base::probe!( class = "inference.kv_page.cold_turn", page = %k, slot = pg.slot as u64, warm_only, - cause = match on_disk { - Some(true) => "page_on_disk_unconfirmed", - Some(false) => "no_page", - None => "no_page_dir", + cause = match (discarded, on_disk) { + (Some(_), _) => "discarded_by_relaunch", + (None, Some(true)) => "page_on_disk_unconfirmed", + (None, Some(false)) => "no_page", + (None, None) => "no_page_dir", }, + discard_reason = discarded.map_or("", crate::inference::slots::DiscardReason::as_str), "this page's slot holds none of its KV and no restorable page exists: it prefills in full" ); }