From 07e7192c78411882d27d0fc93368a0e46b207afa Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 16:08:05 +0100 Subject: [PATCH] persona-wake-span W2: tuning for an open wake (idle_s 300, span_s 1800, wake_usd 1.00) AgentTuning gains idle_s and span_s. Validation: 30 <= idle_s <= span_s, and span_s + 300 <= 3600, the unit's RuntimeMaxSec, named in the error. The wake spend default rises from 0.40 to 1.00 so a multi-turn wake is not cut by a one-turn budget; day_usd stays 3.00. The agent tests that price the unmetered worst case pin 0.40 themselves. Co-Authored-By: Claude Sonnet 5.5 --- crates/mind-body/src/projection.rs | 1 + .../mind-body/src/projection/agent/tests.rs | 4 ++-- crates/mind-body/src/projection/tests.rs | 9 +++++++- crates/mind-body/src/projection/tuning.rs | 22 +++++++++++++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/crates/mind-body/src/projection.rs b/crates/mind-body/src/projection.rs index d896375..0e44c38 100644 --- a/crates/mind-body/src/projection.rs +++ b/crates/mind-body/src/projection.rs @@ -64,6 +64,7 @@ pub(crate) use agent::say::{Mouth, settle_handed}; pub(crate) use wake::{Fault, Waked, wake}; pub use tuning::{TUNING_FILE, TUNING_ROOT}; pub(crate) use tuning::load as load_tuning; +pub(crate) use tuning::AgentTuning; pub(crate) use select::People; use narrate::{cap_words, distinct_2, field_names, heard_overlap, judge_prompt, judged, offers_options, persona_prompt, projector_prompt, word_budget, words}; diff --git a/crates/mind-body/src/projection/agent/tests.rs b/crates/mind-body/src/projection/agent/tests.rs index ae56923..ba8c7df 100644 --- a/crates/mind-body/src/projection/agent/tests.rs +++ b/crates/mind-body/src/projection/agent/tests.rs @@ -128,7 +128,7 @@ impl Rig { fn new() -> Self { let dir = tempfile::tempdir().unwrap(); let session = FileSession::new(dir.path().join("agent-session.cc")); - Self { dir, session, ledger: Memory::default(), stub: Stub::new(), clock: Cell::new(noon()), bounds: AgentTuning::default() } + Self { dir, session, ledger: Memory::default(), stub: Stub::new(), clock: Cell::new(noon()), bounds: AgentTuning { wake_usd: 0.40, ..AgentTuning::default() } } } fn wake(&self, model: &Script, id: &str, instructions: &str, input: &str) -> Turn { @@ -243,7 +243,7 @@ fn t_a1_day_cap_survives_a_restart() { let dir = tempfile::tempdir().unwrap(); let trace = FileTrace::new(dir.path().join("trace.cc")); let session = FileSession::new(dir.path().join("agent-session.cc")); - let (bounds, stub) = (AgentTuning::default(), Stub::new()); + let (bounds, stub) = (AgentTuning { wake_usd: 0.40, ..AgentTuning::default() }, Stub::new()); let clock = noon; let executors: [&dyn Executor; 1] = [&stub]; // One expensive wake: 400k output tokens at $10 a million is $4.00. diff --git a/crates/mind-body/src/projection/tests.rs b/crates/mind-body/src/projection/tests.rs index 95813a1..dcc638c 100644 --- a/crates/mind-body/src/projection/tests.rs +++ b/crates/mind-body/src/projection/tests.rs @@ -885,7 +885,7 @@ fn tuning_absent_is_the_defaults_and_a_file_overrides_and_an_unknown_key_refuses #[test] fn the_agent_bounds_are_the_maps_and_a_file_prices_another_model() { let defaults = Tuning::default().agent; - assert_eq!((defaults.tool_calls, defaults.model_calls, defaults.wake_usd, defaults.day_usd, defaults.ttl_s.short, defaults.ttl_s.long), (8, 10, 0.40, 3.00, 300, 3600)); + assert_eq!((defaults.tool_calls, defaults.model_calls, defaults.wake_usd, defaults.day_usd, defaults.idle_s, defaults.span_s, defaults.ttl_s.short, defaults.ttl_s.long), (8, 10, 1.00, 3.00, 300, 1800, 300, 3600)); let dir = tempfile::tempdir().unwrap(); let path = dir.path().join(TUNING_FILE); std::fs::write(&path, "[agent] @@ -965,6 +965,10 @@ fn a_value_out_of_range_refuses_the_agent_tuning() { ("[agent]\nwake_usd = 2.0\nday_usd = 1.0\n".to_owned(), "agent.wake_usd must be at most agent.day_usd"), ("[agent]\nmax_session_tokens = 0\n".to_owned(), "agent.max_session_tokens and agent.cache_min_tokens"), ("[agent]\ncache_min_tokens = 0\n".to_owned(), "agent.max_session_tokens and agent.cache_min_tokens"), + ("[agent]\nspan_s = 3400\n".to_owned(), "RuntimeMaxSec"), + ("[agent]\nspan_s = 3301\n".to_owned(), "agent.span_s must be at most 3300"), + ("[agent]\nidle_s = 1801\n".to_owned(), "agent.idle_s must be from 30 to agent.span_s"), + ("[agent]\nidle_s = 29\n".to_owned(), "agent.idle_s must be from 30 to agent.span_s"), ("[agent.ttl_s]\nshort = 60\n".to_owned(), "agent.ttl_s must be above 60"), ("[agent.ttl_s]\nlong = 60\n".to_owned(), "agent.ttl_s must be above 60"), ] { @@ -975,6 +979,9 @@ fn a_value_out_of_range_refuses_the_agent_tuning() { // The edges that load: a day cap that is the wake cap, the least ttl, the most calls. std::fs::write(&path, "[agent]\nwake_usd = 1.0\nday_usd = 1.0\ntool_calls = 32\nmodel_calls = 1\n\n[agent.ttl_s]\nshort = 61\nlong = 61\n").unwrap(); assert!(tuning::load(&path).is_ok()); + // The longest span the unit leaves room to close, and an idle window as long as the span. + std::fs::write(&path, "[agent]\nspan_s = 3300\nidle_s = 3300\n").unwrap(); + assert!(tuning::load(&path).is_ok()); } #[test] diff --git a/crates/mind-body/src/projection/tuning.rs b/crates/mind-body/src/projection/tuning.rs index 59e2d9a..1b000fc 100644 --- a/crates/mind-body/src/projection/tuning.rs +++ b/crates/mind-body/src/projection/tuning.rs @@ -124,9 +124,13 @@ pub struct AgentTuning { /// The most tool calls a wake runs, and the most model calls it makes. pub tool_calls: usize, pub model_calls: usize, - /// The most a wake may spend, and the most a Mind may spend in a UTC day, summed from her trace. + /// The most a wake may spend across all its turns, and the most a Mind may spend in a UTC day, summed from her trace. pub wake_usd: f64, pub day_usd: f64, + /// How long an open wake waits, in seconds, for a line that wakes her after her last turn ended, before it closes (`persona::live::wake_end`). + pub idle_s: u64, + /// The longest a wake stays open, in seconds, from its start. The unit's `RuntimeMaxSec` is the backstop, and the close needs room inside it. + pub span_s: u64, /// The prompt size past which her session is discarded and re-seeded. pub max_session_tokens: u64, /// The cache the session's prefix asks for. @@ -180,8 +184,10 @@ impl Default for AgentTuning { model: "claude-sonnet-5-5".into(), tool_calls: 8, model_calls: 10, - wake_usd: 0.40, + wake_usd: 1.00, day_usd: 3.00, + idle_s: 300, + span_s: 1800, max_session_tokens: 80_000, retention: CacheRetention::Long, ttl_s: CacheTtl::default(), @@ -228,6 +234,12 @@ impl AgentTuning { if self.wake_usd > self.day_usd { bail!("agent.wake_usd must be at most agent.day_usd"); } + if self.idle_s < IDLE_MIN_S || self.idle_s > self.span_s { + bail!("agent.idle_s must be from {IDLE_MIN_S} to agent.span_s, not {}", self.idle_s); + } + if self.span_s.saturating_add(CLOSE_ROOM_S) > UNIT_RUNTIME_MAX_S { + bail!("agent.span_s must be at most {} seconds: the unit's RuntimeMaxSec is {UNIT_RUNTIME_MAX_S} and the close needs {CLOSE_ROOM_S} of them, not {}", UNIT_RUNTIME_MAX_S - CLOSE_ROOM_S, self.span_s); + } if self.max_session_tokens == 0 || self.cache_min_tokens == 0 { bail!("agent.max_session_tokens and agent.cache_min_tokens must be above 0"); } @@ -238,6 +250,12 @@ impl AgentTuning { } } +/// The unit's `RuntimeMaxSec` (`mind-persona@.service`), in seconds: the longest a start lives, whatever the tuning says. +const UNIT_RUNTIME_MAX_S: u64 = 3600; +/// What a wake's close needs inside `RuntimeMaxSec` after the span: a last turn, the Interpreter's two calls and the records. +const CLOSE_ROOM_S: u64 = 300; +/// The least idle window: a line a poll away (`persona::live::POLL_S`) and a stagger behind it must still be waited for. +const IDLE_MIN_S: u64 = 30; /// A session is discarded this long before its cache is due to end: a call that starts inside it may not finish inside the cache. pub(crate) const CACHE_MARGIN_S: u64 = 60; /// The most calls of either kind a wake may be tuned to, and the most it and a day may be tuned to spend: a mistyped bound fails