Summary
Agent activity feed cards (tool calls, assistant messages, errors, done markers) are lost when cmux is closed and reopened. The agent reappears in the left pane and the orchestrator knows about it (fixed in #35), but the activity feed is empty.
Current Behavior
AppState.agentEvents is Record<string, AgentEvent[]> kept in renderer memory only
- On restart, the agent shows an empty activity feed
- This was a deliberate design choice to avoid bloating
session.json (see aidocs/chat-orchestrator.md:84,127)
Proposed Approach
Persist events in per-agent files (similar to how conversations use individual JSON files), not in session.json:
- Save: Write
{userData}/agent-events/{agentId}.json when events are added (debounced)
- Load: On session restore, read the events file for each
hasSession: true agent and dispatch SET_AGENT_EVENTS (new action) to populate agentEvents
- Cleanup: Delete the events file when an agent is removed
Considerations
- File size: Activity feeds can grow large (every tool call, delta, subagent event). May need a cap (e.g., keep last N events or last M bytes) or prune transient events (
tool-progress, assistant-delta) before saving
- Write frequency: Events stream rapidly during agent work. Debounce writes (e.g., 2-5 seconds) or only write on
session-idle
- Deltas vs. full messages:
assistant-delta events are accumulated into assistant-message in the UI. Consider only persisting the merged display events rather than raw SDK events
Affected Files
| File |
Change |
src/shared/types.ts |
Add SET_AGENT_EVENTS action |
src/renderer/contexts/AppStateContext.tsx |
Handle SET_AGENT_EVENTS in reducer |
src/renderer/hooks/useSessionRestore.ts |
Load events on restore |
New: src/main/services/AgentEventPersistence.ts |
Read/write per-agent event files |
src/main/ipc/agent-session.ts |
IPC for saving/loading events |
src/preload.ts |
Expose event persistence API |
Related
Summary
Agent activity feed cards (tool calls, assistant messages, errors, done markers) are lost when cmux is closed and reopened. The agent reappears in the left pane and the orchestrator knows about it (fixed in #35), but the activity feed is empty.
Current Behavior
AppState.agentEventsisRecord<string, AgentEvent[]>kept in renderer memory onlysession.json(seeaidocs/chat-orchestrator.md:84,127)Proposed Approach
Persist events in per-agent files (similar to how conversations use individual JSON files), not in
session.json:{userData}/agent-events/{agentId}.jsonwhen events are added (debounced)hasSession: trueagent and dispatchSET_AGENT_EVENTS(new action) to populateagentEventsConsiderations
tool-progress,assistant-delta) before savingsession-idleassistant-deltaevents are accumulated intoassistant-messagein the UI. Consider only persisting the merged display events rather than raw SDK eventsAffected Files
src/shared/types.tsSET_AGENT_EVENTSactionsrc/renderer/contexts/AppStateContext.tsxSET_AGENT_EVENTSin reducersrc/renderer/hooks/useSessionRestore.tssrc/main/services/AgentEventPersistence.tssrc/main/ipc/agent-session.tssrc/preload.tsRelated
aidocs/chat-orchestrator.mdlines 84, 127 — documents the current in-memory-only design