@@ -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