Skip to content

Commit d518e76

Browse files
committed
fix(acp): redact launch args from runtime log and honor file-size ratchet
Review item #1 (security): spawn_agent_child logged the raw agent_args vector with `{:?}` into the runtime log retrievable end-to-end via get_managed_agent_log. Args may legally carry credentials (--token=...), so no argument value may ever be serialized. The resolved-launch marker now records only the resolved command and the argument count, mirroring spawn_snapshot::diff's MaskedBare policy. The marker writer lives in storage.rs as append_resolved_launch_marker(path, command, args): it resolves the command to a full path (DMG launches have a minimal PATH), appends the redacted marker, and returns the resolved command for the BUZZ_ACP_AGENT_COMMAND spawn env, replacing runtime.rs's inline resolution. open_log_file now creates runtime logs with mode 0o600 at creation time (Unix), so the permissions hold regardless of umask; agent stdout/stderr can echo installer/CLI credentials. Regression tests: append_resolved_launch_marker_never_writes_argument_ values asserts the marker carries the command and args_count only -- never token/argument values -- and that unresolvable commands fall through verbatim; open_log_file_creates_owner_only asserts 0o600. File-size ratchet: the two effective-launch tests moved from readiness.rs into readiness_effective_launch_tests.rs (external #[path] module, following readiness_goose_file_config_tests.rs), and runtime.rs stays at/below the ratchet cap after folding command resolution into the storage helper. Unblocks Detect Changed Paths so the required CI jobs run. Signed-off-by: Brad Hallett <[email protected]>
1 parent e2dcd38 commit d518e76

5 files changed

Lines changed: 300 additions & 203 deletions

File tree

‎desktop/src-tauri/src/managed_agents/readiness.rs‎

Lines changed: 6 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,191 +1470,6 @@ mod tests {
14701470
assert!(json["setup_copy"].as_str().unwrap().contains("codex login"));
14711471
}
14721472

1473-
// ── resolve_effective_agent_env ─────────────────────────────────────────
1474-
1475-
#[test]
1476-
fn resolve_effective_agent_env_user_env_wins_over_structured_fields() {
1477-
// User env_vars must win over baked defaults; in OSS builds baked map is empty,
1478-
// so this validates the user-env layer is present in the output.
1479-
let mut env_vars = BTreeMap::new();
1480-
env_vars.insert("BUZZ_AGENT_PROVIDER".to_string(), "anthropic".to_string());
1481-
env_vars.insert(
1482-
"BUZZ_AGENT_MODEL".to_string(),
1483-
"claude-opus-4-5".to_string(),
1484-
);
1485-
1486-
// Minimal record: only the fields resolve_effective_agent_env reads.
1487-
let record = crate::managed_agents::types::ManagedAgentRecord {
1488-
pubkey: "test-pubkey".to_string(),
1489-
name: "test-agent".to_string(),
1490-
persona_id: None,
1491-
private_key_nsec: String::new(),
1492-
auth_tag: None,
1493-
relay_url: String::new(),
1494-
avatar_url: None,
1495-
acp_command: "buzz-acp".to_string(),
1496-
agent_command: "buzz-agent".to_string(),
1497-
agent_command_override: None,
1498-
agent_args: vec![],
1499-
mcp_command: String::new(),
1500-
turn_timeout_seconds: 320,
1501-
idle_timeout_seconds: None,
1502-
max_turn_duration_seconds: None,
1503-
parallelism: 1,
1504-
system_prompt: None,
1505-
model: None,
1506-
provider: None,
1507-
persona_source_version: None,
1508-
env_vars,
1509-
start_on_app_launch: false,
1510-
auto_restart_on_config_change: true,
1511-
runtime_pid: None,
1512-
backend: Default::default(),
1513-
backend_agent_id: None,
1514-
provider_policy_pending: false,
1515-
provider_binary_path: None,
1516-
team_id: None,
1517-
persona_team_dir: None,
1518-
persona_name_in_team: None,
1519-
created_at: String::new(),
1520-
updated_at: String::new(),
1521-
last_started_at: None,
1522-
last_stopped_at: None,
1523-
last_exit_code: None,
1524-
last_error: None,
1525-
last_error_code: None,
1526-
respond_to: Default::default(),
1527-
respond_to_allowlist: vec![],
1528-
display_name: None,
1529-
slug: None,
1530-
runtime: None,
1531-
name_pool: Vec::new(),
1532-
is_builtin: false,
1533-
is_active: true,
1534-
shared: false,
1535-
source_team: None,
1536-
source_team_persona_slug: None,
1537-
catalog_source: None,
1538-
definition_respond_to: None,
1539-
definition_respond_to_allowlist: Vec::new(),
1540-
definition_parallelism: None,
1541-
relay_mesh: None,
1542-
effort_level: None,
1543-
};
1544-
1545-
let runtime = known_acp_runtime_exact("buzz-agent");
1546-
let effective = resolve_effective_agent_env(&record, &[], runtime, &Default::default());
1547-
1548-
// User env_vars must be present in the output (last-write-wins).
1549-
assert_eq!(
1550-
effective.env.get("BUZZ_AGENT_PROVIDER").map(String::as_str),
1551-
Some("anthropic")
1552-
);
1553-
assert_eq!(
1554-
effective.env.get("BUZZ_AGENT_MODEL").map(String::as_str),
1555-
Some("claude-opus-4-5")
1556-
);
1557-
}
1558-
1559-
#[test]
1560-
fn resolve_effective_harness_descriptor_uses_preset_args_for_pinned_command() {
1561-
// An agent pinned to a known ACP runtime via agent_command_override,
1562-
// with no runtime id and no instance args, must take the launch args
1563-
// from the matching PRESET_HARNESSES entry. Otherwise the bare command
1564-
// (e.g. `omp`) launches the interactive TUI, which times out at ACP
1565-
// `initialize` under headless Buzz (no controlling TTY).
1566-
let mk = |command: &str| crate::managed_agents::types::ManagedAgentRecord {
1567-
pubkey: "k".to_string(),
1568-
name: "agent".to_string(),
1569-
agent_command_override: Some(command.to_string()),
1570-
agent_args: vec![],
1571-
runtime: None,
1572-
persona_id: None,
1573-
private_key_nsec: String::new(),
1574-
auth_tag: None,
1575-
relay_url: String::new(),
1576-
avatar_url: None,
1577-
acp_command: "buzz-acp".to_string(),
1578-
agent_command: String::new(),
1579-
mcp_command: String::new(),
1580-
turn_timeout_seconds: 320,
1581-
idle_timeout_seconds: None,
1582-
max_turn_duration_seconds: None,
1583-
parallelism: 1,
1584-
system_prompt: None,
1585-
model: None,
1586-
provider: None,
1587-
persona_source_version: None,
1588-
env_vars: BTreeMap::new(),
1589-
start_on_app_launch: false,
1590-
auto_restart_on_config_change: true,
1591-
runtime_pid: None,
1592-
backend: Default::default(),
1593-
backend_agent_id: None,
1594-
provider_policy_pending: false,
1595-
provider_binary_path: None,
1596-
team_id: None,
1597-
persona_team_dir: None,
1598-
persona_name_in_team: None,
1599-
created_at: String::new(),
1600-
updated_at: String::new(),
1601-
last_started_at: None,
1602-
last_stopped_at: None,
1603-
last_exit_code: None,
1604-
last_error: None,
1605-
last_error_code: None,
1606-
respond_to: Default::default(),
1607-
respond_to_allowlist: vec![],
1608-
display_name: None,
1609-
slug: None,
1610-
name_pool: Vec::new(),
1611-
is_builtin: false,
1612-
is_active: true,
1613-
shared: false,
1614-
source_team: None,
1615-
source_team_persona_slug: None,
1616-
catalog_source: None,
1617-
definition_respond_to: None,
1618-
definition_respond_to_allowlist: Vec::new(),
1619-
definition_parallelism: None,
1620-
relay_mesh: None,
1621-
};
1622-
let global = crate::managed_agents::GlobalAgentConfig::default();
1623-
1624-
let desc = |command: &str| {
1625-
resolve_effective_harness_descriptor(&mk(command), &[], &global).unwrap()
1626-
};
1627-
1628-
// ACP-mode runtimes resolve to `acp`.
1629-
assert_eq!(desc("devin").args, vec!["acp".to_string()]);
1630-
assert_eq!(desc("omp").args, vec!["acp".to_string()]);
1631-
assert_eq!(desc("opencode").args, vec!["acp".to_string()]);
1632-
assert_eq!(desc("kimi").args, vec!["acp".to_string()]);
1633-
assert_eq!(desc("cursor-agent").args, vec!["acp".to_string()]);
1634-
assert_eq!(desc("openclaw").args, vec!["acp".to_string()]);
1635-
// Grok launches its agent stdio mode (not the TUI).
1636-
assert_eq!(
1637-
desc("grok").args,
1638-
vec![
1639-
"agent".to_string(),
1640-
"--always-approve".to_string(),
1641-
"stdio".to_string()
1642-
]
1643-
);
1644-
1645-
// Explicit instance args always win over the preset fallback.
1646-
let mut explicit = mk("omp");
1647-
explicit.agent_args = vec!["acp".to_string(), "--foo".to_string()];
1648-
let explicit_desc = resolve_effective_harness_descriptor(&explicit, &[], &global).unwrap();
1649-
assert_eq!(
1650-
explicit_desc.args,
1651-
vec!["acp".to_string(), "--foo".to_string()]
1652-
);
1653-
1654-
// An unknown command with no preset keeps the (empty) instance args.
1655-
assert!(desc("my-fancy-cli").args.is_empty());
1656-
}
1657-
16581473
// ── provider-specific model fallback tests ────────────────────────────
16591474
#[test]
16601475
fn buzz_agent_databricks_v2_with_databricks_model_but_no_buzz_agent_model_is_ready() {
@@ -1847,3 +1662,9 @@ mod tests {
18471662
#[cfg(test)]
18481663
#[path = "readiness_goose_file_config_tests.rs"]
18491664
mod goose_file_config_tests;
1665+
1666+
// Effective-launch resolution tests live in a sibling file so this module
1667+
// stays under the desktop file-size ratchet.
1668+
#[cfg(test)]
1669+
#[path = "readiness_effective_launch_tests.rs"]
1670+
mod effective_launch_tests;
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
//! Effective-launch resolution tests — `resolve_effective_agent_env` and
2+
//! `resolve_effective_harness_descriptor`.
3+
//!
4+
//! Split out of `readiness.rs`'s inline `mod tests` to keep that module
5+
//! under the desktop file-size ratchet. Included via `#[path]`; `super::*`
6+
//! resolves against `readiness.rs`, matching the `storage_tests.rs` convention.
7+
8+
use std::collections::BTreeMap;
9+
10+
use super::*;
11+
use crate::managed_agents::discovery::known_acp_runtime_exact;
12+
13+
// ── resolve_effective_agent_env ─────────────────────────────────────────
14+
15+
#[test]
16+
fn resolve_effective_agent_env_user_env_wins_over_structured_fields() {
17+
// User env_vars must win over baked defaults; in OSS builds baked map is empty,
18+
// so this validates the user-env layer is present in the output.
19+
let mut env_vars = BTreeMap::new();
20+
env_vars.insert("BUZZ_AGENT_PROVIDER".to_string(), "anthropic".to_string());
21+
env_vars.insert(
22+
"BUZZ_AGENT_MODEL".to_string(),
23+
"claude-opus-4-5".to_string(),
24+
);
25+
26+
// Minimal record: only the fields resolve_effective_agent_env reads.
27+
let record = crate::managed_agents::types::ManagedAgentRecord {
28+
pubkey: "test-pubkey".to_string(),
29+
name: "test-agent".to_string(),
30+
persona_id: None,
31+
private_key_nsec: String::new(),
32+
auth_tag: None,
33+
relay_url: String::new(),
34+
avatar_url: None,
35+
acp_command: "buzz-acp".to_string(),
36+
agent_command: "buzz-agent".to_string(),
37+
agent_command_override: None,
38+
agent_args: vec![],
39+
mcp_command: String::new(),
40+
turn_timeout_seconds: 320,
41+
idle_timeout_seconds: None,
42+
max_turn_duration_seconds: None,
43+
parallelism: 1,
44+
system_prompt: None,
45+
model: None,
46+
provider: None,
47+
persona_source_version: None,
48+
env_vars,
49+
start_on_app_launch: false,
50+
auto_restart_on_config_change: true,
51+
runtime_pid: None,
52+
backend: Default::default(),
53+
backend_agent_id: None,
54+
provider_policy_pending: false,
55+
provider_binary_path: None,
56+
team_id: None,
57+
persona_team_dir: None,
58+
persona_name_in_team: None,
59+
created_at: String::new(),
60+
updated_at: String::new(),
61+
last_started_at: None,
62+
last_stopped_at: None,
63+
last_exit_code: None,
64+
last_error: None,
65+
last_error_code: None,
66+
respond_to: Default::default(),
67+
respond_to_allowlist: vec![],
68+
display_name: None,
69+
slug: None,
70+
runtime: None,
71+
name_pool: Vec::new(),
72+
is_builtin: false,
73+
is_active: true,
74+
shared: false,
75+
source_team: None,
76+
source_team_persona_slug: None,
77+
catalog_source: None,
78+
definition_respond_to: None,
79+
definition_respond_to_allowlist: Vec::new(),
80+
definition_parallelism: None,
81+
relay_mesh: None,
82+
effort_level: None,
83+
};
84+
85+
let runtime = known_acp_runtime_exact("buzz-agent");
86+
let effective = resolve_effective_agent_env(&record, &[], runtime, &Default::default());
87+
88+
// User env_vars must be present in the output (last-write-wins).
89+
assert_eq!(
90+
effective.env.get("BUZZ_AGENT_PROVIDER").map(String::as_str),
91+
Some("anthropic")
92+
);
93+
assert_eq!(
94+
effective.env.get("BUZZ_AGENT_MODEL").map(String::as_str),
95+
Some("claude-opus-4-5")
96+
);
97+
}
98+
99+
#[test]
100+
fn resolve_effective_harness_descriptor_uses_preset_args_for_pinned_command() {
101+
// An agent pinned to a known ACP runtime via agent_command_override,
102+
// with no runtime id and no instance args, must take the launch args
103+
// from the matching PRESET_HARNESSES entry. Otherwise the bare command
104+
// (e.g. `omp`) launches the interactive TUI, which times out at ACP
105+
// `initialize` under headless Buzz (no controlling TTY).
106+
let mk = |command: &str| crate::managed_agents::types::ManagedAgentRecord {
107+
pubkey: "k".to_string(),
108+
name: "agent".to_string(),
109+
agent_command_override: Some(command.to_string()),
110+
agent_args: vec![],
111+
runtime: None,
112+
persona_id: None,
113+
private_key_nsec: String::new(),
114+
auth_tag: None,
115+
relay_url: String::new(),
116+
avatar_url: None,
117+
acp_command: "buzz-acp".to_string(),
118+
agent_command: String::new(),
119+
mcp_command: String::new(),
120+
turn_timeout_seconds: 320,
121+
idle_timeout_seconds: None,
122+
max_turn_duration_seconds: None,
123+
parallelism: 1,
124+
system_prompt: None,
125+
model: None,
126+
provider: None,
127+
persona_source_version: None,
128+
env_vars: BTreeMap::new(),
129+
start_on_app_launch: false,
130+
auto_restart_on_config_change: true,
131+
runtime_pid: None,
132+
backend: Default::default(),
133+
backend_agent_id: None,
134+
provider_policy_pending: false,
135+
provider_binary_path: None,
136+
team_id: None,
137+
persona_team_dir: None,
138+
persona_name_in_team: None,
139+
created_at: String::new(),
140+
updated_at: String::new(),
141+
last_started_at: None,
142+
last_stopped_at: None,
143+
last_exit_code: None,
144+
last_error: None,
145+
last_error_code: None,
146+
respond_to: Default::default(),
147+
respond_to_allowlist: vec![],
148+
display_name: None,
149+
slug: None,
150+
name_pool: Vec::new(),
151+
is_builtin: false,
152+
is_active: true,
153+
shared: false,
154+
source_team: None,
155+
source_team_persona_slug: None,
156+
catalog_source: None,
157+
definition_respond_to: None,
158+
definition_respond_to_allowlist: Vec::new(),
159+
definition_parallelism: None,
160+
relay_mesh: None,
161+
effort_level: None,
162+
};
163+
let global = crate::managed_agents::GlobalAgentConfig::default();
164+
165+
let desc =
166+
|command: &str| resolve_effective_harness_descriptor(&mk(command), &[], &global).unwrap();
167+
168+
// ACP-mode runtimes resolve to `acp`.
169+
assert_eq!(desc("devin").args, vec!["acp".to_string()]);
170+
assert_eq!(desc("omp").args, vec!["acp".to_string()]);
171+
assert_eq!(desc("opencode").args, vec!["acp".to_string()]);
172+
assert_eq!(desc("kimi").args, vec!["acp".to_string()]);
173+
assert_eq!(desc("cursor-agent").args, vec!["acp".to_string()]);
174+
assert_eq!(desc("openclaw").args, vec!["acp".to_string()]);
175+
// Grok launches its agent stdio mode (not the TUI).
176+
assert_eq!(
177+
desc("grok").args,
178+
vec![
179+
"agent".to_string(),
180+
"--always-approve".to_string(),
181+
"stdio".to_string()
182+
]
183+
);
184+
185+
// Explicit instance args always win over the preset fallback.
186+
let mut explicit = mk("omp");
187+
explicit.agent_args = vec!["acp".to_string(), "--foo".to_string()];
188+
let explicit_desc = resolve_effective_harness_descriptor(&explicit, &[], &global).unwrap();
189+
assert_eq!(
190+
explicit_desc.args,
191+
vec!["acp".to_string(), "--foo".to_string()]
192+
);
193+
194+
// An unknown command with no preset keeps the (empty) instance args.
195+
assert!(desc("my-fancy-cli").args.is_empty());
196+
}

0 commit comments

Comments
 (0)