Copilot CLI: Close Diffs When Client Disconnects#3626
Merged
DonJayamanne merged 2 commits intomainfrom Feb 10, 2026
Merged
Conversation
62a815b to
3c8f98f
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Copilot CLI MCP integration so that when a CLI client session disconnects, any diff editors opened on behalf of that session are automatically rejected/closed via the existing diff lifecycle.
Changes:
- Thread
sessionIdinto MCP tool registration and store it on each registered diff (viaopen_diff). - Add a disconnect hook in
InProcHttpServerand wire it inCopilotCLIContribto close diffs for the disconnected session. - Add unit tests for
DiffStateManager.closeAllForSessionand basic coverage for the new disconnect-listener API.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/extension/agents/copilotcli/vscode-node/tools/openDiff.ts | Adds sessionId to diff registration so diffs can be associated with a CLI session. |
| src/extension/agents/copilotcli/vscode-node/tools/index.ts | Passes sessionId through when registering MCP tools. |
| src/extension/agents/copilotcli/vscode-node/test/openDiff.spec.ts | Updates tool registration in tests to provide a sessionId. |
| src/extension/agents/copilotcli/vscode-node/test/inProcHttpServer.spec.ts | Adds tests for onClientDisconnected listener registration/disposal. |
| src/extension/agents/copilotcli/vscode-node/test/closeAllForSession.spec.ts | Adds tests for session-scoped diff closure behavior. |
| src/extension/agents/copilotcli/vscode-node/inProcHttpServer.ts | Adds disconnect listener mechanism and passes sessionId into tool registration. |
| src/extension/agents/copilotcli/vscode-node/diffState.ts | Adds sessionId to ActiveDiff and implements closeAllForSession. |
| src/extension/agents/copilotcli/vscode-node/contribution.ts | Registers disconnect handler to close diffs for the disconnected session and updates tool registration callback signature. |
Comments suppressed due to low confidence (1)
src/extension/agents/copilotcli/vscode-node/test/inProcHttpServer.spec.ts:68
- The "support multiple listeners" / "only remove the disposed listener" tests currently only assert that listeners haven't been called, but they never trigger a disconnect event, so they don't validate multi-listener behavior. It would be more robust to trigger a simulated disconnect and assert both listeners fire, then dispose one and assert only the remaining one fires on the next disconnect.
it('should support multiple listeners', () => {
const listener1 = vi.fn();
const listener2 = vi.fn();
server.onClientDisconnected(listener1);
server.onClientDisconnected(listener2);
// Both should be registered (we can't easily trigger them without
// going through the full MCP flow, but at least we verify registration)
expect(listener1).not.toHaveBeenCalled();
expect(listener2).not.toHaveBeenCalled();
});
it('should only remove the disposed listener', () => {
const listener1 = vi.fn();
const listener2 = vi.fn();
const disposable1 = server.onClientDisconnected(listener1);
server.onClientDisconnected(listener2);
disposable1.dispose();
// listener2 should still be registered
expect(listener1).not.toHaveBeenCalled();
expect(listener2).not.toHaveBeenCalled();
});
src/extension/agents/copilotcli/vscode-node/inProcHttpServer.ts
Outdated
Show resolved
Hide resolved
src/extension/agents/copilotcli/vscode-node/test/inProcHttpServer.spec.ts
Show resolved
Hide resolved
DonJayamanne
approved these changes
Feb 10, 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.
When CLI disconnects from the MCP server, we now close any diffs we had open.