Sessions: preserve cancelled session content in list#307684
Merged
Conversation
When a session is stopped before the agent commits a worktree, keep it in the sessions list with Completed status instead of removing it. This lets the user review whatever content the agent produced before cancellation. - Use CancellationError in _waitForCommittedSession to distinguish cancellation from unexpected failures - On CancellationError in _sendFirstChat/_sendSubsequentChat, set Completed status and fire a changed event instead of removing - Add tests for committed-then-stopped and cancelled-before-commit flows Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Copilot Chat Sessions provider to preserve sessions that are cancelled before they’ve been committed (worktree/URI swap), so users can still reopen the session and review the chat content instead of losing it.
Changes:
- Switch pre-commit cancellation signaling to use
CancellationErrorso callers can distinguish cancellation from unexpected failures. - On
CancellationError, keep the temp session cached, mark itCompleted, and emit achangedevent instead of removing it. - Extend/adjust browser tests to validate “kept in list” behavior for both pre-commit cancellation and post-commit stopping.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts |
Handles pre-commit cancellation by throwing CancellationError and preserving the temp session instead of deleting it. |
src/vs/sessions/contrib/copilotChatSessions/test/browser/copilotChatSessionsProvider.test.ts |
Adds tests for “stop after commit” and “cancel before commit keeps session” behaviors, plus commit-event controllable test setup. |
Comments suppressed due to low confidence (1)
src/vs/sessions/contrib/copilotChatSessions/test/browser/copilotChatSessionsProvider.test.ts:839
- The test name says the cancelled-before-commit session is kept “with completed status”, but the assertions only check that the session remains and that a
changedevent fired. Add an assertion that the kept session’sstatusisSessionStatus.Completedto actually cover the new behavior.
await sendPromise;
assert.strictEqual(provider.getSessions().length, 1, 'session should stay in list after cancellation');
assert.ok(
changes.some(e => e.changed.some(s => s.sessionId === sessionId)),
'changed event should have fired',
);
src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts
Outdated
Show resolved
Hide resolved
src/vs/sessions/contrib/copilotChatSessions/test/browser/copilotChatSessionsProvider.test.ts
Outdated
Show resolved
Hide resolved
…variable - Move isCanceled check from the early-exit path to after the 5s safety timeout so a late commit event (user stops after worktree was initiated but before IPC finishes) is not missed. - Remove unused changes variable in committed-session test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bhavyaus
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a session was stopped before the agent committed a worktree, it was removed from the sessions list entirely. This meant the user lost access to whatever content the agent had already produced — chat messages, partial responses, etc.
Fix
Instead of removing cancelled-before-commit sessions, keep them in the list with
Completedstatus so the user can still click on them and review the chat content.Changes
_waitForCommittedSession— throwsCancellationError(instead of genericError) when the response is cancelled before commit, enabling the caller to distinguish cancellation from unexpected failures._sendFirstChatcatch block — onCancellationError, keeps the temp session in the cache withCompletedstatus and fires achangedevent instead of removing it. Other errors still clean up as before._sendSubsequentChatcatch block — same pattern for the multi-chat path.Tests
stopping a committed session keeps it in the list— verifies a session committed mid-request persists after cancellation.cancelling the request before commit keeps the session with completed status— verifies cancelled sessions stay in the list with achangedevent (notremoved).