From 95c818a50a18fca53c0fb321147a594a5e5b55c6 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Wed, 18 Nov 2026 17:19:21 -0600 Subject: [PATCH 1/2] Bind resident hosting to the applied serving snapshot --- .../start_server/persona_host_reconciler.rs | 28 +++++--- .../src/ipc/start_server/persona_hosting.rs | 24 ------- core/continuum-mind/src/persona/host.rs | 4 +- .../src/persona/spawner_module.rs | 68 ++++++------------- .../src/modules/serving_daemon/planning.rs | 10 --- 5 files changed, 40 insertions(+), 94 deletions(-) diff --git a/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs b/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs index 70dae968ee..27d6a6f812 100644 --- a/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs +++ b/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs @@ -130,6 +130,7 @@ pub(super) async fn run_persona_host( // seats are drawn on that edge, not on the next plan edge. let mut alloc_rx = crate::modules::grid_allocator::subscribe(); let mut alloc_closed = false; + let mut serving_rx = crate::inference::llama_server::serving_state_receiver(); loop { pass += 1; let plan_ready = serving_plan_rx @@ -143,10 +144,6 @@ pub(super) async fn run_persona_host( // of the local plan. `await_ready_serving` short-circuits to a // direct decode-probe of the pinned endpoint (K3, a grid peer). let external_lane = crate::inference::llama_server::external_serving_pin().is_some(); - // The roster follows the LIVE plan's lane count (a pin or tier swap - // must never leave more minds than warm lanes — 2026-09-06). - let live_plan = serving_plan_rx.borrow().clone(); - supervisor.refresh_serving(live_plan.as_ref()); // This node's seats as the grid allocation counts them (seated + open), // once the daemon has published; `None` keeps the warm-slot prior. let roster_here = alloc_rx.borrow().as_ref().and_then(|p| p.roster_here()); @@ -168,11 +165,11 @@ pub(super) async fn run_persona_host( booted = booted, snapshot_live = snapshot_live, changed = last_pass_row.map(|(a, b, c, d, _)| (a, b, c, d) != pass_state).unwrap_or(true), // unwrap_or: first row of the boot = a change by definition - "hosting reconciler pass — will enter host body iff (plan_ready || external_lane); a row = a change or one heartbeat per 60 passes" + "hosting reconciler pass — will enter host body on planned, external or already applied serving; a row = a change or one heartbeat per 60 passes" ); last_pass_row = Some((plan_ready, external_lane, booted, snapshot_live, pass)); } - if plan_ready || external_lane { + if plan_ready || external_lane || snapshot_live { // `fits_on_gpu` is a RESOURCE decision (the model fits VRAM) — it does // NOT prove the lane can DECODE. A lane can fit yet fail EVERY // generation with `500 "Compute error."` while `/health` still answers @@ -186,11 +183,12 @@ pub(super) async fn run_persona_host( // the deadline lapses. On timeout we do NOT spawn (a can't-decode lane // is a loud, novel failure — never a silent per-turn 500); we park and // retry on the next serving edge, self-healing once the lane recovers. - let decode_ready = crate::inference::llama_server::await_ready_serving( + let applied = crate::inference::llama_server::await_ready_serving( std::time::Duration::from_secs(120), ) - .await - .is_some(); + .await; + let verified = applied.as_ref().filter(|state| external_lane || state.ready_verified_at_ms.is_some()); + let decode_ready = supervisor.refresh_serving(verified); let ready_state = (decode_ready, booted); let ready_row_due = match last_ready_row { Some((a, b, at)) => { @@ -300,7 +298,19 @@ pub(super) async fn run_persona_host( // sooner on a pressure edge) — or the grid allocation does. The plan // watch's `changed()` errs only if the daemon is gone — then there is // nothing left to react to. + if serving_rx.is_none() { + serving_rx = crate::inference::llama_server::serving_state_receiver(); + } let plan_edge = tokio::select! { + changed = async { + match serving_rx.as_mut() { + Some(state) => state.changed().await, + None => std::future::pending().await, + } + } => { + if changed.is_err() { break; } + None + } changed = serving_plan_rx.changed() => Some(changed), changed = alloc_rx.changed(), if !alloc_closed => { if changed.is_err() { diff --git a/core/continuum-core/src/ipc/start_server/persona_hosting.rs b/core/continuum-core/src/ipc/start_server/persona_hosting.rs index 607b9de51f..babc1f5bb1 100644 --- a/core/continuum-core/src/ipc/start_server/persona_hosting.rs +++ b/core/continuum-core/src/ipc/start_server/persona_hosting.rs @@ -105,29 +105,6 @@ pub(super) fn start_persona_host( // budget across slots nobody asked for — 2 personas served through 4 // slots at a quarter-window each (the 2026-07-10 starvation). serving_daemon.set_lane_demand(persona_floor as u32); - // The plan is the single grouped source of truth (model + lanes + - // host-fit served window). Pass it by reference to the spawner per - // [[pass-the-model-struct-no-param-hell]] — no destructured loose - // params, no constant clamps re-derived downstream. - let serving_plan = serving_daemon.compute_plan(); - match &serving_plan { - Some(p) if p.fits_on_gpu => { - tracing::info!( - base_model = %p.base_model.model_id, - lanes = p.lanes, - served_context_window = p.served_context_window, - resident = p.resident_models, - tier_id, - "serving daemon drives persona spawn (model + lanes + served window from ServingPlan)" - ); - } - other => { - tracing::warn!( - plan = ?other, - "no GPU-fitting serving plan — spawner falls back to the tier default model, 1 lane, floor window" - ); - } - } // Persona floor — how many citizens to host. Single source: this one // config value drives BOTH the spawner's plan-slot count (via // with_population) AND the identity provider's mint floor below, so @@ -197,7 +174,6 @@ pub(super) fn start_persona_host( let supervisor = crate::persona::host::PersonaSpawnSupervisor::new( crate::persona::spawner_module::PersonaSpawnerModule::new(hw_cap, tier_cat) .with_citizens(resident_roles) - .with_serving(serving_plan.as_ref()) .with_population(persona_floor) // The boot draw's bound before any live plan: the last SETTLED lanes // this host served (card 7c38ff6f) — handed in once, never re-read. diff --git a/core/continuum-mind/src/persona/host.rs b/core/continuum-mind/src/persona/host.rs index d1479aaa46..ce6368177f 100644 --- a/core/continuum-mind/src/persona/host.rs +++ b/core/continuum-mind/src/persona/host.rs @@ -260,8 +260,8 @@ impl PersonaSpawnSupervisor { /// Follow the LIVE serving plan (called on every reconciler pass): the roster /// seats at most the served lane count, so a swap to a bigger model with fewer /// lanes shrinks the roster instead of starving it. - pub fn refresh_serving(&mut self, plan: Option<&crate::inference::planning::serving_plan::ServingPlan>) { - self.spawner.set_serving(plan); + pub fn refresh_serving(&mut self, snapshot: Option<&crate::inference::llama_server::ServingSnapshot>) -> bool { + self.spawner.set_serving(snapshot) } /// Follow the GRID ALLOCATION's roster for this node (card 10bba591), told each diff --git a/core/continuum-mind/src/persona/spawner_module.rs b/core/continuum-mind/src/persona/spawner_module.rs index 809ca5ed25..637b3086f2 100644 --- a/core/continuum-mind/src/persona/spawner_module.rs +++ b/core/continuum-mind/src/persona/spawner_module.rs @@ -74,12 +74,12 @@ pub struct DesiredRole { pub model_id: String, /// Continuous-batching lanes (`n_seq_max`) for this role's backend, from /// the serving daemon's ServingPlan. Defaults to 1 from `plan_for_tier`; - /// `PersonaSpawnerModule::with_serving` overrides it from the live plan. + /// `PersonaSpawnerModule::set_serving` overrides it from the live plan. pub lanes: u32, /// Host-fit served context window (tokens) the gateway llama-server was /// launched with — the planner's single source of truth, NOT a constant. /// Defaults to `MIN_SERVE_CTX` from `plan_for_tier` (runnable floor when no - /// plan is published); `with_serving` overrides it from the live plan. + /// plan is published); `set_serving` overrides it from the live plan. pub served_context_window: u32, } @@ -108,7 +108,7 @@ pub fn plan_for_tier( /// Compose the desired roster from RECIPE-DECLARED roles (#430). The roles /// come from authored data (the default experience's `citizens`); this /// function maps each onto the serving scaffold — LCD fallback model until -/// the serving daemon's plan overrides it via `with_serving`, single lane, +/// the serving daemon's plan overrides it via `set_serving`, single lane, /// runnable-floor window. /// /// SLICE-14 GUARD, now enforced on DATA: heterogeneous multi-role plans are @@ -144,10 +144,10 @@ pub fn plan_for_roles( role: role.clone(), // Fallback model when no ServingPlan is published yet: the FLOOR, which // is the 1.5B coder — there is no 0.5B row in the catalog any more. The - // serving daemon's plan overrides this via with_serving — that's the + // serving daemon's plan overrides this via set_serving — that's the // real, honest, GPU-residency-aware pick. model_id: "continuum-ai/qwen2.5-coder-1.5b-instruct-GGUF".to_string(), - // Default single lane; with_serving overrides from the live plan. + // Default single lane; set_serving overrides from the live plan. lanes: 1, // Runnable floor until the serving daemon publishes a host-fit // window. @@ -209,7 +209,7 @@ pub struct PersonaSpawnerModule { serving_base_model: Option, serving_lanes: u32, /// Host-fit served context window from the live ServingPlan. Defaults to - /// `MIN_SERVE_CTX` (runnable floor); `with_serving` sets the real value. + /// `MIN_SERVE_CTX` (runnable floor); `set_serving` sets the real value. serving_context_window: u32, /// How many citizens of the tier's (homogeneous) role template to host. /// Default 1. Driven by `CONTINUUM_PERSONA_FLOOR` at boot — the SAME @@ -339,49 +339,19 @@ impl PersonaSpawnerModule { self.population = population; } - /// Apply the serving daemon's [`ServingPlan`](crate::inference::planning::serving_plan::ServingPlan): - /// every desired role runs the plan's base model, lane count, and host-fit - /// served context window. The daemon makes the honest per-host decision - /// (budget + footprints, GPU-residency, served window); the spawner obeys - /// it. Passing the whole plan by reference (per [[pass-the-model-struct-no-param-hell]]) - /// keeps adding a new serving knob a one-field change, not a signature - /// re-engineer. `None` (or a plan that doesn't fit GPU) keeps the tier's - /// `plan_for_tier` defaults. - pub fn with_serving( - mut self, - plan: Option<&crate::inference::planning::serving_plan::ServingPlan>, - ) -> Self { - if let Some(p) = plan.filter(|p| p.fits_on_gpu) { - self.serving_base_model = Some(p.base_model.model_id.clone()); - self.serving_lanes = p.lanes.max(1); - self.serving_context_window = p - .served_context_window - .max(crate::inference::planning::MIN_SERVE_CTX); - } - self - } - - /// Mutating twin of [`Self::with_serving`] for the resident reconciler: the - /// serving plan changes at runtime (a pin, a tier swap, a lane relaunch) and the - /// roster's seat count follows the LIVE lane count, never the boot-time one. - pub fn set_serving(&mut self, plan: Option<&crate::inference::planning::serving_plan::ServingPlan>) { - match plan { - Some(p) if p.fits_on_gpu => { - self.serving_base_model = Some(p.base_model.model_id.clone()); - self.serving_lanes = p.lanes.max(1); - self.serving_context_window = p - .served_context_window - .max(crate::inference::planning::MIN_SERVE_CTX); - } - // A live plan that does NOT fit the GPU (a CPU-tier node, or a runtime - // downgrade) must never leave the seat count on a stale GPU plan's lanes - // (IntelMac's review of #3798): the marker and the lane count move together — - // both cleared, so `seats()` falls back to the configured population and the - // runnable-floor template. - _ => { - self.serving_base_model = None; - self.serving_lanes = 1; - } + /// Bind the roster to the geometry verified by the serving owner. + pub fn set_serving(&mut self, snapshot: Option<&crate::inference::llama_server::ServingSnapshot>) -> bool { + let applied = snapshot.filter(|s| s.is_live() && s.held_for.is_none() && s.loading_model.is_none() + && s.lanes > 0 && s.served_context_window > 0); + if let Some((serving, model)) = applied.and_then(|s| s.active_model.as_ref().map(|model| (s, model))) { + self.serving_base_model = Some(model.clone()); + self.serving_lanes = serving.lanes; + self.serving_context_window = serving.served_context_window; + true + } else { + self.serving_base_model = None; + self.serving_lanes = 0; + false } } diff --git a/core/continuum-serving/src/modules/serving_daemon/planning.rs b/core/continuum-serving/src/modules/serving_daemon/planning.rs index c107d0aee4..b564ebddc6 100644 --- a/core/continuum-serving/src/modules/serving_daemon/planning.rs +++ b/core/continuum-serving/src/modules/serving_daemon/planning.rs @@ -8,16 +8,6 @@ impl ServingDaemonModule { self.intent.clone() } - /// Compute the current serving plan from the live host snapshot + on-disk - /// models, WITHOUT relying on a tick having run. The boot path calls this - /// to drive the spawner before the tick loop starts — single source of - /// truth for "what model + how many lanes." - pub fn compute_plan(&self) -> Option { - let budget = self.host_budget_snapshot(); - let mut demand = self.serving_demand(); - account_training_leases(&mut demand, &budget.leases); - plan_serving(&budget.host, &self.live_candidates(), &demand) - } /// Recompute the plan from the live host snapshot + on-disk models, publish /// it, and log the decision. Idempotent — safe to call on init and tick. From cc3f55f6d1e2c2358ef740ee51472356c3e2eb80 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Wed, 18 Nov 2026 17:56:37 -0600 Subject: [PATCH 2/2] Leave resident geometry unbound until serving verifies capacity --- .../start_server/persona_host_reconciler.rs | 3 +-- core/continuum-mind/src/persona/host.rs | 13 +++++++----- .../src/persona/spawner_module.rs | 20 ++++++++----------- .../src/modules/serving_daemon/catalog.rs | 1 + .../src/modules/serving_daemon/planning.rs | 10 +++++----- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs b/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs index 27d6a6f812..19a88333fc 100644 --- a/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs +++ b/core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs @@ -136,8 +136,7 @@ pub(super) async fn run_persona_host( let plan_ready = serving_plan_rx .borrow() .as_ref() - .map(|p| p.fits_on_gpu) - .unwrap_or(false); + .is_some_and(|p| p.fits_on_gpu); // Lane-source-agnostic hosting (misfit / grid design): when the // operator pinned an EXTERNAL OpenAI-compatible endpoint, there is // no local lane to "fit on GPU" — enter the ready-check regardless diff --git a/core/continuum-mind/src/persona/host.rs b/core/continuum-mind/src/persona/host.rs index ce6368177f..d2ed266870 100644 --- a/core/continuum-mind/src/persona/host.rs +++ b/core/continuum-mind/src/persona/host.rs @@ -418,13 +418,13 @@ impl PersonaSpawnSupervisor { ) -> Vec { // A pre-1970 clock reads 0 here: every backoff reads as expired: a retry, never a stuck seat. let now = EpochMs::now().millis(); - let map = self.slot_backoff.lock().unwrap_or_else(|e| e.into_inner()); + let map = self.slot_backoff.lock().unwrap_or_else(|e| e.into_inner()); // Preserve the recorded retry deadlines after lock poisoning. filter_by_backoff_with(now, &map, plans) } fn note_slot_failure(&self, persona_id: Uuid, reason: &str) { let now = EpochMs::now().millis(); - let mut map = self.slot_backoff.lock().unwrap_or_else(|e| e.into_inner()); + let mut map = self.slot_backoff.lock().unwrap_or_else(|e| e.into_inner()); // Preserve the recorded retry deadlines after lock poisoning. let entry = map.entry(persona_id).or_insert(SlotBackoff { attempts: 0, until_ms: 0 }); entry.attempts = entry.attempts.saturating_add(1); let delay = backoff_delay(entry.attempts); @@ -681,7 +681,7 @@ impl PersonaSpawnSupervisor { self.note_slot_failure(pid, &format!("{err}")); } summary.failures.push(BootSlotFailure { - slot_index: slot_index.unwrap_or(slot_idx), + slot_index: slot_index.unwrap_or(slot_idx), // Before slot assignment the roster ordinal identifies the failed request. role: Some(role), persona_id, reason: format!("{err}"), @@ -731,7 +731,7 @@ impl PersonaSpawnSupervisor { let quiesced = self .registry .quiesced_flag(persona_id) - .unwrap_or_else(|| std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false))); + .unwrap_or_else(|| std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false))); // An unregistered service starts with a clear quiescence flag. // Her obligation store (card 920619c5), on the same wired executor her hands use. let obligations = crate::persona::obligation::Obligations::new(executor, persona_id, &agent_name); let handle = match spawn_persona_service( @@ -815,7 +815,10 @@ pub(crate) struct SlotBackoff { /// Doubling from 2 s, capped at 10 min: a refused seat is tried again soon in case the /// cause was transient (a daemon mid-restart), then rarely, and never at pass rate. pub(crate) fn backoff_delay(attempts: u32) -> std::time::Duration { - std::time::Duration::from_secs((2u64 << attempts.saturating_sub(1).min(9)).min(600)) + // derived-or-floor: cap retries at the existing ten-minute service backoff even after repeated failures. + const MAX_RETRY_DELAY_SECS: u64 = 600; + let seconds = if attempts > 9 { MAX_RETRY_DELAY_SECS } else { 2u64 << attempts.saturating_sub(1) }; + std::time::Duration::from_secs(seconds) } /// Pure half of the backoff filter. Plans whose persona is inside its backoff are dropped. diff --git a/core/continuum-mind/src/persona/spawner_module.rs b/core/continuum-mind/src/persona/spawner_module.rs index 637b3086f2..aaf712f070 100644 --- a/core/continuum-mind/src/persona/spawner_module.rs +++ b/core/continuum-mind/src/persona/spawner_module.rs @@ -76,10 +76,7 @@ pub struct DesiredRole { /// the serving daemon's ServingPlan. Defaults to 1 from `plan_for_tier`; /// `PersonaSpawnerModule::set_serving` overrides it from the live plan. pub lanes: u32, - /// Host-fit served context window (tokens) the gateway llama-server was - /// launched with — the planner's single source of truth, NOT a constant. - /// Defaults to `MIN_SERVE_CTX` from `plan_for_tier` (runnable floor when no - /// plan is published); `set_serving` overrides it from the live plan. + /// Verified context capacity in tokens. An unbound role has zero capacity. pub served_context_window: u32, } @@ -148,10 +145,9 @@ pub fn plan_for_roles( // real, honest, GPU-residency-aware pick. model_id: "continuum-ai/qwen2.5-coder-1.5b-instruct-GGUF".to_string(), // Default single lane; set_serving overrides from the live plan. - lanes: 1, - // Runnable floor until the serving daemon publishes a host-fit - // window. - served_context_window: crate::inference::planning::MIN_SERVE_CTX, + lanes: 0, + // Geometry is unbound until the serving owner verifies it. + served_context_window: 0, }) .collect() // TODO #133 slice 14: host every declared role after RoleAwareProvider + @@ -208,8 +204,7 @@ pub struct PersonaSpawnerModule { /// actually spawns — single source of truth, not a hardcode. serving_base_model: Option, serving_lanes: u32, - /// Host-fit served context window from the live ServingPlan. Defaults to - /// `MIN_SERVE_CTX` (runnable floor); `set_serving` sets the real value. + /// Context capacity last verified by the serving owner. serving_context_window: u32, /// How many citizens of the tier's (homogeneous) role template to host. /// Default 1. Driven by `CONTINUUM_PERSONA_FLOOR` at boot — the SAME @@ -268,9 +263,9 @@ impl PersonaSpawnerModule { hw_capability, tier_category, serving_base_model: None, - serving_lanes: 1, + serving_lanes: 0, remembered_lanes: None, - serving_context_window: crate::inference::planning::MIN_SERVE_CTX, + serving_context_window: 0, population: 1, citizens: vec![RoleId::Helper], grid_roster: None, @@ -351,6 +346,7 @@ impl PersonaSpawnerModule { } else { self.serving_base_model = None; self.serving_lanes = 0; + self.serving_context_window = 0; false } } diff --git a/core/continuum-serving/src/modules/serving_daemon/catalog.rs b/core/continuum-serving/src/modules/serving_daemon/catalog.rs index b866754ec6..ea4daacce2 100644 --- a/core/continuum-serving/src/modules/serving_daemon/catalog.rs +++ b/core/continuum-serving/src/modules/serving_daemon/catalog.rs @@ -231,6 +231,7 @@ impl ServingDaemonModule { ) } + #[cfg(test)] pub(super) fn live_candidates(&self) -> Vec { let intent = self.intent.snapshot(); servable_candidates(&self.catalog.snapshot(), &intent.suppressed, &intent.pinned) diff --git a/core/continuum-serving/src/modules/serving_daemon/planning.rs b/core/continuum-serving/src/modules/serving_daemon/planning.rs index b564ebddc6..46837e1833 100644 --- a/core/continuum-serving/src/modules/serving_daemon/planning.rs +++ b/core/continuum-serving/src/modules/serving_daemon/planning.rs @@ -350,7 +350,7 @@ impl ServingDaemonModule { target: "continuum_core::modules::serving_daemon", class = "serving.plan.demotion_refused", floor = floor.as_str(), wanted = wanted.as_str(), - incumbent = incumbent.as_deref().unwrap_or(""), + incumbent = incumbent.as_deref().unwrap_or(""), // Diagnostic label for an empty incumbent. usable_gb = (budget.usable_bytes / 1_000_000_000), physical_usable_gb = (self.physical_budget().usable_bytes / 1_000_000_000), @@ -454,7 +454,7 @@ impl ServingDaemonModule { continuum_base::probe!( target: "continuum_core::modules::serving_daemon", class = "serving.plan", decision = "downshift-held", - incumbent = incumbent.as_deref().unwrap_or(""), + incumbent = incumbent.as_deref().unwrap_or(""), // Diagnostic label for an empty incumbent. wanted = plan.base_model.model_id.as_str(), streak, needs_streak = DOWNSHIFT_SUSTAINED_TICKS, @@ -502,7 +502,7 @@ impl ServingDaemonModule { let mut last = self .last_plan_probe .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()); + .unwrap_or_else(|poisoned| poisoned.into_inner()); // Recover the last reported planning decision after lock poisoning. let window_moved = |prev: u32| -> bool { plan.served_context_window.abs_diff(prev) > prev / 8 }; @@ -622,7 +622,7 @@ impl ServingDaemonModule { spike unknown, publishing 0, which DISABLES the prefill deadband", ); } - let spike = spike_of_served.unwrap_or(0); + let spike = spike_of_served.unwrap_or(0); // Zero disables the prefill deadband until the serving spike is known. crate::inference::prefill_spike::publish(spike); // send_replace keeps the latest even with no live receivers yet. self.publish_plan_snapshot(intent_revision, Some(plan)); @@ -636,7 +636,7 @@ impl ServingDaemonModule { let mut last = self .last_plan_probe .lock() - .unwrap_or_else(|poisoned| poisoned.into_inner()); + .unwrap_or_else(|poisoned| poisoned.into_inner()); // Recover the last reported planning decision after lock poisoning. if last.as_ref().map(|(d, _)| d.as_str()) == Some("") { false } else {