Bug Description
After closing and reopening cmux, chat-created agents appear in the left pane but the chat orchestrator has no knowledge of them. Asking "What agents do I have?" in chat returns empty, and �p_send_to_agent fails because the orchestrator doesn't know the agent exists.
Chat history is restored. The agent entry in the left pane is restored. But the orchestrator's in-memory state and SDK sessions are not.
Steps to Reproduce
- Open cmux, switch to Chat view
- Ask chat to create one or more agents (e.g., "Create an agent for ~/src/my-project")
- Agents appear in left pane with activity feed working
- Close cmux completely
- Reopen cmux
- Agents still appear in left pane (persisted via
session.json)
- Ask chat "What agents do I have?" → reports none
- Activity feed cards are also gone (expected — documented as in-memory only)
Root Cause
Three things are persisted to disk but not reconnected on restore:
1. OrchestratorTools.managedAgents Map is never repopulated
src/main/services/OrchestratorTools.ts:25 — managedAgents is a plain in-memory Map<string, { label, cwd }>, populated only when vp_create_agent runs. Nothing repopulates it on startup, so both vp_list_agents and the enrichPrompt() context injection (via getActiveAgents()) return empty.
2. useSessionRestore doesn't notify the main process
src/renderer/hooks/useSessionRestore.ts:23-33 — for hasSession: true agents, the restore path dispatches ADD_AGENT to the renderer state but never calls any IPC to register the agent back into the main process orchestrator.
3. SDK sessions are not recreated
src/main/services/AgentSessionService.ts holds sessions in an in-memory Map. The restore path never calls agent-session:create for hasSession: true agents, so no SDK session exists for them.
Proposed Fix
-
Add a registration IPC handler (e.g., orchestrator:register-agent) in OrchestratorTools.ts or copilot.ts that inserts an agent into managedAgents without creating a new SDK session.
-
Call it from useSessionRestore for each hasSession: true agent during restore, so the orchestrator knows about pre-existing agents.
-
Lazy-recreate SDK sessions — when vp_send_to_agent is called for a registered agent that has no active SDK session, create the session on demand rather than failing.
This keeps the restore path lightweight (no eager SDK session creation) while ensuring chat awareness of existing agents.
Related
Affected Files
| File |
Role |
src/main/services/OrchestratorTools.ts:25 |
managedAgents Map (never repopulated) |
src/main/services/OrchestratorTools.ts:116-136 |
vp_list_agents reads from empty map |
src/main/services/CopilotService.ts:137-143 |
enrichPrompt() injects empty agent context |
src/renderer/hooks/useSessionRestore.ts:23-33 |
Restore path skips main process registration |
src/main/ipc/copilot.ts:8-26 |
Tool init, agent context provider setup |
src/main/services/AgentSessionService.ts |
SDK sessions not recreated |
Bug Description
After closing and reopening cmux, chat-created agents appear in the left pane but the chat orchestrator has no knowledge of them. Asking "What agents do I have?" in chat returns empty, and �p_send_to_agent fails because the orchestrator doesn't know the agent exists.
Chat history is restored. The agent entry in the left pane is restored. But the orchestrator's in-memory state and SDK sessions are not.
Steps to Reproduce
session.json)Root Cause
Three things are persisted to disk but not reconnected on restore:
1.
OrchestratorTools.managedAgentsMap is never repopulatedsrc/main/services/OrchestratorTools.ts:25—managedAgentsis a plain in-memoryMap<string, { label, cwd }>, populated only whenvp_create_agentruns. Nothing repopulates it on startup, so bothvp_list_agentsand theenrichPrompt()context injection (viagetActiveAgents()) return empty.2.
useSessionRestoredoesn't notify the main processsrc/renderer/hooks/useSessionRestore.ts:23-33— forhasSession: trueagents, the restore path dispatchesADD_AGENTto the renderer state but never calls any IPC to register the agent back into the main process orchestrator.3. SDK sessions are not recreated
src/main/services/AgentSessionService.tsholds sessions in an in-memory Map. The restore path never callsagent-session:createforhasSession: trueagents, so no SDK session exists for them.Proposed Fix
Add a registration IPC handler (e.g.,
orchestrator:register-agent) inOrchestratorTools.tsorcopilot.tsthat inserts an agent intomanagedAgentswithout creating a new SDK session.Call it from
useSessionRestorefor eachhasSession: trueagent during restore, so the orchestrator knows about pre-existing agents.Lazy-recreate SDK sessions — when
vp_send_to_agentis called for a registered agent that has no active SDK session, create the session on demand rather than failing.This keeps the restore path lightweight (no eager SDK session creation) while ensuring chat awareness of existing agents.
Related
managedAgentsglobal mutable state as a refactoring target — this fix could be combined with that cleanup.Affected Files
src/main/services/OrchestratorTools.ts:25managedAgentsMap (never repopulated)src/main/services/OrchestratorTools.ts:116-136vp_list_agentsreads from empty mapsrc/main/services/CopilotService.ts:137-143enrichPrompt()injects empty agent contextsrc/renderer/hooks/useSessionRestore.ts:23-33src/main/ipc/copilot.ts:8-26src/main/services/AgentSessionService.ts