Skip to content

fix: add cancellation token support to ChatAgentResponseStream - #291327

Merged
Karthik Nadig (karthiknadig) merged 1 commit into
mainfrom
comprehensive-whippet
Jan 28, 2026
Merged

Karthik Nadig (karthiknadig) merged 1 commit into
mainfrom
comprehensive-whippet

Conversation

@karthiknadig

Copy link
Copy Markdown
Member

fixes: #291295

Copilot Bot review requested due to automatic review settings January 28, 2026 16:37
@karthiknadig
Karthik Nadig (karthiknadig) marked this pull request as ready for review January 28, 2026 16:47

ghost left a comment

Copy link
Copy Markdown
Contributor

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 wires cancellation support into ChatAgentResponseStream so that question carousels (used by the Ask tool) respect the request cancellation token, fixing the issue where pressing Stop did not correctly stop the agent session.

Changes:

  • Extended ChatAgentResponseStream to accept a CancellationToken and used raceCancellation when awaiting questionCarousel answers, so the await unblocks when the request is cancelled.
  • Updated ExtHostChatAgents2.$invokeAgent to pass the request’s CancellationToken into ChatAgentResponseStream, and to continue cleaning up any pending carousel resolvers on request completion or cancellation.
  • Updated ExtHostChatSession to adapt to the new ChatAgentResponseStream constructor by passing CancellationToken.None, keeping chat sessions’ behavior unchanged while enabling cancellation for agent-based requests.

Reviewed changes

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

File Description
src/vs/workbench/api/common/extHostChatSessions.ts Adjusts ExtHostChatSession construction and getActiveRequestStream to pass a CancellationToken (set to CancellationToken.None) into the new ChatAgentResponseStream signature.
src/vs/workbench/api/common/extHostChatAgents2.ts Adds a CancellationToken parameter to ChatAgentResponseStream, uses raceCancellation in questionCarousel, and passes the request token from $invokeAgent, ensuring Ask tool question carousels are cancellable and properly cleaned up.

@vs-code-engineering vs-code-engineering Bot added this to the January 2026 milestone Jan 28, 2026
// Wait for the user to submit answers
return deferred.p;
// Wait for the user to submit answers, but respect cancellation
return raceCancellation(deferred.p, that._token);

ghost Jan 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this tool implemented in the extension when it has this tight coupling with UI? The ChatAgentResponseStream is not supposed to return a value to the caller, that's contrary to the concept of a "stream" IMO

ghost Jan 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will create an issue to move this into main and get rid of this part.

ghost Jan 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@karthiknadig
Karthik Nadig (karthiknadig) deleted the comprehensive-whippet branch January 28, 2026 16:56
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Mar 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pressing Stop does not stop Agent session if using Ask tool

4 participants