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
20 changes: 11 additions & 9 deletions core/continuum-serving/src/modules/serving_daemon/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ impl ServingDaemonModule {
/// window is her grant from her measured requirement (`grants.rs`), and under `--kv-unified`
/// any one sequence may grow into the whole pool. The sequences are every seated mind, the
/// minds leased in at the last plan, and the scratch traffic, so seating never relaunches.
/// The size is [`launch_pool`] at the host's PHYSICAL budget, never the plan's live one.
/// The size is [`launch_pool`] at the published plan's LIVE budget: what memory holds now, beside
/// 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) {
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(
footprint_for(model).as_ref(),
self.physical_budget().usable_bytes,
self.plan_budget_bytes.load(Ordering::Relaxed),
served_ctx,
lanes,
sequences,
Expand Down Expand Up @@ -706,13 +709,12 @@ impl ServingDaemonModule {
/// That is the fit at `sequences` (a window within `budget_bytes` for each, capped at the trained
/// window) or the plan's own window x its lanes, whichever is larger.
///
/// `budget_bytes` is the PHYSICAL budget (`physical_budget`, the capacity `launch_window` bounds by
/// too), never the plan's live one. The engine launches once and is never relaunched to resize, so
/// a pool sized at a transient is kept for the engine's life: b4be7bc59 launched the M5 at
/// 5 x 2,048 from the cold boot plan, whose window was the bootstrap 2,048 and whose live budget
/// fit nothing at five sequences (2026-11-03 18:18Z, rolled back; Cormac on #5733). On the M5
/// (plan 2 x 128,768) the result is 257,536 for 5; on the IntelMac (plan 2 x 32,768, fit
/// 9 x 32,768) 294,912 for 9, its healthy geometry.
/// `budget_bytes` is the published plan's live budget. `--kv-unified` allocates the whole pool up
/// front and one launch keeps it, so the budget must be what memory holds now: the host's physical
/// total ignores everything else resident (590df4bc3: 5 x 262,144 on the M5, memory pressure 91%,
/// rolled back), and a cold boot's first-tick plan is a transient (b4be7bc59: 5 x 2,048, rolled
/// back), which planning no longer publishes. On the M5 (plan 2 x 128,768) the result is 257,536 for
/// 5; on the IntelMac (plan 2 x 32,768, fit 9 x 32,768) 294,912 for 9, its healthy geometry.
pub(super) fn launch_pool(
footprint: Option<&crate::inference::planning::serving_plan::ModelFootprint>,
budget_bytes: u64,
Expand Down
108 changes: 94 additions & 14 deletions core/continuum-serving/src/modules/serving_daemon/planning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,31 @@ impl ServingDaemonModule {
}
let (budget, leases) = self.host_budget_snapshot();
let intent = self.intent.snapshot();
let catalog = self.catalog.snapshot();
let candidates = servable_candidates(&catalog, &intent.suppressed, &intent.pinned);
let on_disk = servable_candidates(&catalog, &HashSet::new(), &intent.pinned);
self.publish_plan_with_leases(budget, &candidates, &on_disk, intent.revision, &leases);
self.plan_until_decided(budget, intent.revision, &leases, || {
let catalog = self.catalog.snapshot();
(
servable_candidates(&catalog, &intent.suppressed, &intent.pinned),
servable_candidates(&catalog, &HashSet::new(), &intent.pinned),
)
});
}

/// Plan, and re-plan at once while the pass retires the footprint record its plan was computed
/// from: such a plan is invalid by construction, and `candidates` recomputes the footprints
/// without the record (`footprint_for` reads it). Each retire removes one record from a finite
/// set, so this ends. On the M5 it turns the cold boot's 2,048 plan into the 2 x 184,320 the
/// next tick produced (b4be7bc59, 2026-11-03; Cormac on #5739).
pub(super) fn plan_until_decided(
&self,
budget: HostBudget,
intent_revision: u64,
leases: &[crate::resources::lease::ResourceLease],
mut candidates: impl FnMut() -> (Vec<ModelFootprint>, Vec<ModelFootprint>),
) {
until_decided(|| {
let (now, on_disk) = candidates();
self.publish_plan_with_leases(budget, &now, &on_disk, intent_revision, leases)
});
}

/// Pure publish step: run the classifier on the given inputs, publish the
Expand All @@ -60,8 +81,8 @@ impl ServingDaemonModule {
budget: HostBudget,
candidates: &[ModelFootprint],
on_disk: &[ModelFootprint],
) {
self.publish_plan_for_intent(budget, candidates, on_disk, self.intent.snapshot().revision);
) -> PlanOutcome {
self.publish_plan_for_intent(budget, candidates, on_disk, self.intent.snapshot().revision)
}

pub(super) fn publish_plan_snapshot(&self, intent_revision: u64, plan: Option<ServingPlan>) {
Expand Down Expand Up @@ -104,15 +125,15 @@ impl ServingDaemonModule {
candidates: &[ModelFootprint],
on_disk: &[ModelFootprint],
intent_revision: u64,
) {
self.publish_plan_with_leases(budget, candidates, on_disk, intent_revision, &[]);
) -> PlanOutcome {
self.publish_plan_with_leases(budget, candidates, on_disk, intent_revision, &[])
}

fn publish_plan_with_leases(
&self, budget: HostBudget, candidates: &[ModelFootprint],
on_disk: &[ModelFootprint], intent_revision: u64,
leases: &[crate::resources::lease::ResourceLease],
) {
) -> PlanOutcome {
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 Expand Up @@ -270,9 +291,32 @@ impl ServingDaemonModule {
);
*last = Some(key);
}
if previous_stands {
self.retain_plan_for_intent(intent_revision, candidates);
return;
// A starved plan whose own tick just retired the record it was computed from is
// invalid by construction, so it is never published on a cold boot: the engine
// launches once from the first published plan and keeps that pool for life.
// b4be7bc59 launched the M5 at 5 x 2,048 from exactly this plan (18:18:26Z, budget
// sampled at 23 GB, record_retired=true); the next tick, with the record gone and
// the candidates recomputed, planned 2 x 184,320 at the same budget. State, not a
// count (Cormac on #5739): a record can be retired only once, so the next tick's
// plan comes from inputs that survived, and a plan starved by those (a node that
// genuinely cannot hold the requirement) is published as before.
match starved_plan(previous_stands, retired) {
Starved::PreviousStands => {
self.retain_plan_for_intent(intent_revision, candidates);
return PlanOutcome::Decided;
}
Starved::Replan => {
continuum_base::probe!(
target: "continuum_core::modules::serving_daemon", class = "serving.plan.cold_withheld",
model = plan.base_model.model_id.as_str(),
window = plan.served_context_window as u64,
requirement = requirement.unwrap_or(0) as u64, // unwrap_or: probe label; this branch only fires with a requirement present
usable_gb = (budget.usable_bytes / 1_000_000_000),
"a cold boot's starved plan came from the record this tick retired: withheld, so the one launch waits for the next tick's plan"
);
return PlanOutcome::RetiredItsRecord;
}
Starved::Publish => {}
}
}
// THE HOST FLOOR (Joel, 2026-09-16: "if this machine ever returns less than
Expand Down Expand Up @@ -378,7 +422,7 @@ impl ServingDaemonModule {
}
}
}
return;
return PlanOutcome::Decided;
}
// COLD BOOT, no incumbent: a viable base the budget CAN serve beats a
// capability floor it cannot reach. Serve the plan instead of booting dark
Expand Down Expand Up @@ -432,7 +476,7 @@ impl ServingDaemonModule {
incumbent plan until the squeeze proves sustained (#368)",
);
self.retain_plan_for_intent(intent_revision, candidates);
return;
return PlanOutcome::Decided;
}
// Sustained: a real squeeze. Adopt, and re-arm the gate.
self.downshift_streak.store(0, Ordering::Relaxed);
Expand Down Expand Up @@ -623,6 +667,7 @@ impl ServingDaemonModule {
self.publish_plan_snapshot(intent_revision, None);
}
}
PlanOutcome::Decided
}
}

Expand Down Expand Up @@ -736,3 +781,38 @@ mod training_lease_tests {
);
}
}

/// What one planning pass decided: a plan published, retained or refused (`Decided`), or nothing,
/// because the plan was computed from a footprint record that this pass retired, so the caller
/// re-plans at once from the candidates recomputed without it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum PlanOutcome {
Decided,
RetiredItsRecord,
}

/// What a plan below the residents' requirement does. A published plan stands instead when one
/// exists. On a cold boot, a plan computed from the footprint record its own pass retired is
/// invalid by construction, so the pass re-plans; one starved by inputs that survived the pass is
/// published (a dark node is worse than a starved seat).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum Starved {
PreviousStands,
Replan,
Publish,
}

pub(super) fn starved_plan(previous_stands: bool, retired_its_record: bool) -> Starved {
match (previous_stands, retired_its_record) {
(true, _) => Starved::PreviousStands,
(false, true) => Starved::Replan,
(false, false) => Starved::Publish,
}
}

/// Run planning passes until one decides: a pass that retired the record its plan came from
/// re-runs at once. Each retire removes a record from a finite set, so this ends.
pub(super) fn until_decided(mut pass: impl FnMut() -> PlanOutcome) {
while pass() == PlanOutcome::RetiredItsRecord {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,27 @@ fn model_swap_on_a_ready_lane_needs_a_sustained_streak() {
);
}

// what this catches (b4be7bc59 on the M5, 2026-11-03 18:18Z, rolled back): a launch pool sized
// from the cold boot plan. Its window was the bootstrap 2,048 and the plan's live budget fit
// nothing at five sequences, so the engine launched at 5 x 2,048, and one launch is never
// relaunched to resize. On the boot plan the pool is the fit at the physical budget, never the
// plan's 2,048 (Cormac on #5733). Fixed inputs, so the result never depends on the host's RAM
// (Cormac on #5739): the M5's model (20.69 GB weights, 8,317 B/token, read 11-03 12:51Z), a fixed
// 96 GB physical budget, the boot plan (2,048 x 1), five sequences.
// what this catches: a launch pool sized from anything but the published plan's LIVE budget. One
// launch keeps its pool and `--kv-unified` allocates it up front, so b4be7bc59 (the cold boot's
// first-tick 2,048 plan: 5 x 2,048) and 590df4bc3 (the host's physical total: 5 x 262,144, memory
// pressure 91%) were both rolled back on the M5 on 2026-11-03. Fixed inputs, never the host's RAM
// (Cormac on #5739): the pool is the larger of the plan's window x lanes and the fit at the live
// budget, so the M5 at its 23 GB live budget gets its plan's 257,536 and the IntelMac its fit.
#[test]
fn the_launch_pool_never_comes_from_the_boot_plan() {
let trained = 262_144;
let mut fp = footprint_from_parts("ggml-org/Qwen3.6-35B-A3B-GGUF", 20_690_000_000, trained, true, None)
.expect("a footprint from the weights");
fp.kv_per_token = 8_317;
let physical = 96 * GB;
let fit = u64::from(fp.window_within(physical, 5).min(trained)) * 5;
assert!(fit > 2_048, "the physical budget fits more than the bootstrap window: {fit}");
fn the_launch_pool_is_the_live_plans_never_the_physical_totals() {
let launch_pool = super::super::launch::launch_pool;
assert_eq!(launch_pool(Some(&fp), physical, 2_048, 1, 5, trained), fit, "the pool is the physical fit, not the boot plan");
assert_eq!(launch_pool(Some(&fp), 0, 2_048, 1, 5, trained), 2_048, "what b4be7bc59 fed it: a zero budget leaves only the boot plan");
assert_eq!(launch_pool(None, physical, 128_768, 2, 5, trained), 257_536, "no footprint: the plan's own window x lanes");
let m5_trained = 262_144;
let mut m5 = footprint_from_parts("ggml-org/Qwen3.6-35B-A3B-GGUF", 20_690_000_000, m5_trained, true, None)
.expect("a footprint from the weights");
m5.kv_per_token = 8_317;
let m5_live = 23 * GB;
assert_eq!(m5.window_within(m5_live, 5), 0, "the M5's live budget fits no window at five sequences beside the plan");
assert_eq!(launch_pool(Some(&m5), m5_live, 128_768, 2, 5, m5_trained), 257_536, "the M5 launches its plan's 2 x 128,768");
assert!(launch_pool(Some(&m5), m5_live, 128_768, 2, 5, m5_trained) < 5 * u64::from(m5_trained), "never 5 x the trained window (590df4bc3)");

let intel_trained = 32_768;
let mut intel = footprint_from_parts("intelmac", 5 * GB, intel_trained, true, None).expect("a footprint");
intel.kv_per_token = 8_192;
assert_eq!(launch_pool(Some(&intel), 30 * GB, 32_768, 2, 9, intel_trained), 294_912, "the IntelMac: its fit, 9 x 32,768");
assert_eq!(launch_pool(None, 30 * GB, 32_768, 2, 9, intel_trained), 65_536, "no footprint: the plan's own window x lanes");
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ async fn a_plan_below_one_coding_turn_is_not_published_and_the_previous_stands()
.clone()
.expect("a cold boot publishes the best runnable plan, starved or not");
assert!(starved.served_context_window <= 32_768);
assert!(starved.served_context_window > 2_048, "a genuinely starved node launches its own measured window, never a 2,048 fallback (Cormac's case 2 on #5739)");
assert!(
!crate::inference::planning::serving_plan::persona_lane_holds(
starved.served_context_window,
Expand Down Expand Up @@ -656,3 +657,35 @@ fn each_sequence_is_published_its_share_of_the_shared_pool() {
assert_eq!(sequence_share(290_560, 1, 100_000), (100_000, 1), "one sequence is capped at the trained window");
assert_eq!(sequence_share(290_560, 0, 262_144), (262_144, 1), "no sequence count is one, never a divide by zero");
}

// what this catches (b4be7bc59 on the M5, 2026-11-03 18:18Z, rolled back): a cold boot publishing
// (so launching once, for the engine's life) a plan computed off the footprint record the same pass
// retired: 2,048 at a sampled 23 GB; the next pass, without the record, planned 2 x 184,320. A
// starved plan re-plans exactly when its own pass retired its record and nothing is published yet;
// a published plan stands; a plan starved by inputs that survived is published (a dark node is
// worse). And the loop re-runs a pass only while it retires its record (Cormac's case 1 on #5739).
#[test]
fn a_pass_that_retires_its_record_re_plans_never_publishing_the_starved_plan() {
use super::super::planning::{starved_plan, until_decided, PlanOutcome, Starved};
assert_eq!(starved_plan(false, true), Starved::Replan, "cold boot, record retired: re-plan, never publish");
assert_eq!(starved_plan(false, false), Starved::Publish, "cold boot, starved by surviving inputs: publish");
assert_eq!(starved_plan(true, true), Starved::PreviousStands, "a published plan stands");
assert_eq!(starved_plan(true, false), Starved::PreviousStands);
let mut passes = vec![PlanOutcome::RetiredItsRecord, PlanOutcome::RetiredItsRecord, PlanOutcome::Decided].into_iter();
let mut ran = 0;
until_decided(|| {
ran += 1;
passes.next().expect("no pass after the deciding one")
});
assert_eq!(ran, 3, "re-plans while a pass retires its record, stops at the pass that decides");
}

// what this catches: a launch before any plan exists (no sampled budget, no plan published):
// the engine must not start from defaults (Cormac's case 3 on #5739).
#[tokio::test]
async fn no_plan_published_means_no_launch() {
let daemon = daemon_with(Arc::new(FakeServer::healthy(Arc::new(AtomicUsize::new(0)), true)));
assert!(daemon.plan_tx.borrow().plan.is_none(), "nothing planned yet");
assert!(daemon.reconcile_to_plan().is_none(), "no plan, no launch");
}

Loading