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
2 changes: 2 additions & 0 deletions core/continuum-engine/src/inference/llama_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub use liveness::{
mod convergence_attempt;
mod reconcile;
mod shared_pool;
mod pool_growth;
pub use pool_growth::request_pool_growth;
pub use reconcile::{ensure_model_serving, ensure_model_serving_if_current};

mod smoke;
Expand Down
63 changes: 63 additions & 0 deletions core/continuum-engine/src/inference/llama_server/pool_growth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! ONE UPWARD RELAUNCH PER ENGINE, until the engine resizes its pool live (S2 DEBT, card e9724a7d).
//!
//! The engine launches once on a shared pool and is never relaunched for a window or lane change,
//! so whatever the launch reads is kept for the engine's life. Every launch reads a transient: on
//! the M5 on 2026-11-03 the cold boot plan gave 5 x 2,048 (b4be7bc59), the host's physical total
//! gave 5 x 262,144 at 91% memory pressure (590df4bc3), and the live budget sampled while the old
//! core's memory came back gave 16,640 (81aef1844). All three were rolled back. A launch cannot be
//! right by construction, so the plan's rule for every downward adaptation applies ("control both
//! ways"): the launched pool gets ONE scheduled upward test. When the first steady plan proves a
//! strictly larger pool, the serving daemon asks for it, and the next ensure relaunches into it,
//! once. Downward never relaunches. This bends the one-launch rule and goes when S2 lands.
//!
//! The daemon decides (it holds the plan and its budget); the engine's owner acts, as it does for
//! the shared-pool move and the engine convergence: a request keyed by the engine process it names.

/// The engine process the serving daemon has asked to grow, once. A request for any other process
/// is stale and never acts.
static REQUESTED: parking_lot::Mutex<Option<u32>> = parking_lot::Mutex::new(None);

/// Ask the engine owner to relaunch engine `pid` once into the larger pool its next target carries.
pub fn request_pool_growth(pid: u32) {
*REQUESTED.lock() = Some(pid);
}

/// Whether the running engine is due its one growth relaunch: the daemon asked for this process,
/// and the target's pool is strictly larger than what the process reports holding. Unknown (no
/// process, no reported pool) is never a growth.
pub(super) fn growth_due(running_pid: Option<u32>, running_pool: Option<u32>, target_pool: u64) -> bool {
let (Some(pid), Some(running)) = (running_pid, running_pool) else { return false };
*REQUESTED.lock() == Some(pid) && target_pool > u64::from(running)
}

/// The growth was decided for `pid`: the request is spent, so a failed or partial relaunch never
/// loops. The next engine process starts with no request.
pub(super) fn spend(pid: u32) {
let mut requested = REQUESTED.lock();
if *requested == Some(pid) {
*requested = None;
}
}

#[cfg(test)]
mod tests {
use super::*;

// what this catches: the bridge relaunching more than once, downward, or for a process it
// was not asked about. One request names one process; it acts only while the target is larger
// and only until it is spent.
#[test]
fn an_engine_grows_once_upward_and_only_when_asked() {
// A pid no other test in this binary uses.
let pid = 4_000_000_001;
assert!(!growth_due(Some(pid), Some(16_640), 257_536), "never asked: no growth");
request_pool_growth(pid);
assert!(!growth_due(Some(pid + 1), Some(16_640), 257_536), "asked for another process: stale");
assert!(!growth_due(Some(pid), Some(257_536), 257_536), "not strictly larger: no relaunch");
assert!(!growth_due(Some(pid), Some(300_000), 257_536), "downward never relaunches");
assert!(!growth_due(Some(pid), None, 257_536), "an unknown running pool is never a growth");
assert!(growth_due(Some(pid), Some(16_640), 257_536), "asked, and the target is larger: grow");
spend(pid);
assert!(!growth_due(Some(pid), Some(16_640), 257_536), "spent: once per engine");
}
}
24 changes: 21 additions & 3 deletions core/continuum-engine/src/inference/llama_server/reconcile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ async fn serve_or_adopt<C: LlamaServerControl + ?Sized>(
true
}
};
// THE POOL'S ONE UPWARD TEST (S2 debt, `pool_growth`): the daemon asked this engine
// process to grow, and the target's pool is strictly larger than the one it reports
// holding. Decided once per process; downward never relaunches.
let running_pid = ctrl.served_incarnation().map(|engine| engine.pid);
let running_pool = ctrl.served_pool_tokens().await.ok();
let target_pool = u64::from(target.context_window) * u64::from(target.lanes);
let grow_ok = !super::pool_growth::growth_due(running_pid, running_pool, target_pool);
if let (false, Some(pid)) = (grow_ok, running_pid) {
super::pool_growth::spend(pid);
continuum_base::probe!(target: "continuum_core::inference::llama_server", class = "serving.pool.grow",
model = target.model_id(),
pid = u64::from(pid),
from_tokens = running_pool.map_or(0, u64::from), // map_or: grow_ok=false implies the pool is known
to_tokens = target_pool,
"the first steady plan proves a larger pool than this engine launched with: relaunching once into it (S2 debt)"
);
}
// THE ENGINE ITSELF — the fourth operand (card 7c5f139d). A deploy installs the
// engine the pin names (install-llama-server.sh, stamp-gated, atomic), but every
// deploy leaves the lane up for the next core, so an adopted lane keeps running
Expand Down Expand Up @@ -251,20 +268,21 @@ async fn serve_or_adopt<C: LlamaServerControl + ?Sized>(
onto the installed binary"
);
}
if !engine_ok || !sight_ok || !kv_ok || !pool_ok {
if !engine_ok || !sight_ok || !kv_ok || !pool_ok || !grow_ok {
continuum_base::probe!(target: "continuum_core::inference::llama_server", class = "serving.relaunch",
model = target.model_id(),
engine_ok,
sight_ok,
kv_ok,
pool_ok,
grow_ok,
planned_kv = %planned_kv.cache_type,
planned_flash_attn = planned_kv.flash_attn,
running_kv = running_kv.as_ref().map(|r| r.cache_type_or_default().to_string()).unwrap_or_default(), // unwrap_or_default: "" = the running decision is unknown (no live argv); kv_ok is then true
running_flash_attn = running_kv.as_ref().map(|r| r.flash_attn).unwrap_or(false), // unwrap_or: unknown reads false alongside the empty type above
"the running engine is not the one a launch would start now (its binary, its \
sight, its KV decision, or a cache not yet on the shared pool) — relaunching \
once; a window or lane change never relaunches",
sight, its KV decision, a cache not yet on the shared pool, or its one upward \
pool test) — relaunching once; a window or lane change never relaunches",
);
// fall through to relaunch on the installed binary, with eyes, on the decided
// cache type, on the shared pool.
Expand Down
5 changes: 5 additions & 0 deletions core/continuum-serving/src/modules/serving_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ pub struct ServingDaemonModule {
/// 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>,
/// The engine process the one upward pool relaunch was asked for (`pool_growth`): once per
/// engine, S2 debt.
pool_growth_tried: Arc<std::sync::atomic::AtomicU64>,
/// Each local mind's grant on the engine's pool (`grants.rs`): what her binding follows.
/// `None` until a ready engine has been granted from.
grants_tx: watch::Sender<Option<crate::capacity::window_grant::PoolGrants>>,
Expand Down Expand Up @@ -550,6 +553,7 @@ impl ServingDaemonModule {
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)),
pool_growth_tried: Arc::new(std::sync::atomic::AtomicU64::new(0)),
grants_tx: watch::channel(None).0,
shared_pool_of: Arc::new(parking_lot::Mutex::new(None)),
served_pool: Arc::new(std::sync::atomic::AtomicU32::new(0)),
Expand Down Expand Up @@ -678,6 +682,7 @@ mod launch;
mod planning;
mod grants;
mod hold;
mod pool_growth;
mod reconcile;
mod tick;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl ServingDaemonModule {
/// everything else on the node. Never the host's physical total (590df4bc3 sized the M5 at
/// 5 x 262,144 from it: memory pressure 91%, 5.6 GB available, no resident hosted; rolled back)
/// and never a cold boot's first-tick fallback plan, which planning no longer publishes.
fn engine_pool(&self, model: &crate::model_registry::types::Model, served_ctx: u32, lanes: u32) -> (u32, u32) {
pub(super) 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).max(1);
let pool = launch_pool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ impl ServingDaemonModule {
// boot over an inherited lane, #438) the ledger has nothing to add back, and the
// plan's own credit is the one that keeps the successor from fleeing its
// predecessor onto a smaller model. One credit, whichever layer holds the fact.
let ledger_credited = self.resource_daemon.board().attributions.iter().any(|a| {
a.consumer_id == SERVING_CONSUMER_ID && a.kind == serving_pool_kind() && a.bytes > 0
});
let ledger_credited = self.serving_footprint_reported();
if !ledger_credited {
// The boot planner adds incumbent bytes after this snapshot. That
// enlarged budget no longer proves these leases were excluded.
Expand Down
74 changes: 74 additions & 0 deletions core/continuum-serving/src/modules/serving_daemon/pool_growth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//! The serving daemon's side of the pool's ONE UPWARD TEST (S2 DEBT, card e9724a7d; the engine's
//! side and the full story are `llama_server::pool_growth`). The launch reads a transient and one
//! launch keeps its pool (three rollbacks on the M5, 2026-11-03), so the first STEADY plan, whose
//! budget was sampled after the engine is up with its own footprint credited back once, re-sizes
//! the pool by the same `launch_pool` the launch used. When that proves a strictly larger pool than
//! the engine reports holding, the daemon asks for one relaunch into it; never twice per engine
//! process, never downward. Goes when the engine resizes live (S2).
use super::*;

impl ServingDaemonModule {
/// Whether serving has reported its own footprint to the board: the plan's budget is then the
/// ledger's replace-myself budget, sampled with this engine up and credited back exactly once.
/// The ONE reading of "steady" (planning's `at_rest` arm reads it too).
pub(super) fn serving_footprint_reported(&self) -> bool {
self.resource_daemon
.board()
.attributions
.iter()
.any(|a| a.consumer_id == SERVING_CONSUMER_ID && a.kind == serving_pool_kind() && a.bytes > 0)
}

/// Whether the running engine is due its one upward pool relaunch, asking the engine's owner
/// for it when it is. Read on the ready tick, beside the shared-pool move.
pub(super) fn pool_growth_due(&self, desired: &str, served_ctx: u32, lanes: u32) -> bool {
let Some(engine) = self.server.served_incarnation() else { return false };
if self.pool_growth_tried.load(Ordering::Relaxed) == u64::from(engine.pid) {
return false;
}
let Some(model) = (self.model_resolver)(desired) else { return false };
let running = self.served_pool.load(Ordering::Relaxed);
let (per_slot, sequences) = self.engine_pool(&model, served_ctx, lanes);
let wanted = u64::from(per_slot) * u64::from(sequences);
let budget = self.plan_budget_bytes.load(Ordering::Relaxed);
if !grows(self.serving_footprint_reported(), budget, running, wanted) {
return false;
}
self.pool_growth_tried.store(u64::from(engine.pid), Ordering::Relaxed);
crate::inference::llama_server::request_pool_growth(engine.pid);
continuum_base::probe!(
target: "continuum_core::modules::serving_daemon", class = "serving.pool.grow_due",
pid = u64::from(engine.pid),
running_tokens = u64::from(running),
wanted_tokens = wanted,
budget_gb = budget / 1_000_000_000,
"the first steady plan proves a larger pool than the engine launched with: one relaunch into it (S2 debt)"
);
true
}
}

/// PURE: whether a steady plan proves the pool should grow. Steady (serving's footprint reported,
/// so the budget was sampled with the engine up), a sampled budget, a known running pool, and a
/// wanted pool strictly larger. Equal or smaller never relaunches.
pub(super) fn grows(steady: bool, budget_bytes: u64, running_tokens: u32, wanted_tokens: u64) -> bool {
steady && budget_bytes > 0 && running_tokens > 0 && wanted_tokens > u64::from(running_tokens)
}

#[cfg(test)]
mod tests {
use super::grows;

// what this catches (the M5 2026-11-03, 81aef1844: a 16,640 pool launched from a boot-time
// transient and kept): a pool that never grows from a bad launch, or a bridge that relaunches
// when it should not. Only a steady plan with a sampled budget grows it, only upward.
#[test]
fn only_a_steady_plan_grows_the_pool_and_only_upward() {
assert!(grows(true, 23_000_000_000, 16_640, 257_536), "the 81aef1844 case: steady, larger -> grow");
assert!(!grows(false, 23_000_000_000, 16_640, 257_536), "not steady (the boot ticks): never");
assert!(!grows(true, 0, 16_640, 257_536), "no sampled budget: never");
assert!(!grows(true, 23_000_000_000, 0, 257_536), "the running pool unknown: never");
assert!(!grows(true, 23_000_000_000, 257_536, 257_536), "equal: no relaunch");
assert!(!grows(true, 23_000_000_000, 1_310_720, 257_536), "downward never relaunches (590df4bc3's pool stays)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl ServingDaemonModule {
&& live.active_model.as_deref() == Some(desired.as_str())
&& live.adapters == desired_adapter_paths
&& !self.shared_pool_move_due(&live.base_url)
&& !self.pool_growth_due(&desired, served_ctx, lanes)
{
// The lanes this hour served: the health window's maximum (the lane-bound rest
// stands on it).
Expand Down
Loading