Skip to content

Commit fdf1c92

Browse files
wesbillmanPinky
andcommitted
fix(onboarding): rematerialize starter runtime config
Keep the Welcome starter's command, arguments, MCP command, model, and provider aligned when onboarding switches harnesses. Route Claude launches and model discovery through the same resolved CLI used by readiness checks. Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Wes <[email protected]>
1 parent 2ee0189 commit fdf1c92

7 files changed

Lines changed: 98 additions & 62 deletions

File tree

‎desktop/src-tauri/src/commands/agent_model_process.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(super) async fn run_agent_models_command(
4848
for (k, v) in &merged_env {
4949
cmd.env(k, v);
5050
}
51+
crate::managed_agents::configure_runtime_cli(&mut cmd, known_acp_runtime(&agent_command));
5152
cmd.stdout(std::process::Stdio::piped())
5253
.stderr(std::process::Stdio::piped())
5354
.output()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,6 @@ fn probe_auth_status(binary_path: &Path, probe_args: &[&str]) -> AuthStatus {
909909

910910
let mut command = std::process::Command::new(binary_path);
911911
command.args(&probe_args[1..]);
912-
cli_probe::configure_auth_probe_command(&mut command, probe_args);
913912
if let Some(ref path) = augmented_path {
914913
command.env("PATH", path);
915914
}

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ pub(crate) enum ProbeOutcome {
4747
/// one term.
4848
const CONFIG_PARSE_SIGNALS: &[&str] = &["error loading configuration", "unknown variant"];
4949

50-
pub(crate) fn configure_auth_probe_command(
51-
command: &mut std::process::Command,
52-
probe_args: &[&str],
53-
) {
54-
if probe_args.first() == Some(&"claude") {
55-
command.env_remove("ANTHROPIC_API_KEY");
56-
}
57-
}
58-
5950
/// Run the probe at the resolved absolute path so the GUI-PATH gap is
6051
/// bypassed. Injects the same augmented PATH used for launched agents so
6152
/// script shims with `/usr/bin/env <interpreter>` shebangs can find runtimes
@@ -67,7 +58,6 @@ pub(crate) fn login_probe(
6758
) -> ProbeOutcome {
6859
let mut command = std::process::Command::new(binary_path);
6960
command.args(&probe_args[1..]);
70-
configure_auth_probe_command(&mut command, probe_args);
7161
if let Some(path) = augmented_path {
7262
command.env("PATH", path);
7363
}
@@ -107,28 +97,6 @@ pub(crate) fn classify_probe_output(stderr_bytes: &[u8], exit_success: bool) ->
10797
mod tests {
10898
use super::{ProbeOutcome, CONFIG_PARSE_SIGNALS};
10999

110-
#[test]
111-
fn claude_auth_probe_removes_ambient_api_key() {
112-
let mut command = std::process::Command::new("claude");
113-
command.env("ANTHROPIC_API_KEY", "invalid-but-present");
114-
super::configure_auth_probe_command(&mut command, &["claude", "auth", "status"]);
115-
116-
assert!(command
117-
.get_envs()
118-
.any(|(key, value)| { key == "ANTHROPIC_API_KEY" && value.is_none() }));
119-
}
120-
121-
#[test]
122-
fn codex_auth_probe_leaves_unrelated_api_key_alone() {
123-
let mut command = std::process::Command::new("codex");
124-
command.env("ANTHROPIC_API_KEY", "unrelated");
125-
super::configure_auth_probe_command(&mut command, &["codex", "login", "status"]);
126-
127-
assert!(command.get_envs().any(|(key, value)| {
128-
key == "ANTHROPIC_API_KEY" && value == Some(std::ffi::OsStr::new("unrelated"))
129-
}));
130-
}
131-
132100
#[cfg(unix)]
133101
#[test]
134102
fn login_probe_uses_augmented_path_for_env_shebang_interpreter() {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,12 +1467,18 @@ pub(crate) fn build_respond_to_env(
14671467
Ok((set, remove))
14681468
}
14691469

1470-
fn scrub_ambient_runtime_credentials(
1470+
pub(crate) fn configure_runtime_cli(
14711471
command: &mut std::process::Command,
14721472
runtime: Option<&KnownAcpRuntime>,
14731473
) {
1474-
if runtime.is_some_and(|runtime| runtime.id == "claude") {
1475-
command.env_remove("ANTHROPIC_API_KEY");
1474+
let Some(runtime) = runtime else {
1475+
return;
1476+
};
1477+
if runtime.id != "claude" {
1478+
return;
1479+
}
1480+
if let Some(cli_path) = runtime.underlying_cli.and_then(resolve_command) {
1481+
command.env("CLAUDE_CODE_EXECUTABLE", cli_path);
14761482
}
14771483
}
14781484

@@ -1829,11 +1835,6 @@ pub fn spawn_agent_child(
18291835
);
18301836
}
18311837

1832-
// Claude subscription auth must come from the CLI credential store unless
1833-
// the user explicitly configured an API key in Buzz. A stale key inherited
1834-
// from the Desktop process otherwise overrides a valid subscription login.
1835-
scrub_ambient_runtime_credentials(&mut command, runtime_meta);
1836-
18371838
// ── User env vars: live persona env under agent overrides ──────────
18381839
//
18391840
// The record's `env_vars` holds agent-level overrides only. The linked
@@ -1858,6 +1859,7 @@ pub fn spawn_agent_child(
18581859
for (key, value) in super::env_vars::merged_user_env(&persona_over_global, &record.env_vars) {
18591860
command.env(key, value);
18601861
}
1862+
configure_runtime_cli(&mut command, runtime_meta);
18611863

18621864
// Buzz shared compute is stored as a native provider; derive the OpenAI-compatible
18631865
// transport at spawn time and scrub any unrelated ambient OpenAI key.

‎desktop/src-tauri/src/managed_agents/runtime/tests.rs‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -580,30 +580,42 @@ fn name_matches_interpreter_rejects_node_prefix() {
580580
}
581581

582582
#[test]
583-
fn claude_spawn_scrubs_ambient_api_key() {
584-
let mut command = std::process::Command::new("buzz-acp");
585-
command.env("ANTHROPIC_API_KEY", "stale");
583+
fn claude_spawn_uses_the_probed_cli_executable() {
584+
let _guard = crate::managed_agents::lock_path_mutex();
585+
let temp = tempfile::tempdir().expect("temp dir");
586+
let cli = temp
587+
.path()
588+
.join(format!("claude{}", std::env::consts::EXE_SUFFIX));
589+
std::fs::write(&cli, "").expect("write fake cli");
590+
#[cfg(unix)]
591+
{
592+
use std::os::unix::fs::PermissionsExt;
593+
std::fs::set_permissions(&cli, std::fs::Permissions::from_mode(0o755))
594+
.expect("make fake cli executable");
595+
}
596+
let original_path = std::env::var_os("PATH");
597+
std::env::set_var("PATH", temp.path());
586598

587-
super::scrub_ambient_runtime_credentials(
588-
&mut command,
589-
super::known_acp_runtime("claude-agent-acp"),
590-
);
599+
let mut command = std::process::Command::new("buzz-acp");
600+
super::configure_runtime_cli(&mut command, super::known_acp_runtime("claude-agent-acp"));
591601

602+
if let Some(path) = original_path {
603+
std::env::set_var("PATH", path);
604+
} else {
605+
std::env::remove_var("PATH");
606+
}
592607
assert!(command
593608
.get_envs()
594-
.any(|(key, value)| key == "ANTHROPIC_API_KEY" && value.is_none()));
609+
.any(|(key, value)| { key == "CLAUDE_CODE_EXECUTABLE" && value == Some(cli.as_os_str()) }));
595610
}
596611

597612
#[test]
598-
fn non_claude_spawn_preserves_ambient_api_key() {
613+
fn codex_spawn_does_not_set_a_claude_executable() {
599614
let mut command = std::process::Command::new("buzz-acp");
600-
command.env("ANTHROPIC_API_KEY", "explicit");
601-
602-
super::scrub_ambient_runtime_credentials(&mut command, super::known_acp_runtime("codex-acp"));
603-
604-
assert!(command.get_envs().any(|(key, value)| {
605-
key == "ANTHROPIC_API_KEY" && value == Some(std::ffi::OsStr::new("explicit"))
606-
}));
615+
super::configure_runtime_cli(&mut command, super::known_acp_runtime("codex-acp"));
616+
assert!(!command
617+
.get_envs()
618+
.any(|(key, _)| key == "CLAUDE_CODE_EXECUTABLE"));
607619
}
608620

609621
// ── PGID-based orphan sweep tests ───────────────────────────────────────

‎desktop/src/features/onboarding/welcomeGuide.test.mjs‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function makeAgent(overrides = {}) {
2929
relayUrl: RELAY_A,
3030
acpCommand: "buzz-acp",
3131
agentCommand: "buzz-agent",
32+
agentCommandOverride: null,
3233
agentArgs: [],
3334
mcpCommand: "buzz-dev-mcp",
3435
turnTimeoutSeconds: 120,
@@ -37,6 +38,7 @@ function makeAgent(overrides = {}) {
3738
parallelism: 1,
3839
systemPrompt: null,
3940
model: null,
41+
provider: null,
4042
envVars: {},
4143
status: "stopped",
4244
pid: null,
@@ -206,25 +208,63 @@ test("all Welcome starters use the onboarding runtime preference", async () => {
206208
}
207209
});
208210

209-
test("existing Welcome starter is repinned when onboarding runtime changes", () => {
211+
test("existing Welcome starter rematerializes runtime-specific fields atomically", () => {
210212
const existing = makeAgent({
211213
pubkey: PUB_A,
212214
personaId: WELCOME_GUIDE_PERSONA_ID,
213215
agentCommand: "claude-agent-acp",
216+
agentCommandOverride: "claude-agent-acp",
214217
agentArgs: ["--old"],
218+
mcpCommand: "",
219+
model: "claude-sonnet",
220+
provider: "anthropic",
215221
});
216222

217223
assert.deepEqual(
218224
welcomeStarterRuntimeUpdate(existing, {
219225
name: "Fizz",
220226
agentCommand: "codex-acp",
221227
agentArgs: ["--new"],
228+
mcpCommand: "buzz-dev-mcp",
229+
model: "gpt-5.6-sol",
230+
provider: null,
222231
}),
223232
{
224233
pubkey: PUB_A,
225234
agentCommand: "codex-acp",
226235
harnessOverride: true,
227236
agentArgs: ["--new"],
237+
mcpCommand: "buzz-dev-mcp",
238+
model: "gpt-5.6-sol",
239+
provider: null,
240+
},
241+
);
242+
});
243+
244+
test("existing Welcome starter clears stale model and provider for Claude", () => {
245+
const existing = makeAgent({
246+
personaId: WELCOME_GUIDE_PERSONA_ID,
247+
agentCommand: "codex-acp",
248+
agentArgs: [],
249+
model: "gpt-5.6-sol",
250+
provider: "openai",
251+
});
252+
253+
assert.deepEqual(
254+
welcomeStarterRuntimeUpdate(existing, {
255+
name: "Fizz",
256+
agentCommand: "claude-agent-acp",
257+
agentArgs: [],
258+
mcpCommand: "",
259+
}),
260+
{
261+
pubkey: PUB_A,
262+
agentCommand: "claude-agent-acp",
263+
harnessOverride: true,
264+
agentArgs: [],
265+
mcpCommand: "",
266+
model: null,
267+
provider: null,
228268
},
229269
);
230270
});
@@ -241,6 +281,9 @@ test("existing Welcome starter needs no update when runtime already matches", ()
241281
name: "Fizz",
242282
agentCommand: "codex-acp",
243283
agentArgs: ["--same"],
284+
mcpCommand: "buzz-dev-mcp",
285+
model: null,
286+
provider: null,
244287
}),
245288
null,
246289
);

‎desktop/src/features/onboarding/welcomeGuide.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,18 @@ export function welcomeStarterRuntimeUpdate(
233233
existing: ManagedAgent,
234234
desired: CreateManagedAgentInput,
235235
) {
236+
if (!desired.agentCommand) return null;
237+
238+
const desiredArgs = desired.agentArgs ?? [];
239+
const desiredModel = desired.model ?? null;
240+
const desiredProvider = desired.provider ?? null;
241+
const desiredMcpCommand = desired.mcpCommand ?? "";
236242
if (
237-
!desired.agentCommand ||
238-
(existing.agentCommand === desired.agentCommand &&
239-
existing.agentArgs.join(",") === (desired.agentArgs ?? []).join(","))
243+
existing.agentCommand === desired.agentCommand &&
244+
existing.agentArgs.join(",") === desiredArgs.join(",") &&
245+
existing.model === desiredModel &&
246+
existing.provider === desiredProvider &&
247+
existing.mcpCommand === desiredMcpCommand
240248
) {
241249
return null;
242250
}
@@ -245,7 +253,10 @@ export function welcomeStarterRuntimeUpdate(
245253
pubkey: existing.pubkey,
246254
agentCommand: desired.agentCommand,
247255
harnessOverride: true,
248-
agentArgs: desired.agentArgs ?? [],
256+
agentArgs: desiredArgs,
257+
mcpCommand: desiredMcpCommand,
258+
model: desiredModel,
259+
provider: desiredProvider,
249260
};
250261
}
251262

0 commit comments

Comments
 (0)