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
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,7 @@ impl LlmDeliberationFaculty {
/// cached last turn at this box's measured prefill rate, plus her last output at its
/// measured decode rate. Read from her LAST turn's shape (`LAST_TURN_SHAPE`) — the
/// prompt is rendered after the gate, so the previous turn is the honest predictor.
/// `None` when any term is unmeasured: an absence is not a number, and the reserve is
/// then not lent (`resource_admission::reserve_lendable`).
/// `None` when any term is unmeasured: an absence is not a number (the probe says so).
fn expected_occupancy(&self) -> Option<std::time::Duration> {
expected_occupancy_for(self.persona_id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub(super) enum GenerationAdmission {
AdapterOwned,
SharedLocal {
_lane: crate::inference::resource_admission::ServingLanePermit,
_prefill: tokio::sync::OwnedSemaphorePermit,
},
}

Expand Down Expand Up @@ -170,20 +169,10 @@ impl LlmDeliberationFaculty {
continuum_base::probe!(
class = "delib.gate.lane_acquired",
persona = %self.persona_name,
"lane admission granted — prefill slot next"
"lane admission granted — issuing the model call"
);
crate::cognition::health_ledger::note_lane_granted_to(self.persona_id);
// #56 prefill throttle: under live external GPU pressure (a game, the browser)
// fewer than the served lane count may PREFILL concurrently — the instant valve
// for the 2026-07-16 compute-buffer OOM. Same fit rule the capacity sim proves;
// no pressure → target == lanes → this never waits. Released with the block.
let _prefill = crate::inference::prefill_throttle::acquire_prefill_slot().await;
continuum_base::probe!(
class = "delib.gate.prefill_acquired",
persona = %self.persona_name,
"prefill slot granted — issuing the model call"
);
Some(GenerationAdmission::SharedLocal { _lane, _prefill })
Some(GenerationAdmission::SharedLocal { _lane })
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,51 +188,39 @@ mod verdicts;

mod turn_bound;

// what this catches (6780e79b): remote calls never poll local lane/prefill admission;
// falling home waits for both resources and cancellation releases a partial lease.
// what this catches (6780e79b): remote calls never poll local lane admission; falling home
// waits for the lane, and cancelling a waiting admission leaves the lane reusable.
#[tokio::test]
async fn remote_admission_bypasses_busy_local_resources_and_home_reacquires() {
use super::admission::{admit_target, GenerationAdmission};
use crate::ai::adapter::GenerationAdmissionOwner;
use crate::inference::resource_admission::{LaneAdmission, LanePriority};
use crate::inference::prefill_throttle::PrefillThrottle;
use std::future::Future;
use std::task::{Context, Poll, Waker};

let lanes: &'static LaneAdmission = Box::leak(Box::new(LaneAdmission::new()));
lanes.set_served_lane_count(1);
let prefill = PrefillThrottle::with_lanes(1);
let held_lane = lanes.acquire_serving_lane(None, LanePriority::Directed, None).await;
let held_prefill = prefill.acquire_prefill_slot().await;
let polls = std::cell::Cell::new(0);
let local = || async {
polls.set(polls.get() + 1);
let lane = lanes.acquire_serving_lane(None, LanePriority::Directed, None).await;
let prefill = prefill.acquire_prefill_slot().await;
Some(GenerationAdmission::SharedLocal { _lane: lane, _prefill: prefill })
Some(GenerationAdmission::SharedLocal { _lane: lane })
};
let mut cx = Context::from_waker(Waker::noop());
let mut remote = Box::pin(admit_target(GenerationAdmissionOwner::Adapter, local()));
assert!(matches!(remote.as_mut().poll(&mut cx), Poll::Ready(Some(GenerationAdmission::AdapterOwned))));
assert_eq!(polls.get(), 0, "remote dispatch must not enter either local queue");
assert_eq!(polls.get(), 0, "remote dispatch must not enter the local queue");
drop(remote);

let mut home = Box::pin(admit_target(GenerationAdmissionOwner::SharedLocal, local()));
assert!(home.as_mut().poll(&mut cx).is_pending(), "local lane is occupied");
drop(home); // cancelled while waiting for the lane
drop(held_lane);
assert!(home.as_mut().poll(&mut cx).is_pending(), "prefill still occupied");
drop(home); // cancelled while holding lane and waiting for prefill
let mut next_lane = Box::pin(lanes.acquire_serving_lane(None, LanePriority::Directed, None));
let Poll::Ready(released) = next_lane.as_mut().poll(&mut cx) else {
panic!("cancelling partial admission must release its lane");
};
drop(released);
drop(next_lane);
drop(held_prefill);
let admission = admit_target(GenerationAdmissionOwner::SharedLocal, local()).await;
assert!(matches!(admission, Some(GenerationAdmission::SharedLocal { .. })));
drop(admission);
// A completed/cancelled call leaves both resources reusable, not just the lane.
// A completed call leaves the lane reusable.
let next = admit_target(GenerationAdmissionOwner::SharedLocal, local()).await;
assert!(matches!(next, Some(GenerationAdmission::SharedLocal { .. })));
}
2 changes: 1 addition & 1 deletion core/continuum-engine/src/capacity/lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn decide_lane(
/// lane owns peer identity); nil only weakens self-exclusion from the heard
/// set, and we do not currently hear our own offers.
pub fn decide_render_lane(leasability: Leasability) -> LaneDecision {
let spike = crate::inference::prefill_throttle::published_spike_bytes();
let spike = crate::inference::prefill_spike::published_bytes();
let free = crate::resources::ResourceDaemon::global()
.and_then(|d| {
d.board()
Expand Down
2 changes: 1 addition & 1 deletion core/continuum-engine/src/inference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod engine_slots;
pub mod lane_footprint;
pub mod prefill_knee;
pub mod prefill_rate;
pub mod prefill_throttle;
pub mod prefill_spike;
pub mod served_window_store;
pub mod serving_rates;
pub mod lane_registry;
Expand Down
25 changes: 25 additions & 0 deletions core/continuum-engine/src/inference/prefill_spike.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! The served model's per-prefill compute-buffer bytes, published by the serving plan and
//! read by grid placement (`capacity::lease::decide_render_lane`).
//!
//! This was the prefill throttle (#56): a semaphore that let only as many served lanes
//! prefill at once as live free GPU could hold one compute-buffer spike each. One
//! llama-server context reserves its worst-case compute graph once, at load, and packs
//! every slot's tokens into each `llama_decode`, so concurrent prefills in one engine draw
//! no extra transient memory. The throttle guarded nothing and serialized prefill: on the
//! M5 it held 1 permit 22.5% and 2 permits 49.4% of 87 minutes for four minds, and a mind
//! that already held a lane waited a median 24.6 s (p90 83 s) for it before her model call
//! (2026-10-28, build 7ace74020, 161 acts). The fact it carried stays; the gate is gone.

use std::sync::atomic::{AtomicU64, Ordering};

static SPIKE_BYTES: AtomicU64 = AtomicU64::new(0);

/// Publish the served model's per-prefill compute-buffer bytes (0 = unknown).
pub fn publish(spike_bytes: u64) {
SPIKE_BYTES.store(spike_bytes, Ordering::Release);
}

/// The last published per-prefill bytes; 0 until a plan publishes one.
pub fn published_bytes() -> u64 {
SPIKE_BYTES.load(Ordering::Acquire)
}
Loading
Loading