Skip to content

fix: Persist third-party model chat sessions locally to prevent history loss#295757

Open
bxf1001g wants to merge 2 commits intomicrosoft:mainfrom
bxf1001g:fix/persist-external-chat-sessions
Open

fix: Persist third-party model chat sessions locally to prevent history loss#295757
bxf1001g wants to merge 2 commits intomicrosoft:mainfrom
bxf1001g:fix/persist-external-chat-sessions

Conversation

@bxf1001g
Copy link
Copy Markdown

Fixes #300942
When using third-party model agents (e.g., Claude) via Copilot Chat's "Session Target" selector, chat sessions are
lost after VS Code closes or restarts. The session data is saved to disk during the active session, but is never
reloaded into the SESSIONS history panel.
Root Cause
External sessions (those with non-vscodeLocalChatSession:// URIs) are treated as metadata-only:

  1. shouldStoreSession() returns false for non-local sessions, so only metadata (title, date) is persisted — not the
    actual conversation data
  2. getHistorySessionItems() filters out all entries with isExternal: true, hiding them from the history panel
  3. saveState() calls storeSessionsMetadataOnly() for non-local sessions instead of writing full session data
    The result: conversation data exists in .jsonl on disk while the session is active, but after shutdown, only the
    metadata index entry (marked isExternal: true) survives — and it gets filtered out on next load.
    Fix
    This PR adds local persistence for external sessions so they survive across restarts:
    chatSessionStore.ts:
  • Added isPersistedLocally and localStorageId fields to IChatSessionEntryMetadata to track external sessions that
    have been fully saved locally
  • Added storeExternalSessionsLocally() — persists external session data using a generated UUID as the storage key
    (since external session IDs are full URIs with characters invalid for filenames)
  • Updated trimEntries() to include locally-persisted external sessions in the trim count and properly clean up
    their data files
    chatServiceImpl.ts:
  • Updated willDisposeModel to call storeExternalSessionsLocally() for non-local sessions with requests (instead of
    storeSessionsMetadataOnly())
  • Updated saveState() to persist full data for non-local sessions that have requests
  • Updated getHistorySessionItems() to include external sessions that have isPersistedLocally: true, using their
    localStorageId to construct a restorable session resource URI
    Testing
  • TypeScript compilation passes with zero errors in changed files
  • The fix is backward-compatible: existing local sessions are unaffected
  • External sessions without requests continue to use metadata-only storage
    Repro Steps (before fix)
  1. Open a workspace in VS Code
  2. Open Copilot Chat → select Claude as Session Target
  3. Have a conversation with multiple messages
  4. Close VS Code
  5. Reopen VS Code and the same workspace
  6. Check SESSIONS panel → session is gone

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Copilot Chat session history loss for third-party (“external”) model sessions by persisting their full conversation data locally and showing them in the SESSIONS history panel after restart.

Changes:

  • Add local persistence for external chat sessions via a generated UUID-based storage key.
  • Include locally-persisted external sessions in history retrieval and in trimming logic.
  • Update lifecycle persistence paths to store full data (not metadata-only) for non-local sessions that have requests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/vs/workbench/contrib/chat/common/model/chatSessionStore.ts Adds external-session local persistence, index metadata fields, and updates trimming to account for locally-persisted externals.
src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts Persists external sessions with requests during model disposal/saveState and includes locally-persisted external sessions in history listing.

@bxf1001g
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Axonyx Quantum Pvt Ltd"

External sessions (e.g., Claude via Session Target) were only saving
metadata to the index, causing conversation history to be lost on
restart. This change persists full session data locally using a
generated UUID as the storage key, and includes these sessions in
the history panel.

Fixes microsoft/vscode-copilot-release#14129

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bxf1001g bxf1001g force-pushed the fix/persist-external-chat-sessions branch from 0e08283 to f8b8785 Compare February 17, 2026 14:05
@bxf1001g
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree [company="Axonyx Quantum Pvt Ltd"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve chat session history when using third-party model agents (e.g., Claude)

4 participants