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
88 changes: 25 additions & 63 deletions core/continuum-academy/src/cognition/exam_serving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
//! explicit at the exam seam, and the LUDICROUS window-grow that gives a benchmark the
//! biggest window the model+machine allow.
//!
//! The living-persona benchmark used to grab a bare steady-hold and *assume* it was a
//! The living-persona benchmark used to grab a bare hold and *assume* it was a
//! co-tenant slot; the comment said "= `Placement::ShareLane`" but nothing computed it. This
//! module makes it real: it runs the model-aware admission kernel ([`plan_placement`]), and
//! for a share it drives the correct GROW → SETTLE → PIN sequence:
//! 1. **GROW** — declare LUDICROUS ([`ServingLudicrousHold`] → `PowerMode::Performance`), so
//! the daemon re-plans the shared lane to the biggest window the machine fits. Never a
//! starved boot-window (the 2048-eco incident).
//! 2. **SETTLE** — wait for any grow-relaunch to finish
//! ([`wait_for_serving_window_settle`](crate::inference::llama_server::wait_for_serving_window_settle)).
//! A naive "force Performance then run" thrashes: acquiring Ludicrous is itself a re-plan
//! → relaunch, and a relaunch mid-exam connection-refuses every generation (the reverted
//! `95dcec669`). Settling BEFORE the tasks run absorbs that relaunch once, up front.
//! 3. **PIN** — take the steady-hold so no FURTHER relaunch bounces the running exam.
//! for a share it declares LUDICROUS ([`ServingLudicrousHold`] → `PowerMode::Performance`) for
//! the exam's run. Nothing relaunches the engine for a window since 2026-11-03 (one launch, a
//! shared pool), so there is no grow-relaunch to absorb and no pin to hold; the exam's larger
//! window becomes a grant request (S2).
//! The verdict is CARRIED for observability + the curriculum ledger.
//!
//! The `SpawnLane`/`CpuSpill` arms are the rails a DIFFERENT-base exam or a grid placement
Expand All @@ -23,27 +17,17 @@
//! [[proctored-exam-session-dependable-benchmark]] [[serving-mode-follows-activity-ludicrous-to-dream]]
//! [[benchmark-window-must-be-big-not-a-clamped-prompt]] [[lane-admission-planner-scenario-driven]]

use std::time::Duration;

use crate::inference::serving_holds::{ServingLudicrousHold, ServingSteadyHold};
use crate::inference::serving_holds::ServingLudicrousHold;
use crate::resources::placement::{plan_placement, LaneDemand, Placement, ResidentLane};

/// How long to watch for a grow-relaunch to START (lane goes not-ready) after declaring
/// Ludicrous. Must EXCEED the serving daemon's 5s re-plan `TICK` so a relaunch has time to
/// fire; if none does in this window, the lane was already at the target window (no grow).
const LUDICROUS_SETTLE_GRACE: Duration = Duration::from_secs(8);

/// Bound for the whole grow-relaunch to finish (kill + respawn + model reload). A 24B reload
/// is tens of seconds; generous so a real grow always completes, but never hangs the exam.
const LUDICROUS_SETTLE_TIMEOUT: Duration = Duration::from_secs(180);

/// The verdict the exam ACQUIRE reached — carried for observability + the curriculum ledger,
/// so the strategic decision behind every measurement is inspectable.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ExamAcquire {
/// The exam base is already resident → she is measured as a co-tenant decode slot on the
/// live lane (`lane_id`), NO second weight copy. The lane is grown to LUDICROUS
/// (Performance → biggest window), settled, then held steady for the exam. The validated
/// (Performance → biggest window) and settled for the exam. The validated
/// single-GPU path. `reclaim` names any lower-tier lanes the daemon should tier down first
/// (empty in the common case).
SharedLane {
Expand Down Expand Up @@ -71,12 +55,10 @@ impl ExamAcquire {
}
}

/// The RAII holds a shared-lane exam binds for its whole run: LUDICROUS (serve at Performance)
/// + STEADY (no further relaunch). Both release together when the context drops, reverting
/// serving to the live pressure-adaptive mode.
/// The RAII hold a shared-lane exam binds for its whole run: LUDICROUS (serve at Performance).
/// It releases when the context drops, reverting serving to the live pressure-adaptive mode.
struct ExamHold {
_ludicrous: ServingLudicrousHold,
_steady: ServingSteadyHold,
}

/// A held exam serving context. While alive, a shared-lane exam serves at the biggest window
Expand Down Expand Up @@ -109,7 +91,7 @@ impl ExamServingContext {
pub async fn acquire(capacity: u64, resident: &[ResidentLane], demand: &LaneDemand) -> Self {
let acquire = Self::decide(capacity, resident, demand);
let hold = if matches!(acquire, ExamAcquire::SharedLane { .. }) {
Some(Self::grow_settle_pin().await)
Some(Self::grow_settle().await)
} else {
None
};
Expand All @@ -126,7 +108,7 @@ impl ExamServingContext {
}

/// The live serving inputs weren't resolvable (ungoverned host, model row missing, or the
/// lane isn't ready yet) — fall back to the share posture (grow → settle → pin) but MARK the
/// lane isn't ready yet) — fall back to the share posture (grow → settle) but MARK the
/// verdict `unresolved` so the gap is visible rather than silently assumed. The exam still
/// gets the biggest window; only the placement decision is recorded as "couldn't compute".
pub async fn ludicrous_fallback() -> Self {
Expand All @@ -139,31 +121,21 @@ impl ExamServingContext {
lane_id: "live(unresolved)".to_string(),
reclaim: Vec::new(),
},
_hold: Some(Self::grow_settle_pin().await),
_hold: Some(Self::grow_settle().await),
}
}

/// GROW (declare Ludicrous) → SETTLE (absorb any grow-relaunch) → PIN (steady-hold). The
/// Ludicrous hold is taken FIRST and kept, so `host_budget` plans at Performance for the
/// whole exam; the settle happens BEFORE the steady-hold so the pin lands on the grown,
/// stable lane — never on a lane about to relaunch.
async fn grow_settle_pin() -> ExamHold {
/// Declare Ludicrous for the exam: `host_budget` plans at Performance for its whole run.
/// Nothing relaunches the engine for a window since one launch (2026-11-03), so there is no
/// grow to wait for; the exam's larger window becomes a grant request (S2).
async fn grow_settle() -> ExamHold {
let ludicrous = ServingLudicrousHold::acquire();
let settled = crate::inference::llama_server::wait_for_serving_window_settle(
LUDICROUS_SETTLE_GRACE,
LUDICROUS_SETTLE_TIMEOUT,
)
.await;
continuum_base::probe!(
class = "exam.acquire.ludicrous",
settled_window = settled.unwrap_or(0),
settled = settled.is_some(),
"exam lane grown to Ludicrous (Performance) and settled before pinning"
"exam serving declared Ludicrous (Performance) for its run"
);
let steady = ServingSteadyHold::acquire("eval");
ExamHold {
_ludicrous: ludicrous,
_steady: steady,
}
}

Expand All @@ -181,7 +153,7 @@ impl ExamServingContext {
#[cfg(test)]
mod tests {
use super::*;
use crate::inference::serving_holds::{serving_held_steady, serving_ludicrous_active};
use crate::inference::serving_holds::serving_ludicrous_active;
use crate::resources::placement::DemandTier;

const GIB: u64 = 1 << 30;
Expand Down Expand Up @@ -267,43 +239,33 @@ mod tests {
assert!(matches!(v, ExamAcquire::CpuSpill { .. }));
}

// what this catches: the async ACQUIRE for a share holds BOTH Ludicrous and steady for the
// exam's lifetime and releases both on drop (RAII). With no live serving state the settle is
// a fast no-op, so this exercises the grow→settle→pin holds without a daemon. A spawn verdict
// holds nothing local. Guards the reverted-thrash regression: the exam pins the lane (steady)
// AND declares Ludicrous (Performance) — both, together.
// what this catches: the async ACQUIRE for a share holds Ludicrous for the exam's lifetime
// and releases it on drop (RAII). With no live serving state the settle is a fast no-op, so
// this exercises the grow→settle hold without a daemon. A spawn verdict holds nothing local.
#[tokio::test]
async fn share_acquire_holds_ludicrous_and_steady_then_releases_on_drop() {
async fn share_acquire_holds_ludicrous_then_releases_on_drop() {
// Spawn verdict first: holds nothing local, no global gauge touched.
let resident = [live_lane("devstral-24b")];
let spawn =
ExamServingContext::acquire(64 * GIB, &resident, &exam_demand("qwen-coder-32b")).await;
assert!(!spawn.holds(), "a spawn verdict holds no local grow/pin");
assert!(!spawn.holds(), "a spawn verdict holds no local grow");

// Share verdict (under memory pressure — a dedicated copy won't fit at 28 GiB, so the
// isolate demand falls back to a co-tenant share): grows Ludicrous + pins steady.
// isolate demand falls back to a co-tenant share): grows Ludicrous.
let ctx =
ExamServingContext::acquire(28 * GIB, &resident, &exam_demand("devstral-24b")).await;
assert!(
ctx.holds(),
"a shared-lane exam holds the grown, pinned lane"
"a shared-lane exam holds the grown lane"
);
assert!(
serving_ludicrous_active(),
"Ludicrous (Performance) is declared for the exam"
);
assert!(
serving_held_steady(),
"and the lane is pinned steady against further relaunch"
);
drop(ctx);
assert!(
!serving_ludicrous_active(),
"drop reverts to the pressure-adaptive mode (RAII)"
);
assert!(
!serving_held_steady(),
"drop releases the steady pin (RAII)"
);
}
}
6 changes: 2 additions & 4 deletions core/continuum-engine/src/inference/llama_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ pub use liveness::{

mod convergence_attempt;
mod reconcile;
mod shared_pool;
pub use reconcile::{ensure_model_serving, ensure_model_serving_if_current};
#[cfg(test)]
pub(crate) use reconcile::{grow_refused_by_memory_gate, lane_grow_would_narrow_the_window};

mod smoke;
use smoke::{
Expand Down Expand Up @@ -98,7 +97,6 @@ use engine_install::{
};
mod snapshot;
pub mod serving_hold;
use snapshot::SERVING_STATE;
pub use snapshot::{
await_ready_serving, await_snapshot_resettle, current_serving, has_reconciled,
install_serving_state, mark_first_reconcile, serving_state_receiver, MultimodalSupport,
Expand All @@ -108,7 +106,7 @@ mod vision;
pub use vision::vision_lane_ready;
use vision::{main_lane_mmproj_decision_for, MainLaneMmproj};
mod external;
pub use external::{external_serving_pin, probe_external_serving, wait_for_serving_window_settle};
pub use external::{external_serving_pin, probe_external_serving};

mod progress;
pub(crate) use progress::{
Expand Down
8 changes: 8 additions & 0 deletions core/continuum-engine/src/inference/llama_server/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ pub trait LlamaServerControl: Send + Sync {
None
}

/// Was the RUNNING engine launched on one shared KV pool (`--kv-unified`), read off its
/// own argv? An engine on fixed slots can change its slot count only by a relaunch, so
/// the reconcile moves it to the shared pool once. `None` = unknown (no live lane, argv
/// unreadable, a fake): an absence is not a mismatch.
fn launched_on_shared_pool(&self) -> Option<bool> {
None
}

/// Fingerprint of the server's `/slots` activity state (see
/// [`slots_activity_fingerprint_of`]). The health heartbeat compares the value
/// across two consecutive smoke-probe MISSES: changed → the serve loop is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ impl LlamaServerControl for LlamaServerProcess {
Some(crate::inference::lane_process::launch_kv_in(&argv))
}

fn launched_on_shared_pool(&self) -> Option<bool> {
let (_host, port) = split_host_port(&self.root);
let record = crate::inference::lane_registry::live_lane().filter(|r| r.port == port)?;
let argv = crate::inference::lane_process::command_args(record.pid)?;
Some(super::shared_pool::launched_on_shared_pool(&argv))
}

fn wedge_flag(&self) -> Option<crate::inference::wedge::WedgeFlag> {
self.wedge.clone()
}
Expand Down
36 changes: 0 additions & 36 deletions core/continuum-engine/src/inference/llama_server/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,39 +170,3 @@ pub async fn probe_external_serving(timeout: Duration) -> Option<ServingSnapshot
}


/// Wait until the served window has SETTLED after a serving-mode change that may have triggered
/// a grow-relaunch (e.g. an exam declaring Ludicrous/Performance). The caller must be able to
/// pin the lane WITHOUT bouncing in-flight work, so it must know the relaunch is DONE — not
/// merely that the lane was ready a moment ago (it may be about to relaunch on the next 5s plan
/// tick). Returns the settled per-slot window, or `None` on timeout / no serving state.
///
/// Two phases, watch-driven (no polling, no time-based stability guessing):
/// 1. Within `settle_grace` (must exceed the daemon's `TICK`, so a re-plan can fire), watch for
/// the lane to go NOT-ready — the signature of a relaunch. If it never does, no relaunch was
/// needed (the window was already at target) → return the current window immediately.
/// 2. A relaunch happened → wait (bounded by `timeout`) for the lane to come back decode-ready
/// at its new window.
pub async fn wait_for_serving_window_settle(
settle_grace: Duration,
timeout: Duration,
) -> Option<u32> {
let mut rx = SERVING_STATE.get()?.clone();
let start = std::time::Instant::now();
// Phase 1: did a relaunch start (lane went not-ready) within the grace window?
let relaunched = tokio::time::timeout(settle_grace, rx.wait_for(|s| !s.ready))
.await
.is_ok();
if !relaunched {
// No relaunch — the window was already at target. Return it if ready.
let s = rx.borrow_and_update();
return s.ready.then_some(s.served_context_window);
}
// Phase 2: wait for the relaunched lane to come back decode-ready. Bind the timeout result
// before matching so its `watch::Ref` temporary drops before `rx` does (else E0597).
let remaining = timeout.saturating_sub(start.elapsed());
let waited = tokio::time::timeout(remaining, rx.wait_for(|s| s.is_live())).await;
match waited {
Ok(Ok(guard)) => Some(guard.served_context_window),
_ => None,
}
}
3 changes: 2 additions & 1 deletion core/continuum-engine/src/inference/llama_server/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl LlamaServerProcess {
target.adapters.iter().map(|a| a.path.clone()).collect();
let expert_ot = target.expert_ot_value();

let mut invocation = crate::inference::lane_args::base_invocation(
let invocation = crate::inference::lane_args::base_invocation(
&gguf,
&target.model.id,
&host,
Expand Down Expand Up @@ -311,6 +311,7 @@ impl LlamaServerProcess {
max_ubatch: target.model.serving.max_ubatch,
reasoning_budget: target.model.serving.reasoning_budget,
});
let mut invocation = super::shared_pool::on_shared_pool(invocation);
// MoE glass-box env seam (#278): when expert paging is active, the DAEMON
// hands the fork its capture + plan file locations. Previously these envs
// existed only when an operator hand-exported them before booting the
Expand Down
Loading
Loading