From e04dcb96c26e824d7fa9bcf1313e8a38c8cadb3f Mon Sep 17 00:00:00 2001 From: Taylor Ho Date: Fri, 22 May 2026 16:50:29 -0700 Subject: [PATCH] fix: re-read persona system_prompt at spawn time for non-pack agents Previously, the persona re-read in spawn_agent_child() was gated behind has_persona_pack (requiring both persona_pack_path and persona_name_in_pack). Non-pack persona-linked agents fell through to the stale record.system_prompt snapshot from creation time. Now, when record.persona_id is set, we always re-read the PersonaRecord from personas.json at spawn time. Falls back to the record snapshot only when no persona is linked or the persona can't be found. Fixes: editing a persona's instructions now takes effect on the next agent spawn without needing to delete and recreate the agent. --- .../src-tauri/src/managed_agents/runtime.rs | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/desktop/src-tauri/src/managed_agents/runtime.rs b/desktop/src-tauri/src/managed_agents/runtime.rs index 770618fdb..a644adb86 100644 --- a/desktop/src-tauri/src/managed_agents/runtime.rs +++ b/desktop/src-tauri/src/managed_agents/runtime.rs @@ -609,25 +609,20 @@ pub fn spawn_agent_child( command.env("SPROUT_ACP_PERSONA_NAME", persona_name); } - // Resolve system prompt and model: prefer the persona definition (if a - // persona pack is configured and the persona matched), otherwise fall back - // to the record-level overrides. - let has_persona_pack = - record.persona_pack_path.is_some() && record.persona_name_in_pack.is_some(); - let persona_prompt_and_model: Option<(String, Option)> = has_persona_pack - .then(|| { - record - .persona_id - .as_deref() - .and_then(|pid| { - super::load_personas(app) - .ok()? - .into_iter() - .find(|p| p.id == pid) - }) - .map(|p| (p.system_prompt, p.model)) + // Resolve system prompt and model: when a persona_id is set, always + // re-read the PersonaRecord at spawn time so edits take effect without + // deleting and recreating the agent. Fall back to the record-level + // snapshot only when no persona is linked or the persona can't be found. + let persona_prompt_and_model: Option<(String, Option)> = record + .persona_id + .as_deref() + .and_then(|pid| { + super::load_personas(app) + .ok()? + .into_iter() + .find(|p| p.id == pid) }) - .flatten(); + .map(|p| (p.system_prompt, p.model)); let (effective_prompt, effective_model) = match persona_prompt_and_model { Some((prompt, model)) => (Some(prompt), model),