Skip to content

Commit 6373813

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
fix(desktop): resolve effective model and prompt from persona in display path (#972)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent 1bb8b8d commit 6373813

5 files changed

Lines changed: 51 additions & 17 deletions

File tree

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const rules = [
3030
// Do not add to this list; split the file instead. Remove each entry as its
3131
// file is broken up. Tracked as a follow-up.
3232
const overrides = new Map([
33-
["src-tauri/src/commands/agents.rs", 1287],
33+
["src-tauri/src/commands/agents.rs", 1294],
3434
["src-tauri/src/managed_agents/nest.rs", 1420],
3535
["src-tauri/src/managed_agents/runtime.rs", 1940],
3636
["src-tauri/src/managed_agents/personas.rs", 1080],

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use crate::{
77
app_state::AppState,
88
managed_agents::{
99
build_managed_agent_summary, default_agent_workdir, find_managed_agent_mut,
10-
known_acp_runtime, load_managed_agents, managed_agent_avatar_url, missing_command_message,
11-
normalize_agent_args, resolve_command, save_managed_agents, sync_managed_agent_processes,
10+
known_acp_runtime, load_managed_agents, load_personas, managed_agent_avatar_url,
11+
missing_command_message, normalize_agent_args, resolve_command,
12+
resolve_effective_prompt_model_provider, save_managed_agents, sync_managed_agent_processes,
1213
try_regenerate_nest, AgentModelInfo, AgentModelsResponse, UpdateManagedAgentRequest,
1314
UpdateManagedAgentResponse,
1415
},
@@ -62,7 +63,17 @@ pub async fn get_agent_models(
6263
crate::managed_agents::resolve_persona_env(&app, record.persona_id.as_deref())?;
6364
let env = crate::managed_agents::merged_user_env(&persona_env, &record.env_vars);
6465

65-
(resolved, resolved_agent, args, record.model.clone(), env)
66+
// Resolve the effective model from the linked persona so the ModelPicker
67+
// dropdown shows the current persona model as selected.
68+
let personas = load_personas(&app).unwrap_or_default();
69+
let (_prompt, effective_model, _provider) = resolve_effective_prompt_model_provider(
70+
record.persona_id.as_deref(),
71+
&personas,
72+
record.system_prompt.clone(),
73+
record.model.clone(),
74+
);
75+
76+
(resolved, resolved_agent, args, effective_model, env)
6677
}; // store lock released — subprocess runs without holding the lock
6778

6879
// Clone the env map for redaction below — `merged_env` is moved
@@ -249,7 +260,10 @@ pub async fn update_managed_agent(
249260
None
250261
};
251262

252-
let summary = build_managed_agent_summary(&app, record, &runtimes)?;
263+
let summary = {
264+
let personas = load_personas(&app).unwrap_or_default();
265+
build_managed_agent_summary(&app, record, &runtimes, &personas)?
266+
};
253267
(summary, sync_params)
254268
}; // lock dropped here
255269

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use tauri::{AppHandle, State};
33
use crate::{
44
app_state::AppState,
55
managed_agents::{
6-
build_managed_agent_summary, find_managed_agent_mut, load_managed_agents,
6+
build_managed_agent_summary, find_managed_agent_mut, load_managed_agents, load_personas,
77
save_managed_agents, sync_managed_agent_processes, ManagedAgentSummary,
88
},
99
util::now_iso,
@@ -41,5 +41,6 @@ pub fn set_managed_agent_start_on_app_launch(
4141
.iter()
4242
.find(|record| record.pubkey == pubkey)
4343
.ok_or_else(|| format!("agent {pubkey} not found"))?;
44-
build_managed_agent_summary(&app, record, &runtimes)
44+
let personas = load_personas(&app).unwrap_or_default();
45+
build_managed_agent_summary(&app, record, &runtimes, &personas)
4546
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ async fn start_local_agent_with_preflight(
111111
.iter()
112112
.find(|record| record.pubkey == pubkey)
113113
.ok_or_else(|| format!("agent {pubkey} not found"))?;
114-
build_managed_agent_summary(app, record, &runtimes)
114+
let personas = load_personas(app).unwrap_or_default();
115+
build_managed_agent_summary(app, record, &runtimes, &personas)
115116
}
116117

117118
/// Build the standard agent JSON payload for provider deploy calls.
@@ -283,9 +284,10 @@ pub fn list_managed_agents(
283284
save_managed_agents(&app, &records)?;
284285
}
285286

287+
let personas = load_personas(&app).unwrap_or_default();
286288
records
287289
.iter()
288-
.map(|record| build_managed_agent_summary(&app, record, &runtimes))
290+
.map(|record| build_managed_agent_summary(&app, record, &runtimes, &personas))
289291
.collect()
290292
}
291293

@@ -565,8 +567,9 @@ pub async fn create_managed_agent(
565567
.iter()
566568
.find(|record| record.pubkey == pubkey)
567569
.ok_or_else(|| "created agent disappeared unexpectedly".to_string())?;
570+
let personas = load_personas(&app).unwrap_or_default();
568571
(
569-
build_managed_agent_summary(&app, record, &runtimes)?,
572+
build_managed_agent_summary(&app, record, &runtimes, &personas)?,
570573
resolved_avatar_url,
571574
)
572575
};
@@ -595,7 +598,8 @@ pub async fn create_managed_agent(
595598
.iter()
596599
.find(|record| record.pubkey == pubkey)
597600
.ok_or_else(|| "created agent disappeared unexpectedly".to_string())?;
598-
build_managed_agent_summary(&app, record, &runtimes)?
601+
let personas = load_personas(&app).unwrap_or_default();
602+
build_managed_agent_summary(&app, record, &runtimes, &personas)?
599603
}
600604
}
601605
} else {
@@ -681,7 +685,8 @@ pub async fn create_managed_agent(
681685
.iter()
682686
.find(|r| r.pubkey == pubkey)
683687
.ok_or_else(|| "agent disappeared".to_string())?;
684-
build_managed_agent_summary(&app, record, &runtimes)?
688+
let personas = load_personas(&app).unwrap_or_default();
689+
build_managed_agent_summary(&app, record, &runtimes, &personas)?
685690
} else {
686691
agent
687692
};
@@ -811,7 +816,8 @@ pub async fn start_managed_agent(
811816
.iter()
812817
.find(|r| r.pubkey == pubkey)
813818
.ok_or_else(|| format!("agent {pubkey} not found"))?;
814-
build_managed_agent_summary(&app, record, &runtimes)
819+
let personas = load_personas(&app).unwrap_or_default();
820+
build_managed_agent_summary(&app, record, &runtimes, &personas)
815821
}
816822
StartTarget::Provider { backend, .. } => Err(format!(
817823
"agent {pubkey} has unsupported backend kind: {backend:?}"
@@ -1003,7 +1009,8 @@ pub fn stop_managed_agent(
10031009
.iter()
10041010
.find(|record| record.pubkey == pubkey)
10051011
.ok_or_else(|| format!("agent {pubkey} not found"))?;
1006-
build_managed_agent_summary(&app, record, &runtimes)
1012+
let personas = load_personas(&app).unwrap_or_default();
1013+
build_managed_agent_summary(&app, record, &runtimes, &personas)
10071014
}
10081015

10091016
#[tauri::command]

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ pub fn build_managed_agent_summary(
12781278
app: &AppHandle,
12791279
record: &ManagedAgentRecord,
12801280
runtimes: &HashMap<String, ManagedAgentProcess>,
1281+
personas: &[crate::managed_agents::types::PersonaRecord],
12811282
) -> Result<ManagedAgentSummary, String> {
12821283
use crate::managed_agents::BackendKind;
12831284

@@ -1330,6 +1331,17 @@ pub fn build_managed_agent_summary(
13301331
}
13311332
};
13321333

1334+
// Resolve the effective model and system_prompt from the linked persona
1335+
// (mirrors spawn-time logic) so the UI displays the current persona values,
1336+
// not the stale record snapshot.
1337+
let (effective_prompt, effective_model, _effective_provider) =
1338+
resolve_effective_prompt_model_provider(
1339+
record.persona_id.as_deref(),
1340+
personas,
1341+
record.system_prompt.clone(),
1342+
record.model.clone(),
1343+
);
1344+
13331345
Ok(ManagedAgentSummary {
13341346
pubkey: record.pubkey.clone(),
13351347
name: record.name.clone(),
@@ -1343,8 +1355,8 @@ pub fn build_managed_agent_summary(
13431355
idle_timeout_seconds: record.idle_timeout_seconds,
13441356
max_turn_duration_seconds: record.max_turn_duration_seconds,
13451357
parallelism: record.parallelism,
1346-
system_prompt: record.system_prompt.clone(),
1347-
model: record.model.clone(),
1358+
system_prompt: effective_prompt,
1359+
model: effective_model,
13481360
mcp_toolsets: record.mcp_toolsets.clone(),
13491361
env_vars: record.env_vars.clone(),
13501362
backend: record.backend.clone(),
@@ -1435,7 +1447,7 @@ pub(crate) fn build_respond_to_env(
14351447
/// linked persona always wins so persona edits propagate on the next spawn; the
14361448
/// record snapshot is the fallback only when no persona is linked or it was
14371449
/// deleted. Provider comes from the persona (the record has no provider field).
1438-
fn resolve_effective_prompt_model_provider(
1450+
pub(crate) fn resolve_effective_prompt_model_provider(
14391451
persona_id: Option<&str>,
14401452
personas: &[crate::managed_agents::types::PersonaRecord],
14411453
record_prompt: Option<String>,

0 commit comments

Comments
 (0)