Skip to content

Copilot CLI: Close Diffs When Client Disconnects#3626

Merged
DonJayamanne merged 2 commits intomainfrom
mrayermannmsft/feat/closediffsondisconnect
Feb 10, 2026
Merged

Copilot CLI: Close Diffs When Client Disconnects#3626
DonJayamanne merged 2 commits intomainfrom
mrayermannmsft/feat/closediffsondisconnect

Conversation

@MRayermannMSFT
Copy link
Copy Markdown
Member

@MRayermannMSFT MRayermannMSFT commented Feb 10, 2026

When CLI disconnects from the MCP server, we now close any diffs we had open.

@MRayermannMSFT MRayermannMSFT force-pushed the mrayermannmsft/feat/closediffsondisconnect branch from 62a815b to 3c8f98f Compare February 10, 2026 21:21
@MRayermannMSFT MRayermannMSFT marked this pull request as ready for review February 10, 2026 21:23
Copilot AI review requested due to automatic review settings February 10, 2026 21:23
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 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 sessionId into MCP tool registration and store it on each registered diff (via open_diff).
  • Add a disconnect hook in InProcHttpServer and wire it in CopilotCLIContrib to close diffs for the disconnected session.
  • Add unit tests for DiffStateManager.closeAllForSession and 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();
	});
@DonJayamanne DonJayamanne added this pull request to the merge queue Feb 10, 2026
@vs-code-engineering vs-code-engineering bot added this to the February 2026 milestone Feb 10, 2026
Merged via the queue into main with commit 258e7cd Feb 10, 2026
19 checks passed
@DonJayamanne DonJayamanne deleted the mrayermannmsft/feat/closediffsondisconnect branch February 10, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants