Skip to content

Commit c1de3e7

Browse files
wesbillmanPinky
andauthored
fix(desktop): align onboarding runtime auth (#2229)
Signed-off-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent 258cc92 commit c1de3e7

5 files changed

Lines changed: 191 additions & 15 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/runtime.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::{
88
managed_agents::{
99
append_log_marker, known_acp_runtime, login_shell_path, managed_agent_log_path,
1010
missing_command_message, normalize_agent_args, open_log_file, resolve_command,
11-
spawn_key_refusal, ManagedAgentProcess, ManagedAgentRecord, ManagedAgentSummary,
11+
spawn_key_refusal, KnownAcpRuntime, ManagedAgentProcess, ManagedAgentRecord,
12+
ManagedAgentSummary,
1213
},
1314
util::now_iso,
1415
};
@@ -1466,6 +1467,21 @@ pub(crate) fn build_respond_to_env(
14661467
Ok((set, remove))
14671468
}
14681469

1470+
pub(crate) fn configure_runtime_cli(
1471+
command: &mut std::process::Command,
1472+
runtime: Option<&KnownAcpRuntime>,
1473+
) {
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);
1482+
}
1483+
}
1484+
14691485
/// Spawn an agent process without holding any locks on records or runtimes.
14701486
/// Returns the child process and log path on success. The caller is responsible
14711487
/// for updating `ManagedAgentRecord` fields and inserting into the runtimes map.
@@ -1843,6 +1859,7 @@ pub fn spawn_agent_child(
18431859
for (key, value) in super::env_vars::merged_user_env(&persona_over_global, &record.env_vars) {
18441860
command.env(key, value);
18451861
}
1862+
configure_runtime_cli(&mut command, runtime_meta);
18461863

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

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,45 @@ fn name_matches_interpreter_rejects_node_prefix() {
579579
assert!(!super::name_matches_interpreter("node-gyp"));
580580
}
581581

582+
#[test]
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());
598+
599+
let mut command = std::process::Command::new("buzz-acp");
600+
super::configure_runtime_cli(&mut command, super::known_acp_runtime("claude-agent-acp"));
601+
602+
if let Some(path) = original_path {
603+
std::env::set_var("PATH", path);
604+
} else {
605+
std::env::remove_var("PATH");
606+
}
607+
assert!(command
608+
.get_envs()
609+
.any(|(key, value)| { key == "CLAUDE_CODE_EXECUTABLE" && value == Some(cli.as_os_str()) }));
610+
}
611+
612+
#[test]
613+
fn codex_spawn_does_not_set_a_claude_executable() {
614+
let mut command = std::process::Command::new("buzz-acp");
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"));
619+
}
620+
582621
// ── PGID-based orphan sweep tests ───────────────────────────────────────
583622

584623
/// Validates the kernel invariant that the orphan sweep PGID fix relies on:

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
pickWelcomeGuideAgent,
99
pickWelcomeGuideAgentForRelay,
1010
pickWelcomeTeamStarterAgentForRelay,
11+
welcomeStarterRuntimeUpdate,
1112
WELCOME_GUIDE_AGENT_NAME,
1213
WELCOME_GUIDE_PERSONA_ID,
1314
WELCOME_TEAM_ID,
@@ -28,6 +29,7 @@ function makeAgent(overrides = {}) {
2829
relayUrl: RELAY_A,
2930
acpCommand: "buzz-acp",
3031
agentCommand: "buzz-agent",
32+
agentCommandOverride: null,
3133
agentArgs: [],
3234
mcpCommand: "buzz-dev-mcp",
3335
turnTimeoutSeconds: 120,
@@ -36,6 +38,7 @@ function makeAgent(overrides = {}) {
3638
parallelism: 1,
3739
systemPrompt: null,
3840
model: null,
41+
provider: null,
3942
envVars: {},
4043
status: "stopped",
4144
pid: null,
@@ -205,6 +208,87 @@ test("all Welcome starters use the onboarding runtime preference", async () => {
205208
}
206209
});
207210

211+
test("existing Welcome starter rematerializes runtime-specific fields atomically", () => {
212+
const existing = makeAgent({
213+
pubkey: PUB_A,
214+
personaId: WELCOME_GUIDE_PERSONA_ID,
215+
agentCommand: "claude-agent-acp",
216+
agentCommandOverride: "claude-agent-acp",
217+
agentArgs: ["--old"],
218+
mcpCommand: "",
219+
model: "claude-sonnet",
220+
provider: "anthropic",
221+
});
222+
223+
assert.deepEqual(
224+
welcomeStarterRuntimeUpdate(existing, {
225+
name: "Fizz",
226+
agentCommand: "codex-acp",
227+
agentArgs: ["--new"],
228+
mcpCommand: "buzz-dev-mcp",
229+
model: "gpt-5.6-sol",
230+
provider: null,
231+
}),
232+
{
233+
pubkey: PUB_A,
234+
agentCommand: "codex-acp",
235+
harnessOverride: true,
236+
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,
268+
},
269+
);
270+
});
271+
272+
test("existing Welcome starter needs no update when runtime already matches", () => {
273+
const existing = makeAgent({
274+
personaId: WELCOME_GUIDE_PERSONA_ID,
275+
agentCommand: "codex-acp",
276+
agentArgs: ["--same"],
277+
});
278+
279+
assert.equal(
280+
welcomeStarterRuntimeUpdate(existing, {
281+
name: "Fizz",
282+
agentCommand: "codex-acp",
283+
agentArgs: ["--same"],
284+
mcpCommand: "buzz-dev-mcp",
285+
model: null,
286+
provider: null,
287+
}),
288+
null,
289+
);
290+
});
291+
208292
test("welcome team starter definitions and role identities are stable", () => {
209293
assert.equal(WELCOME_TEAM_ID, "builtin-team:welcome");
210294
assert.deepEqual(WELCOME_TEAM_STARTERS, [

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

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,37 @@ export async function buildWelcomeStarterCreateInput(
229229
};
230230
}
231231

232+
export function welcomeStarterRuntimeUpdate(
233+
existing: ManagedAgent,
234+
desired: CreateManagedAgentInput,
235+
) {
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 ?? "";
242+
if (
243+
existing.agentCommand === desired.agentCommand &&
244+
existing.agentArgs.join(",") === desiredArgs.join(",") &&
245+
existing.model === desiredModel &&
246+
existing.provider === desiredProvider &&
247+
existing.mcpCommand === desiredMcpCommand
248+
) {
249+
return null;
250+
}
251+
252+
return {
253+
pubkey: existing.pubkey,
254+
agentCommand: desired.agentCommand,
255+
harnessOverride: true,
256+
agentArgs: desiredArgs,
257+
mcpCommand: desiredMcpCommand,
258+
model: desiredModel,
259+
provider: desiredProvider,
260+
};
261+
}
262+
232263
/**
233264
* Ensure the complete built-in Welcome Team is ready for kickoff.
234265
* The team itself is Rust-seeded; this only activates personas, creates any
@@ -254,29 +285,33 @@ async function provisionWelcomeTeam(
254285

255286
const agents: ManagedAgent[] = [];
256287
for (const starter of WELCOME_TEAM_STARTERS) {
288+
const persona = personasById.get(starter.personaId);
289+
if (!persona) {
290+
throw new Error(`${starter.name} agent not found.`);
291+
}
292+
const desired = await buildWelcomeStarterCreateInput(
293+
starter,
294+
persona,
295+
runtimes,
296+
globalConfig.preferred_runtime,
297+
relayUrl,
298+
);
257299
const existing = pickWelcomeTeamStarterAgentForRelay(
258300
existingAgents,
259301
starter,
260302
relayUrl,
261303
);
262304
if (existing) {
263-
agents.push(existing);
305+
const runtimeUpdate = welcomeStarterRuntimeUpdate(existing, desired);
306+
agents.push(
307+
runtimeUpdate
308+
? (await updateManagedAgent(runtimeUpdate)).agent
309+
: existing,
310+
);
264311
continue;
265312
}
266313

267-
const persona = personasById.get(starter.personaId);
268-
if (!persona) {
269-
throw new Error(`${starter.name} agent not found.`);
270-
}
271-
const created = await createManagedAgent(
272-
await buildWelcomeStarterCreateInput(
273-
starter,
274-
persona,
275-
runtimes,
276-
globalConfig.preferred_runtime,
277-
relayUrl,
278-
),
279-
);
314+
const created = await createManagedAgent(desired);
280315
agents.push(created.agent);
281316
}
282317
const [lead, honey, bumble] = agents;

0 commit comments

Comments
 (0)