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
1 change: 1 addition & 0 deletions core/continuum-engine/src/inference/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use saved_ledger::{LedgerSnapshot, LoadedLedger};
#[cfg(test)]
use saved_ledger::{SavedLedgerFile, LEDGER_FORMAT, SAVED_LEDGER_FILE};
mod engine_generation;
mod adopted_replacement;
mod relaunch_discard;
pub(crate) use relaunch_discard::{DiscardReason, PendingDiscard};
use relaunch_discard::DiscardLog;
Expand Down
25 changes: 25 additions & 0 deletions core/continuum-engine/src/inference/slots/adopted_replacement.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Whether an ADOPTED engine can be replaced now without losing its minds' KV. A core that
//! adopts the engine a previous core left running learns its slot pool and saved ledger only
//! after it starts serving it; until then `checkpoint_adopted_before_replacement` refuses, and
//! a replacement asked for at boot (the one move onto the shared pool, 2026-11-03 04:22Z on the
//! M5: "adopted checkpoint requires a known pool") is handed back. This is that refusal's
//! precondition as one read, so the serving owner asks again exactly when it can succeed.

use super::SlotDirectory;

impl SlotDirectory {
/// The adopted engine at `root` could be checkpointed before a replacement: its pool is
/// known with a verified ledger, no generation of this core owns it, and its paging is
/// certain. An engine this core launched itself owns a generation and answers false.
pub fn adopted_replacement_ready(&self, root: &str) -> bool {
let endpoint = self.endpoint(root);
let state = endpoint.state.lock();
state.generation.is_none()
&& !state.paging_uncertain
&& state
.pool
.as_ref()
.and_then(Option::as_ref)
.is_some_and(|pool| pool.ledger.get().is_some())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ async fn a_refused_adopted_replacement_hands_the_endpoint_back_as_found() -> Res
assert!(!endpoint.is_ready());
Ok(())
}

// what this catches: the serving owner asking to replace an adopted engine before its pool can
// be checkpointed (refused and handed back, and never asked again: the M5 2026-11-03 04:22Z
// stayed on fixed slots), or treating a pool with no verified ledger as ready.
#[test]
fn an_adopted_replacement_is_ready_only_once_its_pool_and_ledger_are_known() -> Result<(), Box<dyn std::error::Error>> {
let root = format!("test://adopted-ready-{}", Uuid::new_v4());
assert!(!directory().adopted_replacement_ready(&root), "no pool known yet");
let pool = directory().ensure_pool(&root, 3);
assert!(!directory().adopted_replacement_ready(&root), "a pool without a verified ledger");
let process = crate::inference::engine_residency::EngineIncarnation::of(std::process::id(), 1)
.ok_or("fixture process identity unavailable")?;
let pages = tempfile::tempdir()?;
// A fresh adoption has no prior pages, and installs an empty ledger stamped with the engine.
let _ = adopt_engine_ledger(&pool, pages.path(), process.pid, process.started_s);
assert!(directory().adopted_replacement_ready(&root), "pool and ledger known: a checkpoint can run");
Ok(())
}
8 changes: 8 additions & 0 deletions core/continuum-serving/src/modules/serving_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ pub struct ServingDaemonModule {
/// asked for divides every mind's window for nothing (the 4-slots-for-2-
/// personas starvation, 2026-07-10). Default 1 — window-first.
lane_demand: Arc<std::sync::atomic::AtomicU32>,
/// The usable bytes the last plan sized against: the budget the one launch lays its pool
/// out on, so the engine holds the memory the planner just proved it may.
plan_budget_bytes: Arc<std::sync::atomic::AtomicU64>,
/// The engine process this core last asked to move onto the shared pool: one try per
/// engine, so a refused move is never retried every tick.
shared_pool_move_tried: Arc<std::sync::atomic::AtomicU64>,

/// L10 (#438): consecutive plan ticks wanting a DIFFERENT base model than the
/// ready incumbent, and which model that was. A model swap re-homes every
Expand Down Expand Up @@ -537,6 +543,8 @@ impl ServingDaemonModule {
pin_store,
intent,
lane_demand: Arc::new(std::sync::atomic::AtomicU32::new(1)),
plan_budget_bytes: Arc::new(std::sync::atomic::AtomicU64::new(0)),
shared_pool_move_tried: Arc::new(std::sync::atomic::AtomicU64::new(0)),
model_change_streak: Arc::new(std::sync::atomic::AtomicU32::new(0)),
pending_model_change: Arc::new(std::sync::Mutex::new(None)),
serving_hold: Arc::new(parking_lot::Mutex::new(None)),
Expand Down
48 changes: 15 additions & 33 deletions core/continuum-serving/src/modules/serving_daemon/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,24 @@ impl ServingDaemonModule {
/// The engine's one KV pool, sized ONCE when the engine starts and never by a relaunch, as
/// `(per-sequence tokens, sequences)` so `-c` is the pool and `--parallel` the ceiling.
///
/// The sequences: every seated mind, the minds leased in from other nodes at the last plan,
/// and the scratch traffic beside them. The pool: what serving may hold AT REST (the
/// physical budget at the current mode, less every other consumer's measured residency on
/// the board, less the prompt cache's grant where it is the same memory), laid out by the
/// plan's own arithmetic, so each sequence fits its compute and never exceeds the trained
/// window. Not the live plan budget, which counts the outgoing engine against itself, and
/// not the cold plan's window x lanes, which was 1 x 80k on a boot that counted two
/// residents (the M5, 2026-11-03 00:52Z). A model with no measured footprint has no fit,
/// so its sequences take the plan's window: a fit, not a constant.
fn engine_pool(
&self,
model: &crate::model_registry::types::Model,
served_ctx: u32,
lanes: u32,
host_prompt_cache_mib: u32,
) -> (u32, u32) {
/// The sequences: every seated mind, the minds leased in at the last plan, and the scratch
/// traffic beside them. Each is laid out on the budget the last plan sized against, by the
/// plan's own arithmetic, so the engine holds the memory the planner proved it may: on the
/// M5, 5 x 69,376, the geometry the planner gave the fixed-slot engine. Sizing it instead
/// from the physical budget less every board holder gave 5 x 36,505 (2026-11-03 04:23Z,
/// backed out at once), and from the cold plan's window x lanes 1 x 80k. The shared pool's
/// saving (one compute graph, not one per sequence) comes as a measured gain, not here. A
/// model with no measured footprint, or no plan yet, keeps the plan's total (window x lanes)
/// shared over the sequences: an unmeasured model is where over-allocating is least safe.
fn engine_pool(&self, model: &crate::model_registry::types::Model, served_ctx: u32, lanes: u32) -> (u32, u32) {
let leased_in = LAST_LEASED_IN_PEAK.load(Ordering::Relaxed);
let sequences = self.seated().saturating_add(1).saturating_add(leased_in).max(lanes);
let kind = serving_pool_kind();
let others: u64 = self
.resource_daemon
.board()
.attributions
.iter()
.filter(|a| a.consumer_id != SERVING_CONSUMER_ID && a.kind == kind)
.map(|a| a.bytes)
.sum();
let cache = match self.system.gpu_memory_mode() {
Some(crate::gpu::monitor::MemoryMode::Unified) => u64::from(host_prompt_cache_mib) << 20,
_ => 0,
};
let at_rest = self.physical_budget().usable_bytes.saturating_sub(others).saturating_sub(cache);
let fitted = footprint_for(model).map(|fp| fp.window_within(at_rest, sequences));
let budget = self.plan_budget_bytes.load(Ordering::Relaxed);
let fitted = footprint_for(model).map(|fp| fp.window_within(budget, sequences));
let per_sequence = match fitted.filter(|tokens| *tokens > 0) {
Some(tokens) => tokens,
None => served_ctx,
None => u32::try_from(u64::from(served_ctx) * u64::from(lanes) / u64::from(sequences.max(1)))
.unwrap_or(served_ctx), // unwrap_or: lanes <= sequences, so the share is at most served_ctx
};
(per_sequence, sequences)
}
Expand Down Expand Up @@ -161,7 +143,7 @@ impl ServingDaemonModule {
// separates "a bit small" from "structurally cannot cache anything".
let one_conversation_mib = prompt_cache.one_conversation_mib;
let host_prompt_cache_mib = prompt_cache.mib;
let (per_sequence, sequences) = self.engine_pool(&model, served_ctx, lanes, host_prompt_cache_mib);
let (per_sequence, sequences) = self.engine_pool(&model, served_ctx, lanes);
let target = ServingTarget {
host_prompt_cache_mib,
model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl ServingDaemonModule {
on_disk: &[ModelFootprint], intent_revision: u64,
leases: &[crate::resources::lease::ResourceLease],
) {
self.plan_budget_bytes.store(budget.usable_bytes, Ordering::Relaxed);
// Hysteresis: pass the currently-served model as the incumbent so a
// transient free-memory dip doesn't thrash the served model.
//
Expand Down
30 changes: 30 additions & 0 deletions core/continuum-serving/src/modules/serving_daemon/reconcile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@ impl ServingDaemonModule {

/// against together, so a stale high can never make a later climb read as flat.

/// An ADOPTED engine on fixed slots moves to the shared pool once its pool can be
/// checkpointed: a core that adopts the engine its predecessor left learns the slot pool
/// only after serving it, so the move asked for at boot is refused and handed back ("adopted
/// checkpoint requires a known pool", the M5 2026-11-03 04:22Z), and a ready lane never
/// re-enters the launch path on its own. One try per engine process; the check is one lock
/// per tick until the pool is known, and the argv is read once.
fn shared_pool_move_due(&self, base_url: &str) -> bool {
let endpoint = crate::ai::openai_endpoints::OpenAiBase::new(base_url);
if !crate::inference::slots::directory().adopted_replacement_ready(endpoint.root()) {
return false;
}
let Some(engine) = self.server.served_incarnation() else {
return false;
};
let pid = u64::from(engine.pid);
if self.shared_pool_move_tried.swap(pid, Ordering::Relaxed) == pid {
return false;
}
let due = self.server.launched_on_shared_pool() == Some(false);
if due {
continuum_base::probe!(
target: "continuum_core::modules::serving_daemon", class = "serving.pool.move",
pid,
"an adopted engine on fixed slots can now be checkpointed: moving it onto the shared pool, once"
);
}
due
}

pub(super) fn reconcile_to_plan(&self) -> Option<JoinHandle<()>> {
let operation = match ServingOperation::acquire(
self.reconciling.clone(),
Expand Down Expand Up @@ -322,6 +351,7 @@ impl ServingDaemonModule {
if live.ready
&& live.active_model.as_deref() == Some(desired.as_str())
&& live.adapters == desired_adapter_paths
&& !self.shared_pool_move_due(&live.base_url)
{
// The lanes this hour served: the health window's maximum (the lane-bound rest
// stands on it).
Expand Down
Loading