From f557a9ecd32cad0319d537df18584fd99c7ae414 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Mon, 2 Nov 2026 22:44:13 -0600 Subject: [PATCH 1/2] One launch, made reliable: the pool is sized on the planner's own budget, and an adopted engine moves to it once it can be checkpointed The M5, 2026-11-03 04:03-04:28Z, after #5720 deployed: - The new core adopted the running fixed-slot engine. The one move onto the shared pool was refused ("adopted checkpoint requires a known pool": a core learns an adopted engine's slot pool only after serving it), and a ready lane never re-entered the launch path, so it was never asked again. - Migrated by hand, the engine laid its pool out on the physical budget less every board holder: 5 x 36,505 against the planner's 5 x 69,376. Backed out to 2c0d45ca0 at once. - `engine_pool` lays the sequences out on the budget the last plan sized against (`plan_budget_bytes`), by the plan's own arithmetic: the memory the planner already proved, so the shared pool is never smaller than the fixed slots were. - `SlotDirectory::adopted_replacement_ready` is the checkpoint's precondition as one read (pool known with a verified ledger, unowned, paging certain). - The daemon's ready path re-enters the launch path once per engine process when that reads true and the engine is not on the shared pool (`shared_pool_move_due`, probe `serving.pool.move`): one lock per tick until then, the argv read once. Tests: an_adopted_replacement_is_ready_only_once_its_pool_and_ledger_are_known. Engine 1400, serving 133; workspace check and ratchets clean. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- core/continuum-engine/src/inference/slots.rs | 1 + .../inference/slots/adopted_replacement.rs | 25 +++++++++++ .../slots/tests/adopted_checkpoint.rs | 18 ++++++++ .../src/modules/serving_daemon.rs | 8 ++++ .../src/modules/serving_daemon/launch.rs | 44 +++++-------------- .../src/modules/serving_daemon/planning.rs | 1 + .../src/modules/serving_daemon/reconcile.rs | 30 +++++++++++++ 7 files changed, 95 insertions(+), 32 deletions(-) create mode 100644 core/continuum-engine/src/inference/slots/adopted_replacement.rs diff --git a/core/continuum-engine/src/inference/slots.rs b/core/continuum-engine/src/inference/slots.rs index f63358d6cd..3ef94c3b7e 100644 --- a/core/continuum-engine/src/inference/slots.rs +++ b/core/continuum-engine/src/inference/slots.rs @@ -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; diff --git a/core/continuum-engine/src/inference/slots/adopted_replacement.rs b/core/continuum-engine/src/inference/slots/adopted_replacement.rs new file mode 100644 index 0000000000..59cf3c2a55 --- /dev/null +++ b/core/continuum-engine/src/inference/slots/adopted_replacement.rs @@ -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()) + } +} diff --git a/core/continuum-engine/src/inference/slots/tests/adopted_checkpoint.rs b/core/continuum-engine/src/inference/slots/tests/adopted_checkpoint.rs index 28c2bbfdae..feb98b9a4e 100644 --- a/core/continuum-engine/src/inference/slots/tests/adopted_checkpoint.rs +++ b/core/continuum-engine/src/inference/slots/tests/adopted_checkpoint.rs @@ -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> { + 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(()) +} diff --git a/core/continuum-serving/src/modules/serving_daemon.rs b/core/continuum-serving/src/modules/serving_daemon.rs index 5aa28e8b01..d92f2ccecc 100644 --- a/core/continuum-serving/src/modules/serving_daemon.rs +++ b/core/continuum-serving/src/modules/serving_daemon.rs @@ -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, + /// 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, + /// 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, /// 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 @@ -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)), diff --git a/core/continuum-serving/src/modules/serving_daemon/launch.rs b/core/continuum-serving/src/modules/serving_daemon/launch.rs index 2fa593ec26..35e635c1c5 100644 --- a/core/continuum-serving/src/modules/serving_daemon/launch.rs +++ b/core/continuum-serving/src/modules/serving_daemon/launch.rs @@ -19,39 +19,19 @@ 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, takes the plan's window. + 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, @@ -161,7 +141,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, diff --git a/core/continuum-serving/src/modules/serving_daemon/planning.rs b/core/continuum-serving/src/modules/serving_daemon/planning.rs index 5da370b7b5..ef831c3aa3 100644 --- a/core/continuum-serving/src/modules/serving_daemon/planning.rs +++ b/core/continuum-serving/src/modules/serving_daemon/planning.rs @@ -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. // diff --git a/core/continuum-serving/src/modules/serving_daemon/reconcile.rs b/core/continuum-serving/src/modules/serving_daemon/reconcile.rs index 3e2c9f4760..1e371b3980 100644 --- a/core/continuum-serving/src/modules/serving_daemon/reconcile.rs +++ b/core/continuum-serving/src/modules/serving_daemon/reconcile.rs @@ -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> { let operation = match ServingOperation::acquire( self.reconciling.clone(), @@ -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). From b97e9ee6e6e3a1fadb29d739f55b6c5c1a72bb15 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Tue, 3 Nov 2026 01:16:47 -0600 Subject: [PATCH 2/2] An unmeasured model keeps the plan's total shared over the engine's sequences (Cormac on #5721) A model with no measured footprint took served_ctx per sequence; with sequences > lanes that pool exceeded what the plan proved. It now takes served_ctx x lanes / sequences. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- core/continuum-serving/src/modules/serving_daemon/launch.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/continuum-serving/src/modules/serving_daemon/launch.rs b/core/continuum-serving/src/modules/serving_daemon/launch.rs index 35e635c1c5..87c3ac8025 100644 --- a/core/continuum-serving/src/modules/serving_daemon/launch.rs +++ b/core/continuum-serving/src/modules/serving_daemon/launch.rs @@ -26,7 +26,8 @@ impl ServingDaemonModule { /// 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, takes the plan's window. + /// 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); @@ -34,7 +35,8 @@ impl ServingDaemonModule { 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) }