Repository navigation
Copilot CLI sessions: restore the session's model and don't resume sessions in use elsewhere - #342230
Closed
Karthik Nadig (karthiknadig) wants to merge 2 commits into
Closed
Karthik Nadig (karthiknadig) wants to merge 2 commits into
Karthik Nadig (karthiknadig) wants to merge 2 commits into
Conversation
Chat history reported the bare Copilot CLI model id, but VS Code looks up a session's model by its full language model identifier (copilotcli/<id>). Opening a Copilot CLI session therefore never restored its model: the picker fell back to a default, and the first request switched the session to that model. This matters for sessions handed off from the Copilot CLI with /code. Co-authored-by: Copilot <[email protected]>
Resuming a session appends to its event log, so a Copilot CLI session that is open in a terminal, or running a request in another VS Code window, must not also be resumed here. Check the session's in-use locks before resuming, and again after resuming in case another process opened it in between. When the session is in use, the request fails with a message that says where it is open instead of writing to the session. Co-authored-by: Copilot <[email protected]>
Contributor
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two history-reconstruction paths still replace Auto selection with a fixed model.
2 open issues
What changed in this PR
Improves Copilot CLI session reopening in VS Code by restoring model identifiers and rejecting resumes when another process holds the session.
Changes:
- Reports fully qualified model identifiers in chat history.
- Checks session locks before and after resuming and surfaces a specific error.
- Adds model-restoration and session-lock regression coverage.
| File | Description |
|---|---|
| extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts | Displays session-in-use errors. |
| extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts | Handles session-in-use errors. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/test/testHelpers.ts | Adds mock session-lock state. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/test/copilotCliSessionService.spec.ts | Tests rejection of busy sessions. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotcliSessionService.ts | Guards session resumption with lock checks. |
| extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotCli.ts | Reuses the model vendor constant. |
| extensions/copilot/src/extension/chatSessions/copilotcli/common/utils.ts | Defines qualified model identifiers. |
| extensions/copilot/src/extension/chatSessions/copilotcli/common/test/copilotCLITools.spec.ts | Updates model-history assertions and coverage. |
| extensions/copilot/src/extension/chatSessions/copilotcli/common/copilotCLITools.ts | Emits qualified history model identifiers. |
Review effort: Balanced
| const turn = turns[currentRequestTurnIndex]; | ||
| if (turn instanceof ChatRequestTurn2 && turn.modelId !== modelId) { | ||
| turns[currentRequestTurnIndex] = new ChatRequestTurn2(turn.prompt, turn.command, turn.references, turn.participant, [...turn.toolReferences], turn.editedFileEvents, turn.id, modelId, turn.modeInstructions2); | ||
| const modelIdentifier = getCopilotCLIModelIdentifier(modelId); |
| currentResponseModelId = resolvedRequestModelId; | ||
| currentCreditsUsed = details?.creditsUsed; | ||
| turns.push(new ChatRequestTurn2(`${commandPrefix}${prompt}`, undefined, references, '', [], undefined, details?.requestId ?? event.id, details?.isUsingAutoModel ? 'auto' : resolvedRequestModelId, modeInstructions2)); | ||
| const requestModelId = details?.isUsingAutoModel ? 'auto' : resolvedRequestModelId; |
Member
Author
|
Closing: the Copilot CLI's |
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.

Part of microsoft/vscode-internalbacklog#10107. Split out of #342120, which is about routing
/codelinks.Two fixes to the Copilot extension's Copilot CLI chat session provider (
copilotcli):claude-sonnet-4.5). VS Code looks up a session's model by its full language model identifier (copilotcli/claude-sonnet-4.5), so opening a Copilot CLI session never restored its model: the picker fell back to a default, and the next request switched the session to it. History now reports the full identifier. Requests made with Auto stay on Auto.How to test
copilot, pick a model other than the default, and send a message. Exit the CLI.copilot --resume=<session-id>in a terminal and leave it open. Send a message to the same session in VS Code. The request fails with the message above, and nothing is written to the session.Validation
npx tsc --noEmit --project tsconfig.jsoninextensions/copilot: passed.npx vitest run src/extension/chatSessions/copilotcli src/extension/chatSessions/vscode-nodeinextensions/copilot: 1277 passed, 1 failed. The failure ("preserves order of edit toolCallIds and permissions for multiple pending edits") also fails onmainwithout these changes.npx eslint --max-warnings=0on the changed files: passed.