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
31 changes: 20 additions & 11 deletions core/continuum-core/src/ipc/start_server/persona_host_reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,19 @@ 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
.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
// 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());
Expand All @@ -168,11 +164,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
Expand All @@ -186,11 +182,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)) => {
Expand Down Expand Up @@ -300,7 +297,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() {
Expand Down
24 changes: 0 additions & 24 deletions core/continuum-core/src/ipc/start_server/persona_hosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 10 additions & 7 deletions core/continuum-mind/src/persona/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -418,13 +418,13 @@ impl PersonaSpawnSupervisor {
) -> Vec<crate::persona::spawner_module::MaterializedPersonaPlan> {
// 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);
Expand Down Expand Up @@ -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}"),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
84 changes: 25 additions & 59 deletions core/continuum-mind/src/persona/spawner_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,9 @@ 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.
/// Verified context capacity in tokens. An unbound role has zero capacity.
pub served_context_window: u32,
}

Expand Down Expand Up @@ -108,7 +105,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
Expand Down Expand Up @@ -144,14 +141,13 @@ 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.
lanes: 1,
// Runnable floor until the serving daemon publishes a host-fit
// window.
served_context_window: crate::inference::planning::MIN_SERVE_CTX,
// Default single lane; set_serving overrides from the live plan.
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 +
Expand Down Expand Up @@ -208,8 +204,7 @@ pub struct PersonaSpawnerModule {
/// actually spawns — single source of truth, not a hardcode.
serving_base_model: Option<String>,
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.
/// 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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -339,49 +334,20 @@ 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;
self.serving_context_window = 0;
false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl ServingDaemonModule {
)
}

#[cfg(test)]
pub(super) fn live_candidates(&self) -> Vec<ModelFootprint> {
let intent = self.intent.snapshot();
servable_candidates(&self.catalog.snapshot(), &intent.suppressed, &intent.pinned)
Expand Down
Loading
Loading