Skip to content

feat: persist agent activity feed across restarts #36

@ianphil

Description

@ianphil

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:

  1. Save: Write {userData}/agent-events/{agentId}.json when events are added (debounced)
  2. Load: On session restore, read the events file for each hasSession: true agent and dispatch SET_AGENT_EVENTS (new action) to populate agentEvents
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions