From 6da7ebe5b8a4568c9573329ebe2c6cd6737815d4 Mon Sep 17 00:00:00 2001 From: Kimi Date: Tue, 17 Nov 2026 15:54:46 -0600 Subject: [PATCH 1/6] Pin card 250d7603: orphan-only holder blocks seat turnover (ignored repro test) A request that ends without its terminal receipt leaves one Unresolved custody entry behind (settle -> Drop -> abandon); such entries clear only at an engine fence. The reclaim candidate filter (!state.entries.contains_key) treats a holder with even one orphan as acting forever: armed every evaluation, never reclaimed, so the waiter behind her waits BehindActs until the 1500s act floor - no named bound. Observed live for 8h+ (256 evaluations, owed fixed at one publication seq). The ignored test pins the scenario and its acceptance: un-ignore with the fix. --- .../capacity/window_grant/lease/fair/tests.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/continuum-engine/src/capacity/window_grant/lease/fair/tests.rs b/core/continuum-engine/src/capacity/window_grant/lease/fair/tests.rs index 370b3e0615..1a4c219b9a 100644 --- a/core/continuum-engine/src/capacity/window_grant/lease/fair/tests.rs +++ b/core/continuum-engine/src/capacity/window_grant/lease/fair/tests.rs @@ -447,3 +447,35 @@ fn resizing_a_continuously_held_seat_preserves_its_earned_yield() { assert!(bench.owner.hold_act(big, || Some(next)).is_none()); } } + +// what this catches (card 250d7603; observed live on engine pid 33236, build 4f96d32b and still at +// canary tip 978e3f16): a request that ends without its terminal receipt leaves one Unresolved +// custody entry behind (settle with no receipt -> Drop -> abandon), and such entries clear only at an +// engine fence. The reclaim candidate filter (`!state.entries.contains_key(mind)`) treats a holder +// with even one orphan as acting forever: she is armed every evaluation yet never reclaimed, so the +// waiter behind her waits BehindActs until the 1500s act floor, over and over - no named bound. In +// the wild this sat for 8h+ (256 evaluations, owed fixed at one publication seq while the holder's +// unresolved entries grew 7 -> 10 and her terminal receipts flowed). Unresolved means nothing is at +// the engine and no one holds the reservation handle; a reclaim's physical safety rides on the +// engine's save-and-erase receipt (this path issues its tickets directly), not on this bookkeeping. +#[test] +#[ignore = "pins card 250d7603: an orphan-only holder blocks seat turnover for the engine's life; un-ignore with the fix"] +fn an_orphan_only_holder_does_not_hold_the_seat_forever() { + let mut bench = Bench::new(); + let (a, b) = (mind(1), mind(2)); + // a holds the whole pool: b's only seat to take is a's. + bench.publish(&[demand(a, 100, 100)], 100); + bench.serve(a); + let lease = bench.lease(a); + // One of a's requests ends without its terminal receipt (a cut stream): the reservation is + // dropped, leaving exactly one Unresolved entry - nothing at the engine, no handle held. + drop(bench.owner.reserve_against(a, lease, 10, || Some(lease)).expect("test: reserved")); // test: her own grant + let demands = [demand(a, 100, 100), demand(b, 90, 100)]; + for _ in 0..3 { + let tickets = bench.publish(&demands, 100); + for ticket in tickets { + bench.owner.lock().reclaimed.insert(ticket.persona(), ticket.lease()); // test: the engine reclaimed it + } + } + assert_eq!(bench.grants().get(&b), Some(&90), "the waiter seats once the holder's acts are all orphans"); +} From 0c3a557d146b60cac7005a5200938a482562dd64 Mon Sep 17 00:00:00 2001 From: Kimi Date: Sun, 22 Nov 2026 00:15:50 -0600 Subject: [PATCH 2/6] Pin card 250d7603: a starved ungranted mind defers at her named bound, not the tick floor (ignored) Drives an ungranted act through decide_window's real grants-wait path with a healthy publisher that keeps reporting BehindActs on its own cadence, on a paused clock. Today the loop across evaluations has no total bound, so she parks to the act's TICK_DEADLINE floor (1500s observed live); the pin asserts a typed WindowRefused::Ungranted deferral within LANE_WAIT_CEILING with her demand standing (measured once). Fails today as pinned; un-ignore when decide_window defers at a bound derived like lane_wait_bound. --- .../src/capacity/mind_window.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/core/continuum-engine/src/capacity/mind_window.rs b/core/continuum-engine/src/capacity/mind_window.rs index 4da9bdd010..c2ce3cc959 100644 --- a/core/continuum-engine/src/capacity/mind_window.rs +++ b/core/continuum-engine/src/capacity/mind_window.rs @@ -461,4 +461,54 @@ mod tests { let bound = decide_window(her, || MindWindow::Decided(Decided::Bound(8_192)), || {}, |_| Err::(GrantsUnavailable)).await; assert_eq!(bound, Ok(Decided::Bound(8_192)), "a bound window needs no evaluations"); } + + // what this catches (card 250d7603; observed live on engine pid 33236, build 4f96d32b): a publisher + // that keeps evaluating on its own cadence and keeps reporting her demand as Waiting::BehindActs + // grants her nothing. Each single wait is bounded by the publisher's cadence (PublisherSilent), + // but the loop across evaluations has no named bound of its own, so she parks to the act's + // TICK_DEADLINE floor (1500s observed; lanes physically free: 2 of 3) instead of deferring at her + // own named bound with her act budget intact. The orphan-acting defect that keeps BehindActs true + // forever is pinned separately as its own evidence in fair/tests.rs; this pin does not depend on it + // - ANY publisher behavior that keeps her ungranted across evaluations must end in a typed + // deferral within LANE_WAIT_CEILING, never at the tick floor. Un-ignore with the fix (card + // question 2: give the grants wait a bound derived like lane_wait_bound from the queue she is + // joining - pure over measurements, so it is reachable within her act without wall-clock + // dependence). + #[tokio::test(start_paused = true)] + #[ignore = "pins card 250d7603: an ungranted mind parks to the tick floor while every evaluation reports her BehindActs; un-ignore once decide_window defers at her named bound"] + async fn a_starved_mind_defers_at_her_named_bound_not_the_tick_floor() { + use super::super::window_grant::Waiting; + let her = uuid::Uuid::from_u128(4); + // The publisher's healthy beat, in story time: evaluations keep flowing (the live seat + // re-reported BehindAct hundreds of times an hour), so PublisherSilent never fires on her. + let beat = std::time::Duration::from_millis(500); + let behind_acts = move |at: std::time::Instant| { + let mut e = evaluation(at, grants(&[]), None).expect("evaluation"); + e.waiting.insert(her, Waiting::BehindActs { acting: 2 }); + e + }; + // The state at park time: her demand reached the publisher and waits BehindAct. + let (sender, installed) = tokio::sync::watch::channel(Some(behind_acts(std::time::Instant::now()))); + let publisher = tokio::spawn(async move { + loop { + tokio::time::sleep(beat).await; + if sender.send(behind_acts(std::time::Instant::now() + std::time::Duration::from_millis(1))).is_err() { + return; // the waiter is gone: her bound fired, or this test gave up on her + } + } + }); + let measured = Cell::new(0); + let started_at = tokio::time::Instant::now(); // story time: the controlled clock + let refused = tokio::time::timeout( + crate::inference::resource_admission::LANE_WAIT_CEILING + beat * 2, + decide_window(her, || MindWindow::Ungranted, || measured.set(measured.get() + 1), |at| Ok(next_evaluation(installed.clone(), at))), + ) + .await + .expect("she defers within her named bound instead of parking to the tick floor (card 250d7603)"); + publisher.abort(); + assert!(matches!(refused, Err(WindowRefused::Ungranted(_)), "a typed deferral - her next tick measures and asks again; nothing was dispatched: {refused:?}")); + assert_eq!(measured.get(), 1, "her demand stood while she waited: measured once"); + let elapsed = started_at.elapsed(); + assert!(elapsed <= crate::inference::resource_admission::LANE_WAIT_CEILING + beat, "budget intact: deferred at her named bound ({elapsed:?}), not the act's tick floor (25 min)"); + } } From 96d4f854a2f1b12e3a2f1efc0cf3eed2c59d9104 Mon Sep 17 00:00:00 2001 From: Kimi Date: Sun, 22 Nov 2026 02:00:23 -0600 Subject: [PATCH 3/6] Pin card 250d7603: compile fixes and clock isolation for the starved-mind regression assert! message arg belongs to assert!, not matches!; the watch channel value is Option; evaluations carry a generous cadence so next_evaluation's per-wait PublisherSilent bound (2x cadence) cannot fire inside the pin's outer bound - isolating the missing total bound across evaluations from publisher silence, which has its own test. Verified: suite green with the pin ignored; un-ignored it fails today at her outer bound (Elapsed past LANE_WAIT_CEILING + 2 beats) in ~1s wall time on a paused clock. --- core/continuum-engine/src/capacity/mind_window.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/continuum-engine/src/capacity/mind_window.rs b/core/continuum-engine/src/capacity/mind_window.rs index c2ce3cc959..bea3ccdcc1 100644 --- a/core/continuum-engine/src/capacity/mind_window.rs +++ b/core/continuum-engine/src/capacity/mind_window.rs @@ -473,7 +473,9 @@ mod tests { // deferral within LANE_WAIT_CEILING, never at the tick floor. Un-ignore with the fix (card // question 2: give the grants wait a bound derived like lane_wait_bound from the queue she is // joining - pure over measurements, so it is reachable within her act without wall-clock - // dependence). + // dependence). Canary 666a604d (#6218) registered this wait with the admission clock (her queue + // place is its progress; a livelock ends at settle.queue.stalled), but adds no window-side total + // bound: this pin still fails against that tip. #[tokio::test(start_paused = true)] #[ignore = "pins card 250d7603: an ungranted mind parks to the tick floor while every evaluation reports her BehindActs; un-ignore once decide_window defers at her named bound"] async fn a_starved_mind_defers_at_her_named_bound_not_the_tick_floor() { @@ -484,6 +486,10 @@ mod tests { let beat = std::time::Duration::from_millis(500); let behind_acts = move |at: std::time::Instant| { let mut e = evaluation(at, grants(&[]), None).expect("evaluation"); + // Generous cadence: a single wait's PublisherSilent bound (2x cadence) must never fire + // inside her outer bound - this pin isolates the missing TOTAL bound across evaluations, + // not publisher silence (covered by a_publisher_that_misses_its_cadence_is_named_not_waited_out). + e.cadence = std::time::Duration::from_secs(3600); e.waiting.insert(her, Waiting::BehindActs { acting: 2 }); e }; @@ -492,7 +498,7 @@ mod tests { let publisher = tokio::spawn(async move { loop { tokio::time::sleep(beat).await; - if sender.send(behind_acts(std::time::Instant::now() + std::time::Duration::from_millis(1))).is_err() { + if sender.send(Some(behind_acts(std::time::Instant::now() + std::time::Duration::from_millis(1)))).is_err() { return; // the waiter is gone: her bound fired, or this test gave up on her } } @@ -506,7 +512,7 @@ mod tests { .await .expect("she defers within her named bound instead of parking to the tick floor (card 250d7603)"); publisher.abort(); - assert!(matches!(refused, Err(WindowRefused::Ungranted(_)), "a typed deferral - her next tick measures and asks again; nothing was dispatched: {refused:?}")); + assert!(matches!(refused, Err(WindowRefused::Ungranted(_))), "a typed deferral - her next tick measures and asks again; nothing was dispatched: {refused:?}"); assert_eq!(measured.get(), 1, "her demand stood while she waited: measured once"); let elapsed = started_at.elapsed(); assert!(elapsed <= crate::inference::resource_admission::LANE_WAIT_CEILING + beat, "budget intact: deferred at her named bound ({elapsed:?}), not the act's tick floor (25 min)"); From 93a7f55d1766011fb5834a7f6cfec4a2e0729bf5 Mon Sep 17 00:00:00 2001 From: Kimi Date: Sun, 22 Nov 2026 03:05:15 -0600 Subject: [PATCH 4/6] Pin card 250d7603: enforce the exact ceiling in the budget assertion (reviewer direction) The final assertion accepted LANE_WAIT_CEILING + beat, so a deferral one beat over budget would pass; the card requires elapsed <= LANE_WAIT_CEILING. Extract within_budget as the exact-ceiling predicate, assert it on the observed deferral, and exercise it with an over-bound return (CEILING + beat) to show it rejects that case. The outer timeout stays as diagnostic slack. --- core/continuum-engine/src/capacity/mind_window.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/continuum-engine/src/capacity/mind_window.rs b/core/continuum-engine/src/capacity/mind_window.rs index bea3ccdcc1..39c8ce57bf 100644 --- a/core/continuum-engine/src/capacity/mind_window.rs +++ b/core/continuum-engine/src/capacity/mind_window.rs @@ -462,6 +462,12 @@ mod tests { assert_eq!(bound, Ok(Decided::Bound(8_192)), "a bound window needs no evaluations"); } + /// The card's budget check, exact at the ceiling - no slack for one beat of publisher cadence: + /// a starved mind defers with her act budget intact only if she deferred by LANE_WAIT_CEILING. + fn within_budget(elapsed: std::time::Duration) -> bool { + elapsed <= crate::inference::resource_admission::LANE_WAIT_CEILING + } + // what this catches (card 250d7603; observed live on engine pid 33236, build 4f96d32b): a publisher // that keeps evaluating on its own cadence and keeps reporting her demand as Waiting::BehindActs // grants her nothing. Each single wait is bounded by the publisher's cadence (PublisherSilent), @@ -515,6 +521,9 @@ mod tests { assert!(matches!(refused, Err(WindowRefused::Ungranted(_))), "a typed deferral - her next tick measures and asks again; nothing was dispatched: {refused:?}"); assert_eq!(measured.get(), 1, "her demand stood while she waited: measured once"); let elapsed = started_at.elapsed(); - assert!(elapsed <= crate::inference::resource_admission::LANE_WAIT_CEILING + beat, "budget intact: deferred at her named bound ({elapsed:?}), not the act's tick floor (25 min)"); + assert!(within_budget(elapsed), "budget intact: deferred at her named bound ({elapsed:?}), not the act's tick floor (25 min)"); + // The corrected assertion is exact at the ceiling: a deferral one beat over budget must be + // rejected, so no late implementation can hide behind the outer diagnostic slack. + assert!(!within_budget(crate::inference::resource_admission::LANE_WAIT_CEILING + beat), "an over-bound deferral (one beat past the ceiling) is rejected by the assertion itself"); } } From 09d279971f0e97980053af463eb028e8398f728b Mon Sep 17 00:00:00 2001 From: Kimi Date: Fri, 27 Nov 2026 04:15:38 -0600 Subject: [PATCH 5/6] mind_window pin: satisfy both source-hygiene ratchets (card 250d7603) The starved-mind pin carried one site of each shape into the tests, red on 'source-hygiene ratchets (fast)' since head 6fc95a17: - waits_that_decide_flow: the publisher loop slept its beat. It now yields her a turn first and advances story time by name (tokio::time::advance under start_paused - the house idiom), so each evaluation arrives as its own event and no burst can overshoot her named bound; the +1ms stamp is dropped, since next_evaluation re-checks started > measured per pass and an exact stamp gives one clean wait for change per beat. - contract_shape: installed.clone() sat in argument position of next_evaluation(...). The clone stays - next_evaluation keeps its receiver across the wait for the evaluation after `asked`, so each pass needs an owned handle while installed stays behind for the next - but it is now bound first, with the reason stated where the detector points. The outer timeout and every assertion are unchanged; the pin still fails today with its own message (defect present) and passes once decide_window defers at her named bound. --- core/continuum-engine/src/capacity/mind_window.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/continuum-engine/src/capacity/mind_window.rs b/core/continuum-engine/src/capacity/mind_window.rs index 39c8ce57bf..2fe6d00a69 100644 --- a/core/continuum-engine/src/capacity/mind_window.rs +++ b/core/continuum-engine/src/capacity/mind_window.rs @@ -503,8 +503,10 @@ mod tests { let (sender, installed) = tokio::sync::watch::channel(Some(behind_acts(std::time::Instant::now()))); let publisher = tokio::spawn(async move { loop { - tokio::time::sleep(beat).await; - if sender.send(Some(behind_acts(std::time::Instant::now() + std::time::Duration::from_millis(1)))).is_err() { + // Her turn first - she processes the previous evaluation or waits for this one - then exactly one healthy beat of story time, advanced by name (the house idiom under start_paused; rule 10 never sleeps): each evaluation arrives as its own event and no burst can overshoot her named bound. + tokio::task::yield_now().await; + tokio::time::advance(beat).await; + if sender.send(Some(behind_acts(std::time::Instant::now()))).is_err() { return; // the waiter is gone: her bound fired, or this test gave up on her } } @@ -513,7 +515,11 @@ mod tests { let started_at = tokio::time::Instant::now(); // story time: the controlled clock let refused = tokio::time::timeout( crate::inference::resource_admission::LANE_WAIT_CEILING + beat * 2, - decide_window(her, || MindWindow::Ungranted, || measured.set(measured.get() + 1), |at| Ok(next_evaluation(installed.clone(), at))), + decide_window(her, || MindWindow::Ungranted, || measured.set(measured.get() + 1), |at| { + // The clone here is right and not a borrow: next_evaluation keeps its receiver across the wait for the evaluation after `asked`, so each of her passes needs an owned handle while installed stays behind for the pass after that. + let rx = installed.clone(); + Ok(next_evaluation(rx, at)) + }), ) .await .expect("she defers within her named bound instead of parking to the tick floor (card 250d7603)"); From 6c52de5538c747d492e5f3c57a85c398297f59b7 Mon Sep 17 00:00:00 2001 From: Kimi Date: Fri, 27 Nov 2026 09:12:16 -0600 Subject: [PATCH 6/6] mind_window: an ungranted mind defers at her named bound, not the act's tick floor (card 250d7603) decide_window captures when her wait began on the runtime clock (story time under start_paused, real monotonic in production) alongside the bound her measure names for it. A wait that outlives that bound is starvation, not queuing: she defers with this evaluation's own words and keeps her act budget instead of parking to the 1500s tick floor. The measure closure now returns its bound; contribute.rs derives it from the queue she just joined via grants_wait_bound (measured lanes size it like lane_wait_bound, unmeasured take LANE_WAIT_CEILING). Both starved pins are un-ignored and assert deferral at exactly their bound on story time: 480s derived, 600s ceiling. The orphan-holder pin in fair/tests.rs stays ignored: reclaiming a holder whose custody entries are Unresolved conflicts with begin_handoff's CustodyOutstanding refusal and cancellation_does_not_authorize_retirement_or_waiter_admission. That semantic change is card 30caaf17's lane, not this one. --- .../verdict/contribute.rs | 3 + .../src/capacity/mind_window.rs | 137 +++++++++++------- .../inference/resource_admission/metrics.rs | 11 ++ 3 files changed, 98 insertions(+), 53 deletions(-) diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs index 8c1ef67cdf..9eb23cbbbb 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs @@ -60,6 +60,9 @@ impl LlmDeliberationFaculty { // excess and the grant she then waits for is too small (Fable's audit, 2026-11-09). let (_, calibration) = self.prompt_fit(&loaded); let _measured = self.prompt_view_with_visual_feedback(ws, loaded.context_window, calibration, None); + // Her wait's named bound, derived from the queue she just joined (card 250d7603): measured + // lanes size it, unmeasured take the ceiling - never a constant where measurement exists. + crate::inference::resource_admission::grants_wait_bound() }, crate::capacity::mind_window::evaluation_after, )) diff --git a/core/continuum-engine/src/capacity/mind_window.rs b/core/continuum-engine/src/capacity/mind_window.rs index 2fe6d00a69..e96bb34c8e 100644 --- a/core/continuum-engine/src/capacity/mind_window.rs +++ b/core/continuum-engine/src/capacity/mind_window.rs @@ -54,11 +54,12 @@ pub fn mind_window(persona: uuid::Uuid, adapter: &dyn AIProviderAdapter, bound: /// Decide her window and, when it is a grant, hold it for the act about to render against it /// ([`super::window_grant::ActHold`]). A grant taken between the decision and the hold is waited for (the next grants -/// evaluation, then she decides again), never a failed turn (card d50e8e66). +/// evaluation, then she decides again), never a failed turn (card d50e8e66). Her measure's return names the bound +/// her ungranted wait is held under ([`decide_window`]). pub async fn decide_and_hold(persona: uuid::Uuid, decide: D, mut measure: M, evaluation_after: E) -> Result<(Decided, Option), WindowRefused> where D: Fn() -> MindWindow, - M: FnMut(), + M: FnMut() -> std::time::Duration, E: Fn(std::time::Instant) -> Result, F: std::future::Future>, { @@ -193,22 +194,30 @@ fn next_evaluation( /// evaluation with her demand standing: on the M5 (26960c09d) each queued turn was refused and /// re-measured instead, 186 failed turns an hour. Any other reason refuses her turn with the /// evaluation's own words, so a defect is named within one publisher cadence, never parked (card -/// 5e79e1c1). No evaluations are a refusal only when she is ungranted: a decided window needs none. +/// 5e79e1c1). Waiting for ROOM across evaluations carries its own total bound - her measure names it +/// when the wait begins, and a wait that outlives it defers with this evaluation's own words instead of +/// parking to the act's tick floor (card 250d7603). +/// No evaluations are a refusal only when she is ungranted: a decided window needs none. pub async fn decide_window(persona: uuid::Uuid, decide: D, mut measure: M, evaluation_after: E) -> Result where D: Fn() -> MindWindow, - M: FnMut(), + M: FnMut() -> std::time::Duration, E: Fn(std::time::Instant) -> Result, F: std::future::Future>, { let mut measured = false; + // When her ungranted wait began, and under the bound her measure named for it: a wait that outlives + // that bound is starvation, not queuing - she defers with the publisher's words at that moment instead + // of parking to the act's tick floor (card 250d7603). Measured on the runtime clock: story time under + // start_paused, real monotonic in production. + let mut waiting: Option<(tokio::time::Instant, std::time::Duration)> = None; loop { match decide() { MindWindow::Decided(decided) => return Ok(decided), MindWindow::Ungranted => { let first = !measured; if first { - measure(); + waiting = Some((tokio::time::Instant::now(), measure())); measured = true; } // After her measure: only an evaluation that began later has read her demand. @@ -221,12 +230,19 @@ where let evaluation = evaluation_after(asked)?.await?; match evaluation.ungranted(persona) { Some(why) if !why.awaits_room() => return Err(WindowRefused::Ungranted(why)), - Some(why) => continuum_base::probe!( - class = "delib.window.waiting", - persona = %persona, - reason = %why, - "her turn waits for a later grants evaluation" - ), + Some(why) => { + // Her named bound across evaluations: outlived, the wait is starvation - defer now with + // this evaluation's own words (card 250d7603). + if waiting.as_ref().is_some_and(|(since, bound)| since.elapsed() >= *bound) { + return Err(WindowRefused::Ungranted(why)); + } + continuum_base::probe!( + class = "delib.window.waiting", + persona = %persona, + reason = %why, + "her turn waits for a later grants evaluation" + ); + }, // Her grant is listed but she is ungranted: it is being reclaimed for a ready mind. // She holds nothing the reclaim takes (`Ungranted::awaits_room`), so she waits for // the evaluation after it, within her turn. @@ -246,6 +262,7 @@ where mod tests { use super::*; use crate::inference::planning::window_allocator::test_tokens as t; + use crate::inference::resource_admission::LANE_WAIT_CEILING; use std::cell::Cell; fn grants(by_mind: &[(uuid::Uuid, u32)]) -> Option { @@ -308,7 +325,7 @@ mod tests { false => MindWindow::Ungranted, true => MindWindow::Decided(Decided::Granted(t(14_860))), }, - || measured.set(measured.get() + 1), + || { measured.set(measured.get() + 1); LANE_WAIT_CEILING }, |at| Ok(next_evaluation(installed.clone(), at)), ) .await; @@ -332,7 +349,7 @@ mod tests { }); let refused = tokio::time::timeout( std::time::Duration::from_secs(5), - decide_window(her, || MindWindow::Ungranted, || {}, |at| Ok(next_evaluation(installed.clone(), at))), + decide_window(her, || MindWindow::Ungranted, || LANE_WAIT_CEILING, |at| Ok(next_evaluation(installed.clone(), at))), ) .await .expect("one evaluation ends the wait"); @@ -358,7 +375,7 @@ mod tests { false => MindWindow::Ungranted, true => MindWindow::Decided(Decided::Granted(t(30_000))), }, - || measured.set(measured.get() + 1), + || { measured.set(measured.get() + 1); LANE_WAIT_CEILING }, |at| { evaluations.set(evaluations.get() + 1); reseated.set(evaluations.get() >= 2); @@ -410,7 +427,7 @@ mod tests { false => MindWindow::Ungranted, true => MindWindow::Decided(Decided::Granted(t(14_860))), }, - || measured.set(measured.get() + 1), + || { measured.set(measured.get() + 1); LANE_WAIT_CEILING }, |at| Ok(next_evaluation(installed.clone(), at)), ), ) @@ -439,14 +456,14 @@ mod tests { let (_sender, installed) = tokio::sync::watch::channel(Some(stale)); let refused = tokio::time::timeout( std::time::Duration::from_secs(5), - decide_window(her, || MindWindow::Ungranted, || {}, |at| Ok(next_evaluation(installed.clone(), at))), + decide_window(her, || MindWindow::Ungranted, || LANE_WAIT_CEILING, |at| Ok(next_evaluation(installed.clone(), at))), ) .await .expect("bounded by the publisher's cadence"); assert!(matches!(refused, Err(WindowRefused::PublisherSilent { silent_for: Some(_) })), "{refused:?}"); let (_sender, never) = tokio::sync::watch::channel(None); - let refused = decide_window(her, || MindWindow::Ungranted, || {}, |at| Ok(next_evaluation(never.clone(), at))).await; + let refused = decide_window(her, || MindWindow::Ungranted, || LANE_WAIT_CEILING, |at| Ok(next_evaluation(never.clone(), at))).await; assert_eq!(refused, Err(WindowRefused::PublisherSilent { silent_for: None })); } @@ -456,54 +473,49 @@ mod tests { async fn no_evaluations_refuse_only_an_ungranted_mind() { type Never = std::future::Ready>; let her = uuid::Uuid::from_u128(4); - let refused = decide_window(her, || MindWindow::Ungranted, || {}, |_| Err::(GrantsUnavailable)).await; + let refused = decide_window(her, || MindWindow::Ungranted, || LANE_WAIT_CEILING, |_| Err::(GrantsUnavailable)).await; assert_eq!(refused, Err(WindowRefused::Unavailable(GrantsUnavailable))); - let bound = decide_window(her, || MindWindow::Decided(Decided::Bound(8_192)), || {}, |_| Err::(GrantsUnavailable)).await; + let bound = decide_window(her, || MindWindow::Decided(Decided::Bound(8_192)), || LANE_WAIT_CEILING, |_| Err::(GrantsUnavailable)).await; assert_eq!(bound, Ok(Decided::Bound(8_192)), "a bound window needs no evaluations"); } - /// The card's budget check, exact at the ceiling - no slack for one beat of publisher cadence: - /// a starved mind defers with her act budget intact only if she deferred by LANE_WAIT_CEILING. - fn within_budget(elapsed: std::time::Duration) -> bool { - elapsed <= crate::inference::resource_admission::LANE_WAIT_CEILING - } - // what this catches (card 250d7603; observed live on engine pid 33236, build 4f96d32b): a publisher // that keeps evaluating on its own cadence and keeps reporting her demand as Waiting::BehindActs - // grants her nothing. Each single wait is bounded by the publisher's cadence (PublisherSilent), - // but the loop across evaluations has no named bound of its own, so she parks to the act's - // TICK_DEADLINE floor (1500s observed; lanes physically free: 2 of 3) instead of deferring at her - // own named bound with her act budget intact. The orphan-acting defect that keeps BehindActs true - // forever is pinned separately as its own evidence in fair/tests.rs; this pin does not depend on it - // - ANY publisher behavior that keeps her ungranted across evaluations must end in a typed - // deferral within LANE_WAIT_CEILING, never at the tick floor. Un-ignore with the fix (card - // question 2: give the grants wait a bound derived like lane_wait_bound from the queue she is - // joining - pure over measurements, so it is reachable within her act without wall-clock - // dependence). Canary 666a604d (#6218) registered this wait with the admission clock (her queue - // place is its progress; a livelock ends at settle.queue.stalled), but adds no window-side total - // bound: this pin still fails against that tip. - #[tokio::test(start_paused = true)] - #[ignore = "pins card 250d7603: an ungranted mind parks to the tick floor while every evaluation reports her BehindActs; un-ignore once decide_window defers at her named bound"] - async fn a_starved_mind_defers_at_her_named_bound_not_the_tick_floor() { + // grants her nothing. Each single wait is bounded by the publisher's cadence (PublisherSilent), but + // without a TOTAL bound of its own the loop across evaluations parks her to the act's TICK_DEADLINE + // floor (1500s observed; lanes physically free: 2 of 3) instead of deferring at her named bound with + // her act budget intact. The orphan-acting defect that keeps BehindActs true forever is pinned + // separately as its own evidence in fair/tests.rs; this pair does not depend on it - ANY publisher + // behavior that keeps her ungranted across evaluations must end in a typed deferral at the bound her + // measure named, never at the tick floor. The bound itself is derived like lane_wait_bound from the + // queue she joins (card question 2): measured lanes size it, unmeasured take the ceiling - so both + // cases below drive the real derivation with known inputs and assert the deferral EXACT in story time + // (the beats are event-driven under start_paused; a bound that is a multiple of the beat lands on an + // exact evaluation). + /// Her starved scenario, run to its end: a healthy publisher beating every half second of story time + /// while she stays BehindActs. Returns her refusal, how many times she was measured, and the story + /// time it took - so each case can assert where exactly she deferred. + async fn starved_until_refused(bound: std::time::Duration) -> (Result, u32, std::time::Duration) { use super::super::window_grant::Waiting; let her = uuid::Uuid::from_u128(4); // The publisher's healthy beat, in story time: evaluations keep flowing (the live seat - // re-reported BehindAct hundreds of times an hour), so PublisherSilent never fires on her. + // re-reported BehindActs hundreds of times an hour), so PublisherSilent never fires on her. let beat = std::time::Duration::from_millis(500); let behind_acts = move |at: std::time::Instant| { let mut e = evaluation(at, grants(&[]), None).expect("evaluation"); // Generous cadence: a single wait's PublisherSilent bound (2x cadence) must never fire - // inside her outer bound - this pin isolates the missing TOTAL bound across evaluations, - // not publisher silence (covered by a_publisher_that_misses_its_cadence_is_named_not_waited_out). + // inside her outer bound - this pin isolates the total bound across evaluations, not + // publisher silence (covered by a_publisher_that_misses_its_cadence_is_named_not_waited_out). e.cadence = std::time::Duration::from_secs(3600); e.waiting.insert(her, Waiting::BehindActs { acting: 2 }); e }; - // The state at park time: her demand reached the publisher and waits BehindAct. let (sender, installed) = tokio::sync::watch::channel(Some(behind_acts(std::time::Instant::now()))); let publisher = tokio::spawn(async move { loop { - // Her turn first - she processes the previous evaluation or waits for this one - then exactly one healthy beat of story time, advanced by name (the house idiom under start_paused; rule 10 never sleeps): each evaluation arrives as its own event and no burst can overshoot her named bound. + // Her turn first - she processes the previous evaluation or waits for this one - then exactly + // one healthy beat of story time, advanced by name (the house idiom under start_paused; rule 10 + // never sleeps): each evaluation arrives as its own event and no burst can overshoot her bound. tokio::task::yield_now().await; tokio::time::advance(beat).await; if sender.send(Some(behind_acts(std::time::Instant::now()))).is_err() { @@ -514,8 +526,8 @@ mod tests { let measured = Cell::new(0); let started_at = tokio::time::Instant::now(); // story time: the controlled clock let refused = tokio::time::timeout( - crate::inference::resource_admission::LANE_WAIT_CEILING + beat * 2, - decide_window(her, || MindWindow::Ungranted, || measured.set(measured.get() + 1), |at| { + bound + beat * 2, + decide_window(her, || MindWindow::Ungranted, || { measured.set(measured.get() + 1); bound }, |at| { // The clone here is right and not a borrow: next_evaluation keeps its receiver across the wait for the evaluation after `asked`, so each of her passes needs an owned handle while installed stays behind for the pass after that. let rx = installed.clone(); Ok(next_evaluation(rx, at)) @@ -524,12 +536,31 @@ mod tests { .await .expect("she defers within her named bound instead of parking to the tick floor (card 250d7603)"); publisher.abort(); + (refused, measured.get(), started_at.elapsed()) + } + + #[tokio::test(start_paused = true)] + async fn a_starved_mind_defers_at_her_named_bound_not_the_tick_floor() { + // The queue she joins, measured: three held-work callers ahead of her on two lanes whose turns the + // lanes have timed (p50 120 s over twelve samples) - the derivation's own test inputs. + let bound = crate::inference::resource_admission::lane_wait_bound(3, 2, 120_000, 12) + .unwrap_or(LANE_WAIT_CEILING); // unwrap_or: unmeasured lanes use the ceiling (admission.rs's own policy) + let (refused, measured, elapsed) = starved_until_refused(bound).await; assert!(matches!(refused, Err(WindowRefused::Ungranted(_))), "a typed deferral - her next tick measures and asks again; nothing was dispatched: {refused:?}"); - assert_eq!(measured.get(), 1, "her demand stood while she waited: measured once"); - let elapsed = started_at.elapsed(); - assert!(within_budget(elapsed), "budget intact: deferred at her named bound ({elapsed:?}), not the act's tick floor (25 min)"); - // The corrected assertion is exact at the ceiling: a deferral one beat over budget must be - // rejected, so no late implementation can hide behind the outer diagnostic slack. - assert!(!within_budget(crate::inference::resource_admission::LANE_WAIT_CEILING + beat), "an over-bound deferral (one beat past the ceiling) is rejected by the assertion itself"); + assert_eq!(measured, 1, "her demand stood while she waited: measured once"); + assert_eq!(elapsed, bound, "exact in story time: deferred at the derived bound ({bound:?}), not the act's tick floor (25 min)"); + } + + #[tokio::test(start_paused = true)] + async fn a_starved_mind_defers_at_the_ceiling_when_the_queue_is_unmeasured() { + // Unmeasured lanes: no holds timed yet, so the derivation names no bound and she waits under the + // ceiling - unknown is not a quantity, but it is still HER OWN named bound under the tick floor. + let bound = crate::inference::resource_admission::lane_wait_bound(0, 0, 0, 0) + .unwrap_or(LANE_WAIT_CEILING); // unwrap_or: unmeasured lanes use the existing diagnostic ceiling + assert_eq!(bound, LANE_WAIT_CEILING, "unmeasured: the derivation names no bound and the ceiling stands"); + let (refused, measured, elapsed) = starved_until_refused(bound).await; + assert!(matches!(refused, Err(WindowRefused::Ungranted(_))), "a typed deferral - her next tick measures and asks again: {refused:?}"); + assert_eq!(measured, 1, "her demand stood while she waited: measured once"); + assert_eq!(elapsed, bound, "exact at the ceiling ({bound:?}), not the act's tick floor (25 min)"); } } diff --git a/core/continuum-engine/src/inference/resource_admission/metrics.rs b/core/continuum-engine/src/inference/resource_admission/metrics.rs index 698ca8fbbd..1bf4683860 100644 --- a/core/continuum-engine/src/inference/resource_admission/metrics.rs +++ b/core/continuum-engine/src/inference/resource_admission/metrics.rs @@ -391,6 +391,17 @@ pub fn lane_wait_bound( .clamp(LANE_WAIT_FLOOR, LANE_WAIT_CEILING), ) } +/// The bound an ungranted mind waits under ACROSS grants evaluations while she is queued here, +/// derived from the queue she is joining exactly like [`lane_wait_bound`]: her place in line over +/// the lanes' measured turn time. Unmeasured lanes take the ceiling, because a node that has never +/// timed a lane may not guess a short one ([[unknown-is-not-a-quantity]]). A wait that outlives it +/// is starvation, not queuing: she defers at her own named bound with her act budget intact instead +/// of parking to the act's tick floor (card 250d7603). +pub fn grants_wait_bound() -> std::time::Duration { + let (hold_p50_ms, hold_samples) = lane_hold_p50_ms(); + lane_wait_bound(work_waiting_now(), served_lane_count(), hold_p50_ms, hold_samples) + .unwrap_or(LANE_WAIT_CEILING) // unwrap_or: unmeasured lanes use the existing diagnostic ceiling +} /// PURE: may a WORK call be lent the lane reserved for directed calls? Whenever no directed /// line is pending here. A directed arrival then takes the next lane any call releases. ///