From e6661e76990d08b37a725729d0d68174683eba95 Mon Sep 17 00:00:00 2001 From: jnjpng Date: Tue, 20 Jan 2026 12:00:37 -0800 Subject: [PATCH] fix: use single source of truth for agent name (#602) Co-authored-by: Letta --- src/cli/App.tsx | 24 ++++++++++++++---------- src/cli/commands/profile.ts | 6 +++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/cli/App.tsx b/src/cli/App.tsx index eec4ba5..64b9088 100644 --- a/src/cli/App.tsx +++ b/src/cli/App.tsx @@ -567,6 +567,11 @@ export default function App({ const [agentId, setAgentId] = useState(initialAgentId); const [agentState, setAgentState] = useState(initialAgentState); + // Helper to update agent name (updates agentState, which is the single source of truth) + const updateAgentName = useCallback((name: string) => { + setAgentState((prev) => (prev ? { ...prev, name } : prev)); + }, []); + // Track current conversation (always created fresh on startup) const [conversationId, setConversationId] = useState(initialConversationId); @@ -902,7 +907,8 @@ export default function App({ llmConfigRef.current = llmConfig; }, [llmConfig]); const [currentModelId, setCurrentModelId] = useState(null); - const [agentName, setAgentName] = useState(null); + // Derive agentName from agentState (single source of truth) + const agentName = agentState?.name ?? null; const [agentDescription, setAgentDescription] = useState(null); const [agentLastRunAt, setAgentLastRunAt] = useState(null); const currentModelLabel = @@ -1527,8 +1533,8 @@ export default function App({ const { getClient } = await import("../agent/client"); const client = await getClient(); const agent = await client.agents.retrieve(agentId); + setAgentState(agent); setLlmConfig(agent.llm_config); - setAgentName(agent.name); setAgentDescription(agent.description ?? null); // Get last message timestamp from agent state if available const lastRunCompletion = (agent as { last_run_completion?: string }) @@ -1926,7 +1932,7 @@ export default function App({ } // Also update agent state if other fields changed - setAgentName(agent.name); + setAgentState(agent); setAgentDescription(agent.description ?? null); const lastRunCompletion = ( agent as { last_run_completion?: string } @@ -3284,7 +3290,6 @@ export default function App({ agentIdRef.current = targetAgentId; setAgentId(targetAgentId); setAgentState(agent); - setAgentName(agent.name); setLlmConfig(agent.llm_config); setConversationId(targetConversationId); @@ -3376,7 +3381,6 @@ export default function App({ agentIdRef.current = agent.id; setAgentId(agent.id); setAgentState(agent); - setAgentName(agent.name); setLlmConfig(agent.llm_config); // Build success message with hints @@ -4613,7 +4617,7 @@ export default function App({ try { const client = await getClient(); await client.agents.update(agentId, { name: newName }); - setAgentName(newName); + updateAgentName(newName); buffersRef.current.byId.set(cmdId, { kind: "command", @@ -4916,7 +4920,7 @@ export default function App({ agentId, agentName: agentName || "", setCommandRunning, - setAgentName, + updateAgentName, }; // /profile - open agent browser (now points to /agents) @@ -5012,7 +5016,7 @@ export default function App({ agentId, agentName: agentName || "", setCommandRunning, - setAgentName, + updateAgentName, }; await handlePin(profileCtx, msg, argsStr); return { submitted: true }; @@ -5026,7 +5030,7 @@ export default function App({ agentId, agentName: agentName || "", setCommandRunning, - setAgentName, + updateAgentName, }; const argsStr = msg.trim().slice(6).trim(); handleUnpin(profileCtx, msg, argsStr); @@ -8476,7 +8480,7 @@ Plan file path: ${planFilePath}`; // Rename if new name provided if (newName && newName !== agentName) { await client.agents.update(agentId, { name: newName }); - setAgentName(newName); + updateAgentName(newName); } // Pin the agent diff --git a/src/cli/commands/profile.ts b/src/cli/commands/profile.ts index fed4ee3..1aed940 100644 --- a/src/cli/commands/profile.ts +++ b/src/cli/commands/profile.ts @@ -21,7 +21,7 @@ export interface ProfileCommandContext { agentId: string; agentName: string; setCommandRunning: (running: boolean) => void; - setAgentName: (name: string) => void; + updateAgentName: (name: string) => void; } // Helper to add a command result to buffers @@ -163,7 +163,7 @@ export async function handleProfileSave( const client = await getClient(); // Update agent name via API await client.agents.update(ctx.agentId, { name: profileName }); - ctx.setAgentName(profileName); + ctx.updateAgentName(profileName); // Save profile to BOTH local and global settings settingsManager.saveProfile(profileName, ctx.agentId); @@ -332,7 +332,7 @@ export async function handlePin( const { getClient } = await import("../../agent/client"); const client = await getClient(); await client.agents.update(ctx.agentId, { name }); - ctx.setAgentName(name); + ctx.updateAgentName(name); } catch (error) { addCommandResult( ctx.buffersRef,