Skip to content

fix: resume disconnected sessions in agent/compaction RPC handlers#491

Draft
maxtara wants to merge 3 commits intostagingfrom
bug/agent-exception-1
Draft

fix: resume disconnected sessions in agent/compaction RPC handlers#491
maxtara wants to merge 3 commits intostagingfrom
bug/agent-exception-1

Conversation

@maxtara
Copy link
Collaborator

@maxtara maxtara commented Mar 2, 2026

Problem

Agent and compaction IPC handlers (copilot:setActiveAgent, copilot:getSessionAgents, copilot:getActiveAgent, copilot:compactSession) crash when the backend CLI has dropped the session but Cooper's sessions Map still holds a reference to it.

Error:

Error occurred in handler for 'copilot:getSessionAgents': TypeError: Cannot read properties of undefined (reading 'agent')
Error occurred in handler for 'copilot:setActiveAgent': Error: Request session.agent.select failed with message: Session not found for sessionId: ...

This can happen any time the backend session expires, the CLI restarts, or a connection resets — not just at startup.

Fix

Added try/catch with resumeDisconnectedSession + retry to all four handlers, matching the existing pattern already used in copilot:send and copilot:sendAndWait. On a Session not found error, the session is transparently reconnected and the operation retried.

Also removed dead-code if (!sessionState.session.rpc) guards — the SDK's rpc getter is lazy-initialized and always returns a value.

Validation

  • npm run build
  • npm run dev

@maxtara maxtara marked this pull request as ready for review March 2, 2026 01:58
@maxtara maxtara marked this pull request as draft March 2, 2026 02:00
When the backend CLI drops a session, agent and compaction IPC handlers now catch the 'Session not found' error, call resumeDisconnectedSession, and retry — matching the existing pattern in copilot:send.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@maxtara maxtara force-pushed the bug/agent-exception-1 branch from b2d3046 to 95880a0 Compare March 2, 2026 03:45
@maxtara maxtara changed the title fix: prevent agent RPC crash before session init fix: resume disconnected sessions in agent/compaction RPC handlers Mar 2, 2026
maxtara and others added 2 commits March 3, 2026 08:53
getSessionAgents and getActiveAgent can be called by the renderer before the session finishes resuming in the main process. Return [] and null instead of throwing, since the renderer will re-query after sessionResumed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant