Skip to content

sessions: resolve focused chat for Copilot CLI state file and debug log export#322197

Draft
roblourens wants to merge 2 commits into
mainfrom
agents/multi-chat-support-copilot-cli-a5a7f20d
Draft

sessions: resolve focused chat for Copilot CLI state file and debug log export#322197
roblourens wants to merge 2 commits into
mainfrom
agents/multi-chat-support-copilot-cli-a5a7f20d

Conversation

@roblourens

Copy link
Copy Markdown
Member

What

Two Agent Host developer actions in the Agents window were always operating on a session's main chat, ignoring which chat tab was actually focused:

  • Open Copilot CLI State File (agentHost.openSessionEventsFile)
  • Export Agent Host Debug Logs (agentHost.exportDebugLogs)

Now that a session can contain multiple chats, and the Copilot CLI state/events file is per-chat (~/.copilot/session-state/<chatId>/events.jsonl), both actions opened/exported the wrong file when a non-main chat tab was focused.

Change

Resolve the focused chat's resource via IActiveSession.activeChat before delegating to the shared events-URI resolver:

  • openSessionEventsFileActions.ts — use activeSession.activeChat.get()?.resource, falling back to the session resource.
  • exportDebugLogsAction.ts — use the focused chat's resource (and title) for the active session; the most-recent-session fallback path still uses the session resource since a plain ISession has no focused-chat notion. The isAgentHostSession type guard was made generic so it preserves the IActiveSession subtype (needed to access activeChat).

The shared resolveEventsUri resolver and the workbench-side OpenCopilotCliStateFileAction (which already uses the last-focused chat widget and is disabled in the Agents window) are unchanged. A chat resource carries the same scheme/authority as its session resource, so remote-connection lookup and local/remote classification are unaffected — only the per-chat events path changes.

Notes for reviewers

  • No behavior change for single-chat sessions.
  • npm run typecheck-client passes; ESLint is clean on the changed files.

(Written by Copilot)

…og export

The "Open Copilot CLI State File" and "Export Agent Host Debug Logs"
actions resolved the session's main chat regardless of which chat tab
was focused. Since the events file is per-chat, use the focused chat
(IActiveSession.activeChat) when resolving the events.jsonl resource.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 20, 2026 03:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates two Agents window developer actions so they operate on the focused chat tab (via IActiveSession.activeChat) rather than always using the session’s main chat, which is important now that Copilot CLI state/events are stored per chat (~/.copilot/session-state/<chatId>/events.jsonl).

Changes:

  • Resolve the Copilot CLI state/events file using the focused chat’s resource, falling back to the session resource when needed.
  • Export Agent Host debug logs scoped to the focused chat (resource + title) for the active session, while keeping the “most recent session” fallback behavior intact.
  • Make the isAgentHostSession type guard generic to preserve the IActiveSession subtype (so activeChat remains accessible after narrowing).
Show a summary per file
File Description
src/vs/sessions/contrib/providers/agentHost/browser/openSessionEventsFileActions.ts Uses activeSession.activeChat.get()?.resource (fallback to session resource) so “Open Copilot CLI State File” targets the focused chat tab.
src/vs/sessions/contrib/providers/agentHost/browser/exportDebugLogsAction.ts Uses the focused chat’s resource/title when exporting debug logs for the active session; updates the type guard to preserve the active-session subtype.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

…t's sdk session

The "Open Copilot CLI State File" and "Export Agent Host Debug Logs" actions
resolved events.jsonl from the chat resource's path id. For peer chats that
path id is the main session id, not the peer chat's backing Copilot SDK
session id, so they opened/exported the wrong file (and export filtered the
shared ~/.copilot/logs by the wrong id).

The host now reports each peer chat's backing sdk session id to the renderer
under SessionState._meta (keyed by AHP chat id), the same carrier already used
for git state. The front end maps the focused chat to its sdk id and reuses the
existing resolveEventsUri / getCopilotCliSessionRawId pipeline by swapping the
resource path to the sdk id. The default chat needs no entry (its path id
already names its logs) and falls back to the chat resource.

- common/state/sessionState.ts: readChatSessionIds / withChatSessionId accessors
- common/agentService.ts: optional IAgent.getChatSessionId
- node/copilot/copilotAgent.ts: implement getChatSessionId (in-mem + persisted)
- node/agentService.ts: publish sdk id into _meta on create/restore, clean up on dispose
- browser/baseAgentHostSessionsProvider.ts: getChatSdkSessionId / getChatSdkSessionResource
- copilotCliEventsUri.ts: buildSdkSessionResource helper
- sessions actions: resolve focused chat -> sdk resource, fall back to chat resource

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.

2 participants