From b91bef7e139b1b4af554152f2b6c3db3ae29794e Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Wed, 28 Oct 2026 19:49:30 -0500 Subject: [PATCH 1/3] The lane floor follows a mind's recent growth samples, never a lifetime peak On the M5, 2026-10-28, the residents' all-time sent_peaks (188-370k tokens; recent turns 20-43k) set a 423,945-token requirement: every runnable plan was refused as below the floor and four residents shared one 27,904-token slot from ~21:46Z. PersonaDemand gains a ring of recent growth samples (sent_recent, serde default); growth_sample takes its max, else her typical demand (requirement_tokens' rule), else the legacy peak. sent_median_with and sent_ceiling_of read it. sent_peak stays recorded for the glass box. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/cognition/working_set.rs | 54 ++++++++++++++++--- .../src/cognition/working_set/tests.rs | 23 +++++++- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/core/continuum-cognition/src/cognition/working_set.rs b/core/continuum-cognition/src/cognition/working_set.rs index 3208e2b2ed..516e4a8a0b 100644 --- a/core/continuum-cognition/src/cognition/working_set.rs +++ b/core/continuum-cognition/src/cognition/working_set.rs @@ -149,6 +149,17 @@ pub struct PersonaDemand { /// Next slot to overwrite in `need_recent`. #[serde(default)] pub need_next: u8, + /// The last [`RECENT_TURNS`] growth samples (what `sent_peak` takes the max of, over a + /// lifetime): the lane floor reads their max, so one historic giant turn stops sizing + /// every plan forever. On the M5, 2026-10-28, all-time `sent_peak`s of 188-370k + /// (recent turns 20-43k) set a 423,945-token requirement no plan could meet, every + /// runnable plan was refused as below the floor, and four residents shared one + /// 27,904-token slot. Legacy files read empty. + #[serde(default)] + pub sent_recent: [u32; RECENT_TURNS], + /// Next slot to overwrite in `sent_recent`. + #[serde(default)] + pub sent_next: u8, } /// How many recent turns define "typical". Sixteen: a working session, not a @@ -169,6 +180,27 @@ fn push_need(d: &mut PersonaDemand, need_tokens: u32) { d.need_next = ((i + 1) % RECENT_TURNS) as u8; } +/// Push one growth sample into her sent ring (newest overwrites oldest). +fn push_sent(d: &mut PersonaDemand, sent_tokens: u32) { + let i = (d.sent_next as usize) % RECENT_TURNS; + d.sent_recent[i] = sent_tokens; + d.sent_next = ((i + 1) % RECENT_TURNS) as u8; +} + +/// Her growth sample for the lane floor: the largest of her RECENT growth samples, never a +/// lifetime peak. A record without that ring (written before it existed) stands on her typical +/// demand, the same rule [`requirement_tokens`] states, and only a record with neither on its +/// legacy peak. +pub fn growth_sample(d: &PersonaDemand) -> Option { + d.sent_recent + .iter() + .copied() + .max() + .filter(|&t| t > 0) + .or_else(|| typical_tokens(d)) + .or_else(|| (d.sent_peak > 0).then_some(d.sent_peak)) +} + fn median_of(ring: &[u32; RECENT_TURNS]) -> Option { let mut v: Vec = ring.iter().copied().filter(|t| *t > 0).collect(); if v.is_empty() { @@ -490,8 +522,15 @@ impl WorkingSetRegistry { *self .observed .entry(persona) - .and_modify(|d| d.sent_peak = d.sent_peak.max(sent_tokens)) - .or_insert(PersonaDemand { last_seen_ms: now_ms, sent_peak: sent_tokens, ..PersonaDemand::default() }) + .and_modify(|d| { + d.sent_peak = d.sent_peak.max(sent_tokens); + push_sent(d, sent_tokens); + }) + .or_insert_with(|| { + let mut d = PersonaDemand { last_seen_ms: now_ms, sent_peak: sent_tokens, ..PersonaDemand::default() }; + push_sent(&mut d, sent_tokens); + d + }) } /// Record the post-fit size of a turn the fit HELD — her need (see @@ -526,8 +565,8 @@ impl WorkingSetRegistry { .filter(|&t| t > 0) } - /// Typical growth sample among `personas` — the median of their retained - /// starvation-aware peaks. The planner's per-lane floor follows this, not the ceiling: one mind + /// Typical growth sample among `personas` — the median of their RECENT starvation-aware + /// peaks ([`growth_sample`], never a lifetime max). The planner's per-lane floor follows this, not the ceiling: one mind /// with a 96k prompt must not size every lane to 120k and starve the roster /// (2026-09-14: 16 residents on 3 lanes). The outlier is reconciled down to the /// served window instead. @@ -543,7 +582,7 @@ impl WorkingSetRegistry { pub fn sent_median_with(&self, personas: &[Uuid], extra: &[u32]) -> Option { let mut peaks: Vec = personas .iter() - .filter_map(|p| self.observed.get(p).map(|e| e.value().sent_peak)) + .filter_map(|p| self.observed.get(p).and_then(|e| growth_sample(e.value()))) .chain(extra.iter().copied()) .filter(|&t| t > 0) .collect(); @@ -553,13 +592,12 @@ impl WorkingSetRegistry { peaks.sort_unstable(); Some(peaks[peaks.len() / 2]) } - /// Largest retained growth sample among `personas`, including unmet demand. + /// Largest recent growth sample among `personas`, including unmet demand ([`growth_sample`]). pub fn sent_ceiling_of(&self, personas: &[Uuid]) -> Option { personas .iter() - .filter_map(|p| self.observed.get(p).map(|e| e.value().sent_peak)) + .filter_map(|p| self.observed.get(p).and_then(|e| growth_sample(e.value()))) .max() - .filter(|&t| t > 0) } /// Record one completed generation's measured output for `persona`. diff --git a/core/continuum-cognition/src/cognition/working_set/tests.rs b/core/continuum-cognition/src/cognition/working_set/tests.rs index e70b1b1f26..d9e9d4ef12 100644 --- a/core/continuum-cognition/src/cognition/working_set/tests.rs +++ b/core/continuum-cognition/src/cognition/working_set/tests.rs @@ -58,7 +58,7 @@ assert_eq!(d.peak_tokens, 176_154); assert_eq!(typical_tokens(&d), Some(45_000), "the median of recent turns"); assert_eq!(requirement_tokens(&d), 45_000); - let legacy = PersonaDemand { peak_tokens: 176_154, last_tokens: 29_911, last_seen_ms: 0, prev_seen_ms: 0, turns: 5, sent_peak: 0, recent: [0; RECENT_TURNS], recent_next: 0, need_recent: [0; RECENT_TURNS], need_next: 0 }; + let legacy = PersonaDemand { peak_tokens: 176_154, last_tokens: 29_911, last_seen_ms: 0, prev_seen_ms: 0, turns: 5, sent_peak: 0, recent: [0; RECENT_TURNS], recent_next: 0, need_recent: [0; RECENT_TURNS], need_next: 0, sent_recent: [0; RECENT_TURNS], sent_next: 0 }; assert_eq!(requirement_tokens(&legacy), 29_911, "no ring: the last turn, never the peak"); let ser: PersonaDemand = serde_json::from_str(r#"{"peak_tokens":1,"last_tokens":2,"last_seen_ms":3,"turns":4}"#).expect("legacy json"); assert_eq!(typical_tokens(&ser), None); @@ -468,3 +468,24 @@ assert!(a2 < start2, "the control: verbatim samples contract ({start2} → {a2})"); } + // what this catches: the lane floor sized by a lifetime peak (the M5, 2026-10-28: sent_peaks + // of 188-370k against recent turns of 20-43k set a 423,945-token requirement, every runnable + // plan was refused, and four residents shared one 27,904-token slot). The floor follows her + // recent growth samples; a legacy record with only a peak stands on her typical demand. + #[test] + fn a_historic_giant_turn_stops_setting_the_lane_floor() { + let reg = WorkingSetRegistry::new(); + let (aris, benchy) = (Uuid::new_v4(), Uuid::new_v4()); + reg.record_sent_in_memory(aris, 370_493, 1); + reg.record_sent_in_memory(benchy, 339_156, 1); + for turn in 0..RECENT_TURNS as u32 { + reg.record_sent_in_memory(aris, 21_000 + turn, 2); + reg.record_sent_in_memory(benchy, 24_000 + turn, 2); + } + let floor = reg.sent_median_of(&[aris, benchy]).expect("two residents"); + assert!(floor < 30_000, "the floor follows recent turns, not the 339k-370k peaks: {floor}"); + assert_eq!(reg.sent_ceiling_of(&[aris, benchy]), Some(24_000 + RECENT_TURNS as u32 - 1)); + let legacy = PersonaDemand { sent_peak: 339_156, recent: [35_000; RECENT_TURNS], ..PersonaDemand::default() }; + assert_eq!(growth_sample(&legacy), Some(35_000), "a record from before the ring stands on her typical turn"); + assert_eq!(growth_sample(&PersonaDemand { sent_peak: 9_000, ..PersonaDemand::default() }), Some(9_000)); + } From ce265af9912f1d389d928c641aad82cffa7325ff Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Thu, 29 Oct 2026 04:42:32 -0500 Subject: [PATCH 2/3] A mind that never sent a growth sample sets no lane floor The legacy fallback (typical demand, else the lifetime peak) is for records written before the sent ring existed, which carry sent_peak > 0. Applied to every record with an empty ring, it gave minds with no growth sample a floor, and the serving re-home tests failed on CI (a_climbing_plan_coalesces..., a_jittering_gain..., a_lane_far_below...). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/cognition/working_set.rs | 15 +++++---------- .../src/cognition/working_set/tests.rs | 4 ++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/continuum-cognition/src/cognition/working_set.rs b/core/continuum-cognition/src/cognition/working_set.rs index 516e4a8a0b..9e3de2ecd0 100644 --- a/core/continuum-cognition/src/cognition/working_set.rs +++ b/core/continuum-cognition/src/cognition/working_set.rs @@ -188,17 +188,12 @@ fn push_sent(d: &mut PersonaDemand, sent_tokens: u32) { } /// Her growth sample for the lane floor: the largest of her RECENT growth samples, never a -/// lifetime peak. A record without that ring (written before it existed) stands on her typical -/// demand, the same rule [`requirement_tokens`] states, and only a record with neither on its -/// legacy peak. +/// lifetime peak. A mind that never sent a growth sample has none, so she sets no floor. A +/// record written before the ring existed holds only its lifetime peak: it stands on her +/// typical demand, the same rule [`requirement_tokens`] states, else on that peak. pub fn growth_sample(d: &PersonaDemand) -> Option { - d.sent_recent - .iter() - .copied() - .max() - .filter(|&t| t > 0) - .or_else(|| typical_tokens(d)) - .or_else(|| (d.sent_peak > 0).then_some(d.sent_peak)) + let recent = d.sent_recent.iter().copied().max().filter(|&t| t > 0); + recent.or_else(|| (d.sent_peak > 0).then(|| typical_tokens(d).unwrap_or(d.sent_peak))) } fn median_of(ring: &[u32; RECENT_TURNS]) -> Option { diff --git a/core/continuum-cognition/src/cognition/working_set/tests.rs b/core/continuum-cognition/src/cognition/working_set/tests.rs index d9e9d4ef12..ce75294897 100644 --- a/core/continuum-cognition/src/cognition/working_set/tests.rs +++ b/core/continuum-cognition/src/cognition/working_set/tests.rs @@ -488,4 +488,8 @@ let legacy = PersonaDemand { sent_peak: 339_156, recent: [35_000; RECENT_TURNS], ..PersonaDemand::default() }; assert_eq!(growth_sample(&legacy), Some(35_000), "a record from before the ring stands on her typical turn"); assert_eq!(growth_sample(&PersonaDemand { sent_peak: 9_000, ..PersonaDemand::default() }), Some(9_000)); + // A mind that never sent a growth sample sets no floor, however large her typical turn: + // the re-home tests' plans moved when such a record contributed one (#5579 CI). + let never_sent = PersonaDemand { recent: [35_000; RECENT_TURNS], ..PersonaDemand::default() }; + assert_eq!(growth_sample(&never_sent), None); } From 7d8acf57b9aff6dccab64fe5de5f8046f0c4335a Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Thu, 29 Oct 2026 09:26:54 -0500 Subject: [PATCH 3/3] growth_sample states its legacy order as an Option chain, not an unwrap_or (unwrap ratchet 1937 -> 1936) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- core/continuum-cognition/src/cognition/working_set.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/continuum-cognition/src/cognition/working_set.rs b/core/continuum-cognition/src/cognition/working_set.rs index 9e3de2ecd0..518ecc461f 100644 --- a/core/continuum-cognition/src/cognition/working_set.rs +++ b/core/continuum-cognition/src/cognition/working_set.rs @@ -192,8 +192,13 @@ fn push_sent(d: &mut PersonaDemand, sent_tokens: u32) { /// record written before the ring existed holds only its lifetime peak: it stands on her /// typical demand, the same rule [`requirement_tokens`] states, else on that peak. pub fn growth_sample(d: &PersonaDemand) -> Option { - let recent = d.sent_recent.iter().copied().max().filter(|&t| t > 0); - recent.or_else(|| (d.sent_peak > 0).then(|| typical_tokens(d).unwrap_or(d.sent_peak))) + if let Some(recent) = d.sent_recent.iter().copied().max().filter(|&t| t > 0) { + return Some(recent); + } + if d.sent_peak == 0 { + return None; + } + typical_tokens(d).or(Some(d.sent_peak)) } fn median_of(ring: &[u32; RECENT_TURNS]) -> Option {