Skip to content

Commit a3ee2c5

Browse files
authored
fix(desktop): preserve agent model/provider when persona snapshot fields are blank (#1583)
1 parent 3c6c0d4 commit a3ee2c5

6 files changed

Lines changed: 354 additions & 18 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,17 @@ const overrides = new Map([
6060
// config-bridge: get_agent_config_surface/write_agent_config_field/put_agent_session_config
6161
// commands add ~40 lines. Queued to split.
6262
// branch cut; override bumped to cover the merged total. Queued to split.
63+
// persona-blank-fallback: persona_snapshot_with_agent_config_fallback call
64+
// sites add ~4 lines (extra fallback params + inline comments). build_deploy_payload
65+
// fix (blank-persona provider/model fallback) adds ~6 lines. Bug fix.
6366
// archive/mod_tests.rs carries the full test module for archive/mod.rs:
6467
// unit tests + 4 real-relay integration tests (ignored, live-relay only).
6568
// Production logic in mod.rs is now ~527 lines (under 1000). mod_tests.rs
6669
// is test-only content; the override covers the test growth accumulated
6770
// across the local-archive + agent-metric-archive PR series. store_tests.rs
6871
// (~731 lines) is under 1000 so needs no override.
6972
["src-tauri/src/archive/mod_tests.rs", 1208],
70-
["src-tauri/src/commands/agents.rs", 1437],
73+
["src-tauri/src/commands/agents.rs", 1443],
7174
// #1418 read-path fix: get_thread_replies' blocker fix (shared TIMELINE_KINDS
7275
// const + build_thread_replies_filter helper, mirroring the channel sibling so
7376
// the two p-gate filters can't drift) plus two guard unit tests. The file was
@@ -94,7 +97,9 @@ const overrides = new Map([
9497
// activity-feed threads avatar_url into build_managed_agent_summary for the
9598
// assistant-bubble pinned snapshot.
9699
// +1 for agent_pubkey field in setup payload (config-nudge card wire).
97-
["src-tauri/src/managed_agents/runtime.rs", 2208],
100+
// persona-blank-fallback: resolve_effective_prompt_model_provider gains a
101+
// record_provider param + applies persona_field_with_record_fallback. +5 lines.
102+
["src-tauri/src/managed_agents/runtime.rs", 2213],
98103
// config-bridge setup-payload env-boundary fix adds readiness wiring in
99104
// spawn_agent_child; load-bearing security fix, queued to split.
100105
["src-tauri/src/managed_agents/config_bridge/reader.rs", 1016],

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ fn resolve_config_surface(
6565
personas,
6666
record.system_prompt.clone(),
6767
record.model.clone(),
68+
record.provider.clone(),
6869
);
6970

7071
// Build the baseline the reader overrides a live model against, paired with

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,19 @@ async fn start_local_agent_with_preflight(
258258
// starts with the current persona config (system_prompt, model, provider,
259259
// env_vars). This clears the "out of date" drift badge without requiring a
260260
// delete+recreate. Agent-level env_vars overrides still win (persona_snapshot
261-
// layers persona env under agent overrides).
261+
// layers persona env under agent overrides). When the persona leaves model or
262+
// provider blank, the agent record's own configured values are preserved so a
263+
// user-set model/provider is never clobbered by an unconfigured persona.
262264
if let Some(persona_id) = record.persona_id.clone() {
263265
let personas = load_personas(app).unwrap_or_default();
264266
if let Some(persona) = personas.iter().find(|p| p.id == persona_id) {
265267
let snapshot =
266-
crate::managed_agents::persona_events::persona_snapshot(persona, &record.env_vars);
268+
crate::managed_agents::persona_events::persona_snapshot_with_agent_config_fallback(
269+
persona,
270+
&record.env_vars,
271+
record.model.as_deref(), // fallback: record.model
272+
record.provider.as_deref(), // fallback: record.provider
273+
);
267274
if let Some(prompt) = snapshot.system_prompt {
268275
record.system_prompt = Some(prompt);
269276
}
@@ -330,9 +337,10 @@ fn build_deploy_payload(
330337
// stale derived env copies in `env_vars` (or have no provider at all for
331338
// imported personas whose derived keys were filtered at import time).
332339
//
333-
// Precedence mirrors local spawn: persona structured model is authoritative
334-
// when present; the agent record's `model` is a fallback for personas that
335-
// don't specify one (or when no persona is linked).
340+
// Precedence: persona field wins when non-blank; otherwise falls back to the
341+
// record's own field (same blank-normalization as the snapshot path). This
342+
// matches `persona_snapshot_with_agent_config_fallback` exactly — a blank
343+
// persona field must not wipe a record value that the user configured.
336344
let (effective_model, effective_provider) = if let Some(pid) = record.persona_id.as_deref() {
337345
let personas = load_personas(app).map_err(|e| {
338346
format!(
@@ -343,11 +351,12 @@ fn build_deploy_payload(
343351
.into_iter()
344352
.find(|p| p.id == pid)
345353
.ok_or_else(|| format!("persona `{pid}` not found while building deploy payload"))?;
346-
let model = persona.model.clone().or(record.model.clone());
347-
let provider = persona.provider;
354+
let fallback = crate::managed_agents::persona_events::persona_field_with_record_fallback;
355+
let model = fallback(persona.model.as_deref(), record.model.as_deref()); // fallback: record.model
356+
let provider = fallback(persona.provider.as_deref(), record.provider.as_deref()); // fallback: record.provider
348357
(model, provider)
349358
} else {
350-
(record.model.clone(), None)
359+
(record.model.clone(), record.provider.clone())
351360
};
352361

353362
Ok(serde_json::json!({

0 commit comments

Comments
 (0)