agentmux_srv_core/ambient/purpose.rs
1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Every ambient purpose, in one place: its tag (the second half of an
5//! `AmbientCallKey`, the outcome-log purpose and the token-usage category), how
6//! long its CLI call may run, and which queue it waits in. Each caller keeps its OWN purpose: two callers under
7//! one purpose cancel each other.
8//!
9//! docs/reports/REPORT_AMBIENT_FRAMEWORK_REASSESSMENT_2026_10_08.md section 6.3.
10
11use std::time::Duration;
12
13use super::limits::Class;
14
15/// One kind of ambient call.
16#[derive(Debug, PartialEq, Eq)]
17pub struct Purpose {
18 pub tag: &'static str,
19 /// The CLI call's time limit, spawn to exit.
20 pub timeout: Duration,
21 /// Whether the outcome log is given the reply, for its length. Off for a purpose whose
22 /// reply restates the conversation itself (the continuity state): its length says too much. Never the text.
23 pub logs_reply: bool,
24 /// Which queue its calls wait in (`limits`).
25 pub class: Class,
26}
27
28/// The time limits. A call that answers in about 1.5 s on a quiet account can
29/// take much longer when many agents share one login and the CLI retries on
30/// overload, and a reply cut off at the limit has been paid for and is thrown
31/// away. 15 s timed out a third of suggestion calls. A suggestion or a title
32/// that arrives after 25 s is still useful.
33const INTERACTIVE_TIMEOUT: Duration = Duration::from_secs(30);
34const BACKGROUND_TIMEOUT: Duration = Duration::from_secs(45);
35
36/// The per-turn session title the pane requests (`session:activity_summary`).
37/// It reads a digest of the session as well as the message now, and nothing waits on
38/// it: the header keeps its last title until the new one is stored. A title call
39/// that times out is an evaluation lost and a stale title left standing (one pane's
40/// calls timed out at 30 s several times in a day), so it has the background limit.
41pub const ACTIVITY_SUMMARY: Purpose =
42 Purpose { tag: "activity_summary", timeout: BACKGROUND_TIMEOUT, class: Class::Interactive, logs_reply: true };
43
44/// A missing session title, recovered by the background sweep
45/// (`backend::reactive::activity_watcher`). Its own purpose so it never cancels,
46/// or is cancelled by, the pane's own title request.
47pub const ACTIVITY_SUMMARY_PUSHED: Purpose =
48 Purpose { tag: "activity_summary_pushed", timeout: BACKGROUND_TIMEOUT, class: Class::Background, logs_reply: true };
49
50/// The once-per-definition conversation preview for the AgentPicker's "My Agents"
51/// list (`tasks::generate_definition_activity_summary`).
52pub const DEFINITION_SUMMARY: Purpose =
53 Purpose { tag: "definition_summary", timeout: BACKGROUND_TIMEOUT, class: Class::Background, logs_reply: true };
54
55/// A subagent's display name (`tasks::generate_subagent_name`), when its parent
56/// gave no description. One-shot: the name is cached on `SubAgent.display_name`,
57/// so its generation is always `1`. The backlog pass runs it as background work.
58pub const SUBAGENT_NAME: Purpose =
59 Purpose { tag: "subagent_name", timeout: INTERACTIVE_TIMEOUT, class: Class::Interactive, logs_reply: true };
60
61/// A Workflow dispatch's display name. Separate from `SUBAGENT_NAME` so the two
62/// are counted apart. docs/specs/SPEC_SWARM_DISPATCH_NAMING_AND_ROW_MODEL_2026_07_19.md.
63pub const DISPATCH_NAME: Purpose =
64 Purpose { tag: "dispatch_name", timeout: INTERACTIVE_TIMEOUT, class: Class::Interactive, logs_reply: true };
65
66/// The composer's ghost-text next-prompt suggestion.
67/// docs/specs/SPEC_AMBIENT_GHOST_TEXT_NEXT_PROMPT_2026_07_03.md.
68pub const NEXT_PROMPT_SUGGESTION: Purpose =
69 Purpose { tag: "next_prompt_suggestion", timeout: INTERACTIVE_TIMEOUT, class: Class::Interactive, logs_reply: true };
70
71/// A line narrating an autonomous AgentMux action in the pane's conversation.
72pub const NARRATION: Purpose =
73 Purpose { tag: "ambient_narration", timeout: BACKGROUND_TIMEOUT, class: Class::Background, logs_reply: true };
74
75/// The rolling continuity state (`backend::continuity_state`): off any
76/// user-facing path, and a long multi-section reply, so it may take longer.
77pub const CONTINUITY_STATE: Purpose =
78 Purpose { tag: "continuity_state", timeout: Duration::from_secs(90), class: Class::Background, logs_reply: false };
79
80/// The Swarm Supervisor's verdict on a turn that just ended
81/// (`backend::supervisor`): continue the agent, or stop for the user. Background
82/// class: nobody is waiting on a reply in a pane, and a burst of agents ending
83/// turns together must not hold up a title or a suggestion. 90 s, like the
84/// continuity state: a verdict reasons over the whole turn, and took 14 to 27 s
85/// on a busy shared login where 45 s timed out (the agent waits idle either way).
86/// docs/specs/SPEC_SWARM_SUPERVISOR_2026_10_16.md ยง3.3.
87pub const SUPERVISOR_VERDICT: Purpose =
88 Purpose { tag: "supervisor_verdict", timeout: Duration::from_secs(90), class: Class::Background, logs_reply: true };
89
90/// Every purpose, for anything that lists them.
91#[cfg(test)]
92pub const ALL: &[&Purpose] = &[
93 &ACTIVITY_SUMMARY,
94 &ACTIVITY_SUMMARY_PUSHED,
95 &DEFINITION_SUMMARY,
96 &SUBAGENT_NAME,
97 &DISPATCH_NAME,
98 &NEXT_PROMPT_SUGGESTION,
99 &NARRATION,
100 &CONTINUITY_STATE,
101 &SUPERVISOR_VERDICT,
102];
103
104#[cfg(test)]
105mod tests {
106 use super::*;
107
108 #[test]
109 fn every_purpose_has_its_own_tag() {
110 let mut tags: Vec<&str> = ALL.iter().map(|p| p.tag).collect();
111 tags.sort_unstable();
112 tags.dedup();
113 assert_eq!(tags.len(), ALL.len(), "two purposes share a tag, so they would cancel each other");
114 }
115
116 /// The continuity state restates the conversation (its goal, the latest
117 /// request, exact identifiers): the srv log is not even told its length (#4501).
118 #[test]
119 fn only_replies_that_restate_the_conversation_stay_out_of_the_log() {
120 let quiet: Vec<&str> = ALL.iter().filter(|p| !p.logs_reply).map(|p| p.tag).collect();
121 assert_eq!(quiet, vec![CONTINUITY_STATE.tag]);
122 }
123}