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
8 changes: 0 additions & 8 deletions core/continuum-core/src/test_env/module_wiring_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
Expand All @@ -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
}

Expand All @@ -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(())
}
}
Expand All @@ -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<dyn std::error::Error>> {
const CHILD: &str = "CONTINUUM_ADOPTED_EXIT_FIXTURE";
Expand All @@ -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));
Expand All @@ -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(())
}
}
5 changes: 5 additions & 0 deletions core/continuum-engine/src/inference/llama_server/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub struct LlamaServerProcess {
pub(super) last_started: parking_lot::Mutex<Option<crate::inference::slots::EngineGeneration>>,
/// A signalled adopted predecessor stays fenced across timeout/cancellation.
pub(super) retiring_adopted: parking_lot::Mutex<Option<crate::inference::engine_residency::EngineIncarnation>>,
/// 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<Option<crate::inference::slots::PendingDiscard>>,
/// 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions core/continuum-engine/src/inference/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
14 changes: 13 additions & 1 deletion core/continuum-engine/src/inference/slots/engine_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)?;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions core/continuum-engine/src/inference/slots/kv_slot_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ pub struct EndpointSlots {
pub(super) paging_tasks: Mutex<tokio::task::JoinSet<()>>,
/// The read side of `EndpointState::ready`, for turns that hold through a transition.
pub(super) ready_rx: tokio::sync::watch::Receiver<bool>,
/// 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<DiscardLog>,
}

pub struct EndpointAdmission {
Expand Down
Loading
Loading