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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/continuum-cognition/src/cognition/act_observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod page_budget;
pub use apply::{apply_act, ActChain};

mod settle;
pub use settle::{drive_to_settle_with_credit, TurnCredit};
pub use settle::{drive_to_settle_with_credit, TurnBudget, TurnCredit};
pub use settle::{drive_to_settle, drive_to_settle_with_input, settle_step};

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions core/continuum-cognition/src/cognition/act_observe/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::inference::turn_bound::TICK_DEADLINE;
mod tick_deadline;
mod turn_credit;
pub use turn_credit::TurnCredit;
mod turn_budget;
pub use turn_budget::TurnBudget;
pub use tick_deadline::*;
mod settle_to_outcome;
use settle_to_outcome::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
pub(super) async fn settle_to_outcome<'c>(
cycle: &WorkspaceCycle,
mut burst: Burst,
max_acts: usize,
budget: TurnBudget,
mut framing: TurnFraming,
mut conversation: Option<&mut dyn crate::cognition::conversation::PersonaConversation>,
mut credit: Option<&mut (dyn TurnCredit + 'c)>,
Expand Down Expand Up @@ -64,7 +64,7 @@ pub(super) async fn settle_to_outcome<'c>(
// in a row with no act between them means the nudge is not working, so she settles
// rather than being trapped. Her own behavior is the budget — no counter, no constant.
let mut narrations_since_act: usize = 0;
// ONE STEP BUDGET (2026-11-02): every generation of a turn spends `max_acts`, the caller's
// ONE STEP BUDGET (2026-11-02): every generation of a turn spends the caller's `TurnBudget`, its
// one bound: acts, spoken plans and retried faulted generations alike. This counts the
// steps that were not acts; `acts + non_act_steps` is what the turn has spent.
let mut non_act_steps: usize = 0;
Expand Down Expand Up @@ -100,14 +100,8 @@ pub(super) async fn settle_to_outcome<'c>(
// withheld, and the pre-gate warning now lands 4 acts before THIS bound —
// genuinely before, not at, the cliff). Plumbing must never out-stubborn
// the engineer it serves.
// Divide BEFORE multiply so this can never overflow: a self-tick (non-benchmark)
// turn passes `max_acts = usize::MAX` (the "unlimited acts" sentinel), and the old
// `max_acts * 3` overflowed usize → a debug-build panic that aborted EVERY persona
// service loop the instant it self-ticked, so residency could never hold
// (resident_count flapped to 0, #412 root). `(max_acts / 4)` is always ≤ max_acts, so
// `* 3` stays in range; `saturating_mul` is belt-and-suspenders. 3/4 of the budget,
// overflow-safe.
let discovery_budget = (max_acts / 4).saturating_mul(3).max(1);
// Three quarters of a bounded budget; an unbounded (live) turn has no discovery gate.
let discovery_budget = budget.discovery_steps();
let mut mutated_yet = false;
let mut saturation_probed = false;

Expand Down Expand Up @@ -301,7 +295,7 @@ pub(super) async fn settle_to_outcome<'c>(
persona = body.persona_name.as_str(),
milestone = milestone,
acts = acts,
max_acts = max_acts,
budget = ?budget,
"act-budget proprioception fact recorded in working memory"
);
};
Expand All @@ -316,37 +310,37 @@ pub(super) async fn settle_to_outcome<'c>(
// no fix, no tool.
let gate_approaching = framing.workspace_deliverable
&& !mutated_yet
&& discovery_budget >= 4
&& acts == discovery_budget - 4;
&& discovery_budget.is_some_and(|steps| steps >= 4 && acts == steps - 4);
if gate_approaching {
budget_fact_at = Some(acts);
probe_budget_fact("pre_gate");
body.working_memory.record_fact(&format!(
"[act-budget] {acts} acts spent, none has changed a file yet. This turn's contract withholds further acts after {discovery_budget} total unless the workspace has been written to — the deliverable is the workspace change, and unwritten work is not part of it."
"[act-budget] {acts} acts spent, none has changed a file yet. This turn's contract withholds further acts after {} total unless the workspace has been written to — the deliverable is the workspace change, and unwritten work is not part of it.",
discovery_budget.unwrap_or(acts) // set: gate_approaching requires a bounded budget
));
} else if acts == 0 {
budget_fact_at = Some(acts);
probe_budget_fact("turn_start");
body.working_memory.record_fact(&if max_acts == usize::MAX {
"[act-budget] This turn has no fixed act budget: I act until I settle. \
The deliverable is the workspace as I leave it when I settle — \
work not yet written when I settle is not part of it."
.to_string()
} else {
body.working_memory.record_fact(&if let TurnBudget::Steps(max_acts) = budget {
format!(
"[act-budget] This turn grants me {max_acts} act→observe \
cycles before I must settle. The deliverable is the workspace \
as I leave it when I settle — work not yet written when the \
budget ends is not part of it."
)
} else {
"[act-budget] This turn has no fixed act budget: I act until I settle. \
The deliverable is the workspace as I leave it when I settle — \
work not yet written when I settle is not part of it."
.to_string()
});
} else if acts == max_acts / 2 {
} else if let Some(max_acts) = budget.remaining(0).filter(|steps| acts == steps / 2) {
budget_fact_at = Some(acts);
probe_budget_fact("midpoint");
body.working_memory.record_fact(&format!(
"[act-budget] I have spent {acts} of my {max_acts} acts this turn."
));
} else if max_acts.saturating_sub(acts) == 2 {
} else if let Some(max_acts) = budget.remaining(0).filter(|steps| steps.saturating_sub(acts) == 2) {
budget_fact_at = Some(acts);
probe_budget_fact("two_remaining");
body.working_memory.record_fact(&format!(
Expand All @@ -360,22 +354,23 @@ pub(super) async fn settle_to_outcome<'c>(
// saturated its discovery budget without a single mutation (#390 gate above), a
// fresh Act is returned un-driven and she must settle into a Speak/Pass.
// Speaking is never gated.
let discovery_open =
!framing.workspace_deliverable || mutated_yet || acts < discovery_budget;
if !discovery_open && acts + non_act_steps < max_acts && !saturation_probed {
let discovery_open = !framing.workspace_deliverable
|| mutated_yet
|| discovery_budget.is_none_or(|steps| acts < steps);
if !discovery_open && budget.allows(acts + non_act_steps) && !saturation_probed {
saturation_probed = true;
continuum_base::probe!(
class = "persona.settle.discovery_saturated",
room_id = %room_id,
acts = acts,
discovery_budget = discovery_budget,
max_acts = max_acts,
discovery_budget = ?discovery_budget,
budget = ?budget,
"workspace-deliverable turn spent its discovery budget with zero \
mutations — withholding further acts so the remaining budget reaches \
the empty-diff re-drive instead of being read away (#390 state gate)"
);
}
let may_act = acts + non_act_steps < max_acts && discovery_open;
let may_act = budget.allows(acts + non_act_steps) && discovery_open;
let act_started = std::time::Instant::now();
continuum_base::probe!(
class = "settle.tick.start",
Expand Down Expand Up @@ -580,7 +575,7 @@ pub(super) async fn settle_to_outcome<'c>(
// turn's own step budget, spent by plans and acts alike (a plan is a
// generation too), never a separate constant on how many plans she may
// make (2026-11-02); the fact names the count so pacing stays hers.
if framing.workspace_deliverable && acts + non_act_steps + 1 < max_acts {
if framing.workspace_deliverable && budget.allows(acts + non_act_steps + 1) {
if let Some(body) = cycle.acting() {
if !mutated_workspace(&body.working_memory.recent_entries(), ConcernPhase::JustSettled) {
narrations_since_act += 1;
Expand All @@ -590,11 +585,14 @@ pub(super) async fn settle_to_outcome<'c>(
// the fact; the "an explanation of a fix is not the fix"
// sermon accumulated dozens of copies in looping minds
// and became the content of their turns.
let left = match budget.remaining(acts + non_act_steps) {
Some(left) => format!(", {left} steps left this turn"),
None => String::new(),
};
body.working_memory.record_fact(&format!(
"[no-deliverable] I settled by speaking ({narrations_since_act} \
plans in a row, {} of this turn's {max_acts} steps left); no act \
of mine has changed a file in this workspace yet.",
max_acts - acts - non_act_steps
plans in a row{left}); no act of mine has changed a file in this \
workspace yet."
));
continuum_base::probe!(
class = "persona.settle.no_deliverable",
Expand Down Expand Up @@ -775,7 +773,7 @@ pub(super) async fn settle_to_outcome<'c>(
class = "persona.act.lane_starved",
room_id = %room_id,
act = acts,
steps_kept = (max_acts.saturating_sub(acts + non_act_steps)) as u64,
steps_kept = ?budget.remaining(acts + non_act_steps),
error = %error,
"deferred at the serving gate without reaching the model — act budget and deliberation retries left intact for the next tick"
);
Expand Down Expand Up @@ -808,15 +806,15 @@ pub(super) async fn settle_to_outcome<'c>(
// retry waits out another whole bound on the same engine (up to three, so one
// turn held four). It surrenders now, a failed act: demand and a failure for
// the resident ledger, never a completion (Fable on #5498).
if acts + non_act_steps + 1 < max_acts && !dropped_in_flight {
if budget.allows(acts + non_act_steps + 1) && !dropped_in_flight {
delib_retries += 1;
non_act_steps += 1;
continuum_base::probe!(
class = "persona.settle.deliberation_retry",
room_id = %room_id,
acts = acts,
retry = delib_retries,
steps_kept = (max_acts.saturating_sub(acts + non_act_steps)) as u64,
steps_kept = ?budget.remaining(acts + non_act_steps),
error = %error,
"transient deliberation fault — retrying the thought in place (the turn is not yet surrendered)"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ pub(super) fn act_probe_client() -> &'static reqwest::Client {
// its own truncation). Still used here for the settlement answer-head.
/// Drive the mind to SETTLEMENT: tick → if `Act`, run it + fold the observation
/// into the next perception → re-tick → until it `Speak`s/`Pass`es or the
/// external `max_acts` budget is spent.
/// external step budget ([`TurnBudget`]) is spent.
///
/// `max_acts` is the EXTERNAL observer's stopwatch — the grader holds it because
/// The [`TurnBudget`] is the EXTERNAL observer's stopwatch — the grader holds it because
/// the eval room has no heartbeat to pace re-perception. It is NOT a cap that
/// lives in the persona's head (the live path has no such bound; an "acts
/// forever" persona is a fitness gap to train away, never a substrate ceiling —
Expand Down Expand Up @@ -251,43 +251,43 @@ impl PaceCadence {
pub fn drive_to_settle(
cycle: &WorkspaceCycle,
burst: impl Into<Burst>,
max_acts: usize,
budget: impl Into<TurnBudget>,
framing: TurnFraming,
) -> impl std::future::Future<Output = SettleOutcome> + Send + '_ {
drive_with_input(cycle, burst.into(), max_acts, framing, None, None)
drive_with_input(cycle, burst.into(), budget.into(), framing, None, None)
}

/// The live driver leases its existing conversation between steps. No second
/// runner, cancellation of an in-flight tool, or replacement task is involved.
pub fn drive_to_settle_with_input<'a>(
cycle: &'a WorkspaceCycle,
burst: Burst,
max_acts: usize,
budget: impl Into<TurnBudget>,
framing: TurnFraming,
conversation: &'a mut dyn crate::cognition::conversation::PersonaConversation,
) -> impl std::future::Future<Output = SettleOutcome> + Send + 'a {
drive_with_input(cycle, burst, max_acts, framing, Some(conversation), None)
drive_with_input(cycle, burst, budget.into(), framing, Some(conversation), None)
}

/// A live card-linked turn uses the same driver with its own credit capture.
/// The optional owner never changes the activity's decision or assigns a verdict.
pub fn drive_to_settle_with_credit<'a>(
cycle: &'a WorkspaceCycle,
burst: Burst,
max_acts: usize,
budget: impl Into<TurnBudget>,
framing: TurnFraming,
conversation: &'a mut dyn crate::cognition::conversation::PersonaConversation,
credit: Option<&'a mut dyn TurnCredit>,
) -> impl std::future::Future<Output = SettleOutcome> + Send + 'a {
// Return the shared driver directly: an async forwarding wrapper needlessly
// nests its state in every live/eval caller and inflates future layout depth.
drive_with_input(cycle, burst, max_acts, framing, Some(conversation), credit)
drive_with_input(cycle, burst, budget.into(), framing, Some(conversation), credit)
}

pub(super) async fn drive_with_input<'c>(
cycle: &WorkspaceCycle,
burst: Burst,
max_acts: usize,
budget: TurnBudget,
framing: TurnFraming,
conversation: Option<&mut dyn crate::cognition::conversation::PersonaConversation>,
mut credit: Option<&mut (dyn TurnCredit + 'c)>,
Expand All @@ -297,7 +297,7 @@ pub(super) async fn drive_with_input<'c>(
let settled = settle_to_outcome(
cycle,
burst,
max_acts,
budget,
framing,
conversation,
credit.as_deref_mut(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! How many steps a turn may spend: every generation it makes (acts, spoken plans, retried
//! faulted generations). A type, so "no limit" is a variant and never a number standing for one
//! (`usize::MAX` was the live turn's sentinel, and a probe once read its remainder as
//! 18446744073709551614).

/// A turn's step budget.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TurnBudget {
/// A live turn: she acts until she settles.
Unbounded,
/// A caller-bounded turn (an eval, a solve): at most this many steps.
Steps(usize),
}

impl TurnBudget {
/// Whether a turn that has spent `spent` steps may take another.
pub fn allows(self, spent: usize) -> bool {
match self {
Self::Unbounded => true,
Self::Steps(n) => spent < n,
}
}

/// Steps left after `spent`; `None` when the turn is unbounded.
pub fn remaining(self, spent: usize) -> Option<usize> {
match self {
Self::Unbounded => None,
Self::Steps(n) => Some(n.saturating_sub(spent)),
}
}

/// The acts a workspace-deliverable turn may spend before its first write (the #390
/// discovery gate): three quarters of a bounded budget, at least one; an unbounded turn has
/// no discovery gate.
pub fn discovery_steps(self) -> Option<usize> {
match self {
Self::Unbounded => None,
Self::Steps(n) => Some((n / 4 * 3).max(1)),
}
}
}

impl From<usize> for TurnBudget {
fn from(steps: usize) -> Self {
Self::Steps(steps)
}
}
4 changes: 2 additions & 2 deletions core/continuum-cognition/src/cognition/conversation/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum SenderType {
}

/// Input modality for messages
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, TS)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, TS, schemars::JsonSchema)]
#[serde(rename_all = "lowercase")]
#[ts(export, export_to = "../../../protocol/typescript/persona/Modality.ts")]
pub enum Modality {
Expand All @@ -39,7 +39,7 @@ pub enum Modality {
// INBOX MESSAGE
//=============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, TS)]
#[derive(Debug, Clone, Serialize, Deserialize, TS, schemars::JsonSchema)]
#[ts(
export,
export_to = "../../../protocol/typescript/persona/InboxMessage.ts"
Expand Down
1 change: 1 addition & 0 deletions core/continuum-core/src/airc/inbound_attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ pub async fn publish_transcript_event(
class = "mind.feed.event",
room = %event.room_id.as_uuid(),
from = %event.peer_id.as_uuid(),
event_id = %event.event_id.as_uuid(),
residents = fed,
"a room event fed to resident minds"
);
Expand Down
Loading
Loading