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 @@ -212,40 +212,17 @@ impl DreamConsolidationRegion {
let consolidated = Arc::clone(&self.consolidated);
let reviewed = Arc::clone(&self.reviewed);
let boundaries = Arc::clone(&self.review_boundaries);
let mut boundary_wake = self.review_boundary_wake.subscribe();
#[cfg(test)]
let idle_wait = self.idle_wait.clone();
tokio::spawn(async move {
let _permit = permit;
// #2561 preemption = paging out: an arriving demand does not queue
// behind a dream — it CANCELS it. The dropped future closes the
// generation stream (the backend abandons the slot on disconnect);
// the half-formed dream is discarded, and it is CHEAP to discard:
// dreams are the lowest-priced resident in the paging economy,
// re-dreamable from the same engrams on the next bored window.
//
// BOREDOM FIRST, THEN THE RACE. The wait used to live inside `dream_pass`,
// so the cancel arm below was armed while the pass was still parked on her
// gate — mid-turn the cancel won instantly, the in-flight slot cleared, and
// the region re-spawned every tick (measured 2026-09-03: 22 `paged_out` per
// citizen at an exact 30s cadence, zero consolidations). A dream arises
// only in her sustained idle; only THEN can wakefulness cancel it.
{
let a = crate::cognition::activity_gate::persona_activity(persona_id);
if !crate::cognition::activity_gate::persona_bored(
a,
crate::inference::measured_hold::subscribe()
.borrow()
.is_some(),
continuum_base::time::EpochMs::now().millis(),
) {
continuum_base::probe!(
class = "dream.awaiting_boredom",
persona = %persona_id,
"dream pass parked on HER activity gate — arises only in her sustained idle"
);
}
}
// A dream pass runs while she works (row 6 of MIND-DATAFLOW-OVERHAUL, card a31e72a4):
// it waited for HER sustained idle and her next act cancelled it, so a resident
// who is always engaged never consolidated (the M5, 2026-10-31: dreams 0 in 12 h;
// 2026-09-14: awaiting_boredom x26, paged_out x6, zero consolidations). Its
// generations ask at LanePriority::Ambient inside the non-directed budget
// (distiller.rs), so a directed call keeps its lane; one pass per resident is in
// flight (the permit), and a tick launches one only when fresh episodes exist.
if trigger == DreamTrigger::CardBoundary {
continuum_base::probe!(
class = "dream.card_boundary",
Expand Down Expand Up @@ -284,45 +261,12 @@ impl DreamConsolidationRegion {
}
return;
}
// A review arriving while idle work is parked must not disappear behind
// its in-flight flag. Retire only the wait; next tick selects fresh
// episodes under the bounded boundary policy, including the finished work.
let bored = async {
#[cfg(test)]
if let Some(wait) = idle_wait {
wait.notified().await;
return;
}
crate::cognition::activity_gate::wait_for_boredom_of(persona_id).await;
};
tokio::select! {
_ = async {
loop {
if storage_available && boundaries.lock().unwrap().get(&persona_id).is_some_and(|r| !r.pending.is_empty()) { // JUSTIFIED: inspect the owner state without holding its guard across the wait.
return;
}
if boundary_wake.changed().await.is_err() { return; }
}
} => { return; }
_ = bored => {}
}
tokio::select! {
_ = dream_pass(
reflector,
persona_id,
clusters,
fresh,
consolidated,
reviewed,
) => {}
_ = crate::cognition::activity_gate::wait_for_engagement_of(persona_id) => {
continuum_base::probe!(
class = "dream.paged_out",
persona = %persona_id,
"activity arrived mid-dream — dream cancelled and discarded (re-dreamable)"
);
}
// A test parks the pass here, before inference, to deliver a review while it is in flight.
#[cfg(test)]
if let Some(wait) = idle_wait {
wait.notified().await;
}
dream_pass(reflector, persona_id, clusters, fresh, consolidated, reviewed).await;
});

TickOutcome {
Expand Down Expand Up @@ -385,21 +329,9 @@ impl DreamConsolidationRegion {
let reflector = reflector.clone();
tokio::spawn(async move {
let _permit = permit;
// HER GAP, NOT BETWEEN HER TURNS (card 07188783): belief hygiene waits for her
// sustained idle, the same gate the idle consolidation pass takes, and her next act
// cancels it; its beliefs stay unreviewed for the next pass. Nothing about it is
// urgent, so it never interleaves with her turns.
crate::cognition::activity_gate::wait_for_boredom_of(persona_id).await;
tokio::select! {
_ = review_pass(reflector, persona_id, beliefs, reviewed) => {}
_ = crate::cognition::activity_gate::wait_for_engagement_of(persona_id) => {
continuum_base::probe!(
class = "dream.review_paged_out",
persona = %persona_id,
"activity arrived mid-review: the review is cancelled and its beliefs stay unreviewed for the next pass"
);
}
}
// Belief hygiene runs while she works, like every dream pass (card a31e72a4); the
// cooldown above keeps it a trickle, and its generations ask at Ambient priority.
review_pass(reflector, persona_id, beliefs, reviewed).await;
});
Some(TickOutcome {
published: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use super::*;
use crate::runtime::brain_region::RegionContext;

// ce37fbfb: a parked idle owner cannot swallow a reviewed boundary;
// repeated delivery and concurrent ticks must not double inference.
// ce37fbfb, a31e72a4: the idle pass runs while she works (no wait for her idle); a reviewed
// boundary delivered while it is in flight is finished by a later tick, never swallowed by the
// in-flight flag; repeated delivery and concurrent ticks never double inference.
#[tokio::test]
async fn reviewed_boundary_wakes_the_idle_owner_and_deduplicates_replay() {
async fn a_reviewed_boundary_during_an_idle_pass_is_finished_once_without_doubling_inference() {
use std::sync::atomic::{AtomicUsize, Ordering};
let persona = Uuid::new_v4();
let seeds: Vec<_> = (0..3)
Expand All @@ -34,30 +35,27 @@ async fn reviewed_boundary_wakes_the_idle_owner_and_deduplicates_replay() {
HeuristicInferenceAdapter::new().with_generate_observer(calls.clone()),
),
}));
region.idle_wait = Some(Arc::new(tokio::sync::Notify::new()));
let park = Arc::new(tokio::sync::Notify::new());
region.idle_wait = Some(park.clone());
region.consolidate(persona).await;
tokio::task::yield_now().await;
assert!(region.dreaming());
assert_eq!(
calls.load(Ordering::SeqCst),
0,
"the actual owner is parked before inference"
);
assert!(region.dreaming(), "the idle pass is in flight");
let review = Uuid::new_v4();
assert!(region.request_reviewed_boundary(persona, review));
assert!(!region.request_reviewed_boundary(persona, review));
assert!(!region.request_reviewed_boundary(persona, review), "repeated delivery queues once");
park.notify_one();
drain(&region).await;
assert_eq!(
calls.load(Ordering::SeqCst),
0,
"wake retires stale selection; it does not start another task"
2,
"the idle pass ran to the end while she works: one consolidator and one historian request"
);
tokio::join!(region.consolidate(persona), region.consolidate(persona));
drain(&region).await;
assert_eq!(
calls.load(Ordering::SeqCst),
2,
"one consolidator and one historian request"
"the boundary finds its episodes already folded: finished, with no second inference"
);
assert_eq!(
admission
Expand All @@ -67,7 +65,7 @@ async fn reviewed_boundary_wakes_the_idle_owner_and_deduplicates_replay() {
.count(),
1
);
assert!(!region.request_reviewed_boundary(persona, review));
assert!(!region.request_reviewed_boundary(persona, review), "a finished boundary is not queued again");
region.consolidate(persona).await;
drain(&region).await;
assert_eq!(calls.load(Ordering::SeqCst), 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ impl LlmDeliberationFaculty {
let _admission = self
.admit_generation(ws, &request, adapter.generation_admission(), &mut capture)
.await?;
// HER task-positive system is engaged from here: the per-citizen boredom gate
// (dreams) reads this stamp, never a room wake.
crate::cognition::activity_gate::persona_engaged(self.persona_id);
// COGNITION PULSE per generation, not only per turn start. The claim-renewal
// gate reads this stamp, and a single service-loop turn can run many acts: on
// the M5 an act takes 7-9 minutes, so a multi-act turn outlives the 30-minute
Expand Down
7 changes: 3 additions & 4 deletions core/continuum-mind/src/modules/cognition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ impl ServiceModule for CognitionModule {
/// while we tried to save her.
/// 2. Wait for the turns already admitted to finish, bounded.
///
/// The count comes from the permits the loops hold, not from `activity_gate`'s
/// `engaged` flag: engagement is stamped at serving-lane acquisition, so a turn that
/// has taken a message and is still composing context is not engaged, and draining on
/// that flag would walk past exactly the turns whose loss leaves no trace.
/// The count comes from the permits the loops hold: a turn that has taken a message and
/// is still composing context holds one before any serving lane, so the drain waits for
/// exactly the turns whose loss would leave no trace.
///
/// Returns the number still running when the budget expired — a citizen who is still
/// thinking is a fact the receipt reports, not one it waits forever for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ pub(super) async fn serve_persona_loop_inner(
// Taken the moment a wake is produced, BEFORE the match, because the
// `Wake::Tick` arm does its self-tick deliberation INLINE and then `continue`s —
// it never reaches the code below it. A permit taken after the match would have
// counted inbound turns and silently missed every self-directed one, which is the
// same blindness as draining on `activity_gate`'s `engaged` flag: that one is
// stamped at serving-lane acquisition, so a turn still composing its context does
// not appear there either. Both gaps hide turns that have consumed input and
// written nothing.
// counted inbound turns and silently missed every self-directed one: turns that have
// consumed input and written nothing.
//
// Held to the end of the loop body, so it is released on EVERY exit path — the
// `continue` at the end of the tick arm included. A manual decrement would have to
Expand Down
6 changes: 0 additions & 6 deletions core/continuum-mind/src/persona/service_loop/wake_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ pub(super) async fn await_wake(
mind.next_mind_check = Some(tokio::time::Instant::now());
}
}
// HER turn boundary: idle whenever the loop is back at its wake select. The
// matching `engaged` stamp is set where a serving lane is actually acquired
// (the deliberation faculty) — a room wake alone is not wakefulness, or a
// busy room would cancel every dream (measured: 290 paged out in 20 min with
// the stamp on the wake itself).
crate::cognition::activity_gate::persona_idle(ctx.identity.peer_id.as_uuid());
// BIASED: a line already in her inbox beats a due self-tick. Without the
// order, a directed line that made her yield a parked lane wait could
// lose the next wake to the tick again (random branch choice) — a yield
Expand Down
Loading
Loading