Skip to content

fix: make ResponseProcessor.diff and XtabCustomDiffPatchResponseHandler respect cancellation token#4986

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/ensure-cancellation-token-respected
Draft

fix: make ResponseProcessor.diff and XtabCustomDiffPatchResponseHandler respect cancellation token#4986
Copilot wants to merge 3 commits intomainfrom
copilot/ensure-cancellation-token-respected

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 5, 2026

Two async generators ignored the passed CancellationToken, meaning cancellation requests had no effect during streaming — the generators would continue processing until naturally exhausted.

Changes

  • ResponseProcessor.diff — adds optional cancellationToken: CancellationToken = CancellationToken.None parameter; checks isCancellationRequested at the top of each for await iteration and returns early if set

  • XtabCustomDiffPatchResponseHandler.handleResponse — adds optional cancellationToken parameter; checks isCancellationRequested before processing each extracted patch and returns NoNextEditReason.GotCancelled('duringStreaming') if set

  • xtabProvider.streamEdits — passes cancellationToken to both generators; adds a post-loop cancellation check so a token cancelled mid-stream returns GotCancelled('duringStreaming') rather than falling through to NoSuggestions

// Before
export async function* diff(originalLines, modifiedLines, cursorOffset, params): AsyncIterable<LineReplacement> {
    for await (const line of modifiedLines) { /* no cancellation check */ }
}

// After
export async function* diff(originalLines, modifiedLines, cursorOffset, params,
    cancellationToken: CancellationToken = CancellationToken.None): AsyncIterable<LineReplacement> {
    for await (const line of modifiedLines) {
        if (cancellationToken.isCancellationRequested) { return; }
        // ...
    }
}

All new parameters are optional with CancellationToken.None as default, so existing callers are unaffected. Tests added for pre-cancelled tokens and mid-stream cancellation.

Original prompt

Please, fix all issues. Make a commit per fix.

Ensure, ReponseProcessor.diff and XtabCustomDiffPatchResponseHandler respect cancellation token properly.

[Chronological Review: The conversation began with the user requesting an exploration of whether the passed cancellation token is respected by all code paths. The user then requested fixes for all identified issues, specifically mentioning `ResponseProcessor.diff` and `XtabCustomDiffPatchResponseHandler` to ensure they respect the cancellation token properly. The conversation has focused on ensuring proper handling of cancellation tokens in the codebase.]

[Intent Mapping:

  1. "Explore if the passed in cancellation token is respected by all code paths." - User wants to verify the handling of cancellation tokens in the code.
  2. "Please, fix all issues. Make a commit per fix." - User requests to address identified issues with a structured approach to commits.
  3. "Ensure, ResponseProcessor.diff and XtabCustomDiffPatchResponseHandler respect cancellation token properly." - User specifies which components need to be fixed regarding cancellation token handling.]

[Technical Inventory:

  • Repository: vscode-copilot-chat
  • Key Components: ResponseProcessor.diff, XtabCustomDiffPatchResponseHandler
  • Focus: Cancellation token handling in the codebase.]

[Code Archaeology:

  • Files discussed: ResponseProcessor.diff, XtabCustomDiffPatchResponseHandler
  • No specific code changes have been documented yet, as the conversation is still in the planning and exploration phase.]

[Progress Assessment:

  • Completed Tasks: None yet, as the conversation is focused on identifying issues.
  • Partially Complete Work: Exploration of cancellation token handling is ongoing.]

[Context Validation: All necessary context for continuation is captured, including user requests and specific components to focus on.]

[Recent Commands Analysis:

  • Last Agent Commands: The user requested exploration and fixes related to cancellation tokens in specific components.
  • Tool Results Summary: No tool results have been generated yet as the conversation is still in the initial stages of identifying issues.
  • Pre-Summary State: The agent was actively discussing the need to explore and fix cancellation token handling in the specified components when the token budget was exceeded.
  • Operation Context: The commands were executed to align with the user's goal of ensuring proper cancellation token handling in the codebase.]
1. Conversation Overview: - Primary Objectives: 1. "Explore if the passed in cancellation token is respected by all code paths." 2. "Please, fix all issues. Make a commit per fix." 3. "Ensure, `ResponseProcessor.diff` and `XtabCustomDiffPatchResponseHandler` respect cancellation token properly." - Session Context: The conversation has focused on exploring and fixing issues related to cancellation token handling in the codebase, specifically in the `ResponseProcessor.diff` and `XtabCustomDiffPatchResponseHandler`. - User Intent Evolution: The user started with a request for exploration and then moved to a more action-oriented request for fixes and commits.
  1. Technical Foundation:
  • Repository: vscode-copilot-chat
  • Key Components: ResponseProcessor.diff, XtabCustomDiffPatchResponseHandler
  • Focus: Ensuring proper handling of cancellation tokens in the codebase.
  1. Codebase Status:
  • File Name: ResponseProcessor.diff
    • Purpose: To handle differences in responses, potentially involving cancellation tokens.
    • Current State: No modifications have been made yet.
  • File Name: XtabCustomDiffPatchResponseHandler
    • Purpose: To manage custom diff patch responses, also needing to respect cancellation tokens.
    • Current State: No modifications have been made yet.
  1. Problem Resolution:
  • Issues Encountered: Need to verify and fix cancellation token handling in specified components.
  • Solutions Implemented: None yet, as the conversation is still in the exploration phase.
  • Debugging Context: Ongoing exploration of cancellation token handling.
  • Lessons Learned: Understanding the importance of cancellation tokens in asynchronous operations.
  1. Progress Tracking:
  • Completed Tasks: None yet.
  • Partially Complete Work: Exploration of cancellation token handling is ongoing.
  • Validated Outcomes: None yet.
  1. Active Work State:
  • Current Focus: Exploring and fixing cancellation token handling in ResponseProcessor.diff and XtabCustomDiffPatchResponseHandler.
  • Recent Context: The user has requested to ensure that specific components respect cancellation tokens and to make commits for each fix.
  • Working Code: No specific code snippets have been modified or discussed yet.
  • Immediate Context: The user is focused on ensuring proper cancellation token handling in the specified components.
  1. Recent Operations:
  • Last Agent Commands: User requested exploration and fixes related to cancellation tokens.
  • Tool Results Summa...

Created from VS Code.

Copilot AI and others added 2 commits April 5, 2026 20:14
Add a CancellationToken parameter (defaulting to CancellationToken.None) to
ResponseProcessor.diff. The generator now checks the token at the beginning of
each loop iteration and returns early when cancellation is requested.

Also update the streamEdits caller in xtabProvider to:
- Pass the cancellation token through to ResponseProcessor.diff
- Check the cancellation token after the for-await loop exits, returning
  GotCancelled('duringStreaming') instead of NoSuggestions when cancelled

Co-authored-by: ulugbekna <16353531+ulugbekna@users.noreply.github.com>
Add a CancellationToken parameter (defaulting to CancellationToken.None) to
XtabCustomDiffPatchResponseHandler.handleResponse. The handler now checks the
token before processing each extracted patch and returns
NoNextEditReason.GotCancelled('duringStreaming') when cancellation is requested.

Also update the caller in xtabProvider to pass the cancellation token through.

Co-authored-by: ulugbekna <16353531+ulugbekna@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues with cancellation token in ResponseProcessor and Xtab handler fix: make ResponseProcessor.diff and XtabCustomDiffPatchResponseHandler respect cancellation token Apr 5, 2026
Copilot AI requested a review from ulugbekna April 5, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants