From 72e08cd0f55d5f6f284300e967cca3bad01b35e7 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Tue, 3 Nov 2026 13:24:20 -0600 Subject: [PATCH 1/4] The one launch waits for a budgeted plan and sizes from its live budget, never physical totals (590df4bc3 launched the M5 at 5 x 262,144) 590df4bc3 sized the pool from physical_budget (TOTAL x the mode's fraction): 5 x 262,144 = 1,310,720 tokens on the M5, memory pressure 91% high with 5.6 GB available (canary: 80%, 12.4 GB), no resident hosted in four minutes; rolled back 19:21Z. Physical totals ignore everything else resident, and --kv-unified allocates the whole pool at launch. b4be7bc59's 5 x 2,048 came from the cold boot's first-tick plan. - planning: a cold boot's FIRST starved plan (below the residents' requirement, no plan published yet) is held back once (per daemon, keyed by model); the next recompute publishes. On the M5 that next tick, one second later, planned 2 x 184,320 at the same 23 GB live budget. A second starved plan publishes as before: a dark node is worse than a starved seat. - launch_pool reads the published plan's live budget (plan_budget_bytes) again: max(plan window x lanes, fit at the live budget). - Tests (fixed inputs): the M5 at 23 GB live gets 257,536, never 5 x 262,144; the IntelMac 294,912; the cold-boot publication test now asserts the first starved plan is held back and the second published. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/modules/serving_daemon.rs | 4 ++ .../src/modules/serving_daemon/launch.rs | 20 +++++----- .../src/modules/serving_daemon/planning.rs | 20 ++++++++++ .../serving_daemon/tests/one_launch.rs | 39 ++++++++++--------- .../serving_daemon/tests/publication.rs | 23 +++++------ 5 files changed, 68 insertions(+), 38 deletions(-) diff --git a/core/continuum-serving/src/modules/serving_daemon.rs b/core/continuum-serving/src/modules/serving_daemon.rs index cf6f59000d..8c0c67eb48 100644 --- a/core/continuum-serving/src/modules/serving_daemon.rs +++ b/core/continuum-serving/src/modules/serving_daemon.rs @@ -357,6 +357,9 @@ pub struct ServingDaemonModule { /// Whether the engine process `pid` runs on the shared pool: read off its argv once per /// process, never every tick. shared_pool_of: Arc>>, + /// The model whose cold-boot first plan was starved and held back once, so the one launch + /// waits for the next recompute (`planning.rs`); a second starved plan publishes. + cold_deferred: parking_lot::Mutex>, /// The pool the running engine reports (`served_pool_tokens`, its `context_geometry`), as /// the launch's ready path last read it; `0` = not read. The grants' one source for the pool. served_pool: Arc, @@ -552,6 +555,7 @@ impl ServingDaemonModule { shared_pool_move_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)), + cold_deferred: parking_lot::Mutex::new(None), served_pool: Arc::new(std::sync::atomic::AtomicU32::new(0)), model_change_streak: Arc::new(std::sync::atomic::AtomicU32::new(0)), pending_model_change: Arc::new(std::sync::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 b2fa8ace4a..4e16e5ebb0 100644 --- a/core/continuum-serving/src/modules/serving_daemon/launch.rs +++ b/core/continuum-serving/src/modules/serving_daemon/launch.rs @@ -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, @@ -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, diff --git a/core/continuum-serving/src/modules/serving_daemon/planning.rs b/core/continuum-serving/src/modules/serving_daemon/planning.rs index ff9aed308a..a82bc0f070 100644 --- a/core/continuum-serving/src/modules/serving_daemon/planning.rs +++ b/core/continuum-serving/src/modules/serving_daemon/planning.rs @@ -274,6 +274,26 @@ impl ServingDaemonModule { self.retain_plan_for_intent(intent_revision, candidates); return; } + // A COLD BOOT'S FIRST starved plan is not published: the engine launches once + // from whatever plan is published first and is never relaunched to resize, so a + // first-tick fallback becomes the pool for the engine's life (b4be7bc59 launched + // the M5 at 5 x 2,048 from the 2,048 plan at 18:18:26Z; the next tick, one second + // later with the record retired, planned 2 x 184,320 at the same 23 GB). The next + // recompute decides: a second starved plan is published as before, because a dark + // node is worse than a starved seat (Cormac on #5739). + let mut deferred = self.cold_deferred.lock(); + if deferred.as_deref() != Some(plan.base_model.model_id.as_str()) { + *deferred = Some(plan.base_model.model_id.clone()); + continuum_base::probe!( + target: "continuum_core::modules::serving_daemon", class = "serving.plan.cold_deferred", + 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 first plan is starved: not published, so the one launch waits for the next recompute" + ); + return; + } } // THE HOST FLOOR (Joel, 2026-09-16: "if this machine ever returns less than // 27b we are sucking"). The debounce below separates jitter from a sustained diff --git a/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs b/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs index 16e63bae75..e4b0cec57d 100644 --- a/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs +++ b/core/continuum-serving/src/modules/serving_daemon/tests/one_launch.rs @@ -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"); } diff --git a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs index 57aba362ae..1f6bdc1685 100644 --- a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs +++ b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs @@ -315,9 +315,11 @@ async fn a_plan_below_one_coding_turn_is_not_published_and_the_previous_stands() daemon.reconcile_to_plan().is_none(), "excluded retained model cannot dispatch" ); - // With NO plan published (a cold boot) and a requirement the box cannot hold, the - // best runnable plan is still published — a dark node is worse than a starved seat - // (Cormac's condition on #4257: IntelMac's 32k-trained 1.5B against a 58k typical). + // With NO plan published (a cold boot) and a requirement the box cannot hold, the first + // starved plan is held back once, so the one launch never comes from a first-tick fallback + // (b4be7bc59: 5 x 2,048 on the M5, 2026-11-03), and the next recompute publishes the best + // runnable plan: a dark node is worse than a starved seat (Cormac's condition on #4257: + // IntelMac's 32k-trained 1.5B against a 58k typical). let mut cold = ServingDaemonModule::new( Arc::new(GpuMemoryManager::simulated("Intel", 16 * GB)), Arc::new(SystemResourceMonitor::new()), @@ -330,14 +332,13 @@ async fn a_plan_below_one_coding_turn_is_not_published_and_the_previous_stands() cold.working_set.record_in_memory(uuid::Uuid::new_v4(), 200_000, 1); let rx_cold = cold.subscribe(); let small = vec![footprint_from_parts("coder-1.5b", GB, 32_768, true, None).unwrap()]; - cold.publish_plan( - HostBudget { - usable_bytes: 12 * GB, - perf_cores: 4, - }, - &small, - &small, - ); + let budget = HostBudget { + usable_bytes: 12 * GB, + perf_cores: 4, + }; + cold.publish_plan(budget, &small, &small); + assert!(rx_cold.borrow().is_none(), "a cold boot's first starved plan is held back, so no launch comes from it"); + cold.publish_plan(budget, &small, &small); let starved = rx_cold .borrow() .clone() From c54486cc063eb315baaefaf819c8539cb137b46d Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Tue, 3 Nov 2026 13:29:55 -0600 Subject: [PATCH 2/4] Planning re-plans in the same pass when it retires the record its plan came from; tests for Cormac's four cases - PlanOutcome from publish_plan_with_leases; plan_until_decided loops while a pass retires its own record (state, not a count: each retire removes a record from a finite set); recompute calls it with the catalog's candidates, which footprint_for recomputes without the retired record. - lane_footprint::record_for_test (test-fixtures): a measured record in memory, no save. - Tests: a_pass_that_retires_its_record_publishes_the_re_plan_never_the_starved_plan (case 1), the cold-boot starved node publishes its own window > 2,048 (case 2), no_plan_published_means_no_launch (case 3), the_launch_pool_is_the_live_plans_never_the_physical_totals (case 4). - The counter from 72e08cd0f is gone (Cormac: a count would launch small on a second starved plan). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/inference/lane_footprint.rs | 7 ++ .../src/modules/serving_daemon.rs | 4 - .../src/modules/serving_daemon/planning.rs | 84 +++++++++++------ .../serving_daemon/tests/publication.rs | 89 ++++++++++++++++--- 4 files changed, 143 insertions(+), 41 deletions(-) diff --git a/core/continuum-engine/src/inference/lane_footprint.rs b/core/continuum-engine/src/inference/lane_footprint.rs index 7e40bc2831..f05d54c328 100644 --- a/core/continuum-engine/src/inference/lane_footprint.rs +++ b/core/continuum-engine/src/inference/lane_footprint.rs @@ -267,6 +267,13 @@ pub fn retire_if_sampled_since(model: &str, since_ms: u64) -> bool { /// The fresh measured record for `model`, if any — per-token AND the geometry it was /// taken at, so a caller can turn an excess over a known rate into fixed bytes. +/// TEST FIXTURE: a measured record for `model`, in memory only (no save), as a sample would leave +/// it. Lets a planner test reproduce a trapped record without a live process to measure. +#[cfg(any(test, feature = "test-fixtures"))] +pub fn record_for_test(model: &str, cost: MeasuredCost) { + COSTS.lock().insert(model.to_string(), cost); +} + pub fn measured_record(model: &str) -> Option { let now = EpochMs::now().millis(); COSTS.lock().get(model).filter(|c| c.fresh_at(now)).cloned() diff --git a/core/continuum-serving/src/modules/serving_daemon.rs b/core/continuum-serving/src/modules/serving_daemon.rs index 8c0c67eb48..cf6f59000d 100644 --- a/core/continuum-serving/src/modules/serving_daemon.rs +++ b/core/continuum-serving/src/modules/serving_daemon.rs @@ -357,9 +357,6 @@ pub struct ServingDaemonModule { /// Whether the engine process `pid` runs on the shared pool: read off its argv once per /// process, never every tick. shared_pool_of: Arc>>, - /// The model whose cold-boot first plan was starved and held back once, so the one launch - /// waits for the next recompute (`planning.rs`); a second starved plan publishes. - cold_deferred: parking_lot::Mutex>, /// The pool the running engine reports (`served_pool_tokens`, its `context_geometry`), as /// the launch's ready path last read it; `0` = not read. The grants' one source for the pool. served_pool: Arc, @@ -555,7 +552,6 @@ impl ServingDaemonModule { shared_pool_move_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)), - cold_deferred: parking_lot::Mutex::new(None), served_pool: Arc::new(std::sync::atomic::AtomicU32::new(0)), model_change_streak: Arc::new(std::sync::atomic::AtomicU32::new(0)), pending_model_change: Arc::new(std::sync::Mutex::new(None)), diff --git a/core/continuum-serving/src/modules/serving_daemon/planning.rs b/core/continuum-serving/src/modules/serving_daemon/planning.rs index a82bc0f070..cfa25d270f 100644 --- a/core/continuum-serving/src/modules/serving_daemon/planning.rs +++ b/core/continuum-serving/src/modules/serving_daemon/planning.rs @@ -41,10 +41,33 @@ 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, Vec), + ) { + loop { + let (now, on_disk) = candidates(); + if self.publish_plan_with_leases(budget, &now, &on_disk, intent_revision, leases) == PlanOutcome::Decided { + return; + } + } } /// Pure publish step: run the classifier on the given inputs, publish the @@ -60,8 +83,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) { @@ -104,15 +127,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. @@ -272,27 +295,27 @@ impl ServingDaemonModule { } if previous_stands { self.retain_plan_for_intent(intent_revision, candidates); - return; + return PlanOutcome::Decided; } - // A COLD BOOT'S FIRST starved plan is not published: the engine launches once - // from whatever plan is published first and is never relaunched to resize, so a - // first-tick fallback becomes the pool for the engine's life (b4be7bc59 launched - // the M5 at 5 x 2,048 from the 2,048 plan at 18:18:26Z; the next tick, one second - // later with the record retired, planned 2 x 184,320 at the same 23 GB). The next - // recompute decides: a second starved plan is published as before, because a dark - // node is worse than a starved seat (Cormac on #5739). - let mut deferred = self.cold_deferred.lock(); - if deferred.as_deref() != Some(plan.base_model.model_id.as_str()) { - *deferred = Some(plan.base_model.model_id.clone()); + // 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. + if retired { continuum_base::probe!( - target: "continuum_core::modules::serving_daemon", class = "serving.plan.cold_deferred", + 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 first plan is starved: not published, so the one launch waits for the next recompute" + "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; + return PlanOutcome::RetiredItsRecord; } } // THE HOST FLOOR (Joel, 2026-09-16: "if this machine ever returns less than @@ -398,7 +421,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 @@ -452,7 +475,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); @@ -643,6 +666,7 @@ impl ServingDaemonModule { self.publish_plan_snapshot(intent_revision, None); } } + PlanOutcome::Decided } } @@ -756,3 +780,13 @@ 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, +} + diff --git a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs index 1f6bdc1685..cb4501c067 100644 --- a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs +++ b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs @@ -315,11 +315,9 @@ async fn a_plan_below_one_coding_turn_is_not_published_and_the_previous_stands() daemon.reconcile_to_plan().is_none(), "excluded retained model cannot dispatch" ); - // With NO plan published (a cold boot) and a requirement the box cannot hold, the first - // starved plan is held back once, so the one launch never comes from a first-tick fallback - // (b4be7bc59: 5 x 2,048 on the M5, 2026-11-03), and the next recompute publishes the best - // runnable plan: a dark node is worse than a starved seat (Cormac's condition on #4257: - // IntelMac's 32k-trained 1.5B against a 58k typical). + // With NO plan published (a cold boot) and a requirement the box cannot hold, the + // best runnable plan is still published — a dark node is worse than a starved seat + // (Cormac's condition on #4257: IntelMac's 32k-trained 1.5B against a 58k typical). let mut cold = ServingDaemonModule::new( Arc::new(GpuMemoryManager::simulated("Intel", 16 * GB)), Arc::new(SystemResourceMonitor::new()), @@ -332,18 +330,20 @@ async fn a_plan_below_one_coding_turn_is_not_published_and_the_previous_stands() cold.working_set.record_in_memory(uuid::Uuid::new_v4(), 200_000, 1); let rx_cold = cold.subscribe(); let small = vec![footprint_from_parts("coder-1.5b", GB, 32_768, true, None).unwrap()]; - let budget = HostBudget { - usable_bytes: 12 * GB, - perf_cores: 4, - }; - cold.publish_plan(budget, &small, &small); - assert!(rx_cold.borrow().is_none(), "a cold boot's first starved plan is held back, so no launch comes from it"); - cold.publish_plan(budget, &small, &small); + cold.publish_plan( + HostBudget { + usable_bytes: 12 * GB, + perf_cores: 4, + }, + &small, + &small, + ); let starved = rx_cold .borrow() .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, @@ -657,3 +657,68 @@ 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 launching +// from a plan computed off a footprint record that the same pass retired. That plan read 2,048 at a +// sampled 23 GB, and the engine kept 5 x 2,048 for life; the next tick, without the record, planned +// 2 x 184,320. A pass that retires its own record re-plans at once, and the plan that is published +// (so launched) is the re-plan, never the starved one (Cormac's case 1 on #5739). The candidates +// follow the record exactly as `footprint_for` does: its rate while it stands, the estimate after. +#[tokio::test] +async fn a_pass_that_retires_its_record_publishes_the_re_plan_never_the_starved_plan() { + let mut cold = ServingDaemonModule::new( + Arc::new(GpuMemoryManager::simulated("M5", 64 * GB)), + Arc::new(SystemResourceMonitor::new()), + test_resource_daemon(), + test_catalog(), + test_pin_store(), + ); + cold.working_set = crate::cognition::working_set::WorkingSetRegistry::new(); + cold.set_leased_in_sent_source(Arc::new(Vec::new)); + cold.working_set.record_in_memory(uuid::Uuid::new_v4(), 16_000, 1); + let rx = cold.subscribe(); + let model = "cold-retire-fixture-35b"; + let estimate = footprint_from_parts(model, 20 * GB, 262_144, true, None).unwrap(); + let mut trapped = estimate.clone(); + trapped.kv_per_token = 1_000_000; // a trapped record: ~10k tokens fit beside the weights, below the requirement + crate::inference::lane_footprint::record_for_test( + model, + crate::inference::lane_footprint::MeasuredCost { + per_token_bytes: trapped.kv_per_token, + lanes: 1, + window: 8_192, + allocated_tokens: Some(8_192), + anon_bytes: 0, + last_ms: continuum_base::time::EpochMs::now().millis(), + }, + ); + let budget = HostBudget { usable_bytes: 30 * GB, perf_cores: 6 }; + let mut seen = Vec::new(); + cold.plan_until_decided(budget, cold.intent.snapshot().revision, &[], || { + let fp = match crate::inference::lane_footprint::measured_record(model) { + Some(_) => trapped.clone(), + None => estimate.clone(), + }; + seen.push(fp.kv_per_token); + (vec![fp.clone()], vec![fp]) + }); + assert_eq!(seen, vec![1_000_000, estimate.kv_per_token], "planned once from the record, once more after retiring it"); + let published = rx.borrow().clone().expect("the re-plan is published"); + assert!( + crate::inference::planning::serving_plan::persona_lane_holds(published.served_context_window, Some(16_000)), + "the launch takes the re-plan, which holds the requirement: {} x {}", + published.lanes, + published.served_context_window + ); + assert!(crate::inference::lane_footprint::measured_record(model).is_none(), "the trapped record is retired"); +} + +// 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"); +} + From a8c2cfa20e169c9d287d5cfce5d98d92924351be Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Tue, 3 Nov 2026 13:33:34 -0600 Subject: [PATCH 3/4] Cold-boot retire test plants its record through lane_footprint::observe (no fixture in lane_footprint.rs) and uses the 200k-token requirement whose floor the starved plan misses Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/inference/lane_footprint.rs | 7 ----- .../serving_daemon/tests/publication.rs | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/core/continuum-engine/src/inference/lane_footprint.rs b/core/continuum-engine/src/inference/lane_footprint.rs index f05d54c328..7e40bc2831 100644 --- a/core/continuum-engine/src/inference/lane_footprint.rs +++ b/core/continuum-engine/src/inference/lane_footprint.rs @@ -267,13 +267,6 @@ pub fn retire_if_sampled_since(model: &str, since_ms: u64) -> bool { /// The fresh measured record for `model`, if any — per-token AND the geometry it was /// taken at, so a caller can turn an excess over a known rate into fixed bytes. -/// TEST FIXTURE: a measured record for `model`, in memory only (no save), as a sample would leave -/// it. Lets a planner test reproduce a trapped record without a live process to measure. -#[cfg(any(test, feature = "test-fixtures"))] -pub fn record_for_test(model: &str, cost: MeasuredCost) { - COSTS.lock().insert(model.to_string(), cost); -} - pub fn measured_record(model: &str) -> Option { let now = EpochMs::now().millis(); COSTS.lock().get(model).filter(|c| c.fresh_at(now)).cloned() diff --git a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs index cb4501c067..e845c96fac 100644 --- a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs +++ b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs @@ -675,24 +675,27 @@ async fn a_pass_that_retires_its_record_publishes_the_re_plan_never_the_starved_ ); cold.working_set = crate::cognition::working_set::WorkingSetRegistry::new(); cold.set_leased_in_sent_source(Arc::new(Vec::new)); - cold.working_set.record_in_memory(uuid::Uuid::new_v4(), 16_000, 1); + cold.working_set.record_in_memory(uuid::Uuid::new_v4(), 200_000, 1); let rx = cold.subscribe(); let model = "cold-retire-fixture-35b"; let estimate = footprint_from_parts(model, 20 * GB, 262_144, true, None).unwrap(); let mut trapped = estimate.clone(); trapped.kv_per_token = 1_000_000; // a trapped record: ~10k tokens fit beside the weights, below the requirement - crate::inference::lane_footprint::record_for_test( + // Plant the record the way a live sample does: 8.192 GB beyond the floors over 8,192 tokens of + // one lane is 1,000,000 B/token. A sample straddling a residency change is refused; retry. + while crate::inference::lane_footprint::observe( + crate::inference::lane_footprint::begin_sample(), model, - crate::inference::lane_footprint::MeasuredCost { - per_token_bytes: trapped.kv_per_token, - lanes: 1, - window: 8_192, - allocated_tokens: Some(8_192), - anon_bytes: 0, - last_ms: continuum_base::time::EpochMs::now().millis(), - }, - ); - let budget = HostBudget { usable_bytes: 30 * GB, perf_cores: 6 }; + 1, + 8_192, + 8_192, + 8_192_000_000, + 0, + 0, + ) + .is_err() + {} + let budget = HostBudget { usable_bytes: 60 * GB, perf_cores: 6 }; let mut seen = Vec::new(); cold.plan_until_decided(budget, cold.intent.snapshot().revision, &[], || { let fp = match crate::inference::lane_footprint::measured_record(model) { @@ -705,7 +708,7 @@ async fn a_pass_that_retires_its_record_publishes_the_re_plan_never_the_starved_ assert_eq!(seen, vec![1_000_000, estimate.kv_per_token], "planned once from the record, once more after retiring it"); let published = rx.borrow().clone().expect("the re-plan is published"); assert!( - crate::inference::planning::serving_plan::persona_lane_holds(published.served_context_window, Some(16_000)), + crate::inference::planning::serving_plan::persona_lane_holds(published.served_context_window, Some(70_071)), "the launch takes the re-plan, which holds the requirement: {} x {}", published.lanes, published.served_context_window From 04ba3a1a1ed69a245caec053f7666c8f9d4505b6 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Tue, 3 Nov 2026 13:39:51 -0600 Subject: [PATCH 4/4] Starved-plan decision and the re-plan loop are pure functions with direct tests (starved_plan, until_decided) The planner-level fixture could not reach the legacy-floor branch (publication_prompt_floor applies only without per-mind requirements, i.e. a boot whose floor comes from a remembered sent median), so the rule is tested where it lives: starved_plan(previous_stands, retired) and until_decided(pass). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/modules/serving_daemon/planning.rs | 64 +++++++++++----- .../serving_daemon/tests/publication.rs | 74 +++++-------------- 2 files changed, 64 insertions(+), 74 deletions(-) diff --git a/core/continuum-serving/src/modules/serving_daemon/planning.rs b/core/continuum-serving/src/modules/serving_daemon/planning.rs index cfa25d270f..83f345a217 100644 --- a/core/continuum-serving/src/modules/serving_daemon/planning.rs +++ b/core/continuum-serving/src/modules/serving_daemon/planning.rs @@ -62,12 +62,10 @@ impl ServingDaemonModule { leases: &[crate::resources::lease::ResourceLease], mut candidates: impl FnMut() -> (Vec, Vec), ) { - loop { + until_decided(|| { let (now, on_disk) = candidates(); - if self.publish_plan_with_leases(budget, &now, &on_disk, intent_revision, leases) == PlanOutcome::Decided { - return; - } - } + self.publish_plan_with_leases(budget, &now, &on_disk, intent_revision, leases) + }); } /// Pure publish step: run the classifier on the given inputs, publish the @@ -293,10 +291,6 @@ impl ServingDaemonModule { ); *last = Some(key); } - if previous_stands { - self.retain_plan_for_intent(intent_revision, candidates); - return PlanOutcome::Decided; - } // 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. @@ -306,16 +300,23 @@ impl ServingDaemonModule { // 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. - if retired { - 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; + 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 @@ -790,3 +791,28 @@ pub(super) enum PlanOutcome { 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 {} +} + diff --git a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs index e845c96fac..ecc1205b94 100644 --- a/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs +++ b/core/continuum-serving/src/modules/serving_daemon/tests/publication.rs @@ -658,62 +658,26 @@ fn each_sequence_is_published_its_share_of_the_shared_pool() { 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 launching -// from a plan computed off a footprint record that the same pass retired. That plan read 2,048 at a -// sampled 23 GB, and the engine kept 5 x 2,048 for life; the next tick, without the record, planned -// 2 x 184,320. A pass that retires its own record re-plans at once, and the plan that is published -// (so launched) is the re-plan, never the starved one (Cormac's case 1 on #5739). The candidates -// follow the record exactly as `footprint_for` does: its rate while it stands, the estimate after. -#[tokio::test] -async fn a_pass_that_retires_its_record_publishes_the_re_plan_never_the_starved_plan() { - let mut cold = ServingDaemonModule::new( - Arc::new(GpuMemoryManager::simulated("M5", 64 * GB)), - Arc::new(SystemResourceMonitor::new()), - test_resource_daemon(), - test_catalog(), - test_pin_store(), - ); - cold.working_set = crate::cognition::working_set::WorkingSetRegistry::new(); - cold.set_leased_in_sent_source(Arc::new(Vec::new)); - cold.working_set.record_in_memory(uuid::Uuid::new_v4(), 200_000, 1); - let rx = cold.subscribe(); - let model = "cold-retire-fixture-35b"; - let estimate = footprint_from_parts(model, 20 * GB, 262_144, true, None).unwrap(); - let mut trapped = estimate.clone(); - trapped.kv_per_token = 1_000_000; // a trapped record: ~10k tokens fit beside the weights, below the requirement - // Plant the record the way a live sample does: 8.192 GB beyond the floors over 8,192 tokens of - // one lane is 1,000,000 B/token. A sample straddling a residency change is refused; retry. - while crate::inference::lane_footprint::observe( - crate::inference::lane_footprint::begin_sample(), - model, - 1, - 8_192, - 8_192, - 8_192_000_000, - 0, - 0, - ) - .is_err() - {} - let budget = HostBudget { usable_bytes: 60 * GB, perf_cores: 6 }; - let mut seen = Vec::new(); - cold.plan_until_decided(budget, cold.intent.snapshot().revision, &[], || { - let fp = match crate::inference::lane_footprint::measured_record(model) { - Some(_) => trapped.clone(), - None => estimate.clone(), - }; - seen.push(fp.kv_per_token); - (vec![fp.clone()], vec![fp]) +// 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!(seen, vec![1_000_000, estimate.kv_per_token], "planned once from the record, once more after retiring it"); - let published = rx.borrow().clone().expect("the re-plan is published"); - assert!( - crate::inference::planning::serving_plan::persona_lane_holds(published.served_context_window, Some(70_071)), - "the launch takes the re-plan, which holds the requirement: {} x {}", - published.lanes, - published.served_context_window - ); - assert!(crate::inference::lane_footprint::measured_record(model).is_none(), "the trapped record is retired"); + 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):