Skip to content

[Refactor] Decouple Tool-Specific Cancellation Logic from SchedulerStateManager#23699

Open
akash-manna-sky wants to merge 2 commits intogoogle-gemini:mainfrom
akash-manna-sky:issue-16716
Open

[Refactor] Decouple Tool-Specific Cancellation Logic from SchedulerStateManager#23699
akash-manna-sky wants to merge 2 commits intogoogle-gemini:mainfrom
akash-manna-sky:issue-16716

Conversation

@akash-manna-sky
Copy link

[Refactor] Decouple Tool-Specific Cancellation Logic from SchedulerStateManager

Summary

Details

Related Issues

Fixes #16716

How to Validate

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@akash-manna-sky akash-manna-sky marked this pull request as ready for review March 24, 2026 19:36
@akash-manna-sky akash-manna-sky requested review from a team as code owners March 24, 2026 19:36
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the core scheduling mechanism by decoupling tool-specific cancellation logic from the SchedulerStateManager. The change centralizes the responsibility of defining cancellation outcomes within the tools themselves, leading to a more maintainable and extensible architecture. This improves how cancelled tool operations communicate their final state.

Highlights

  • Decoupled Cancellation Logic: The SchedulerStateManager no longer contains tool-specific logic for generating cancellation results. Instead, tools now provide a cancelResult directly within their confirmation details, promoting better modularity.
  • Enhanced Confirmation Details: A new optional cancelResult field of type ToolResultDisplay has been added to various SerializableConfirmationDetails types, allowing tools to specify how their cancellation should be displayed.
  • Updated WriteFileTool: The WriteFileTool has been updated to populate the new cancelResult field with relevant file diff information when its operation is cancelled.
  • Comprehensive Testing: New and updated unit tests have been added to SchedulerStateManager and WriteFileTool to ensure the correct propagation and usage of the cancelResult across different tool types.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Mar 24, 2026
@akash-manna-sky
Copy link
Author

Hello @abhipatel12, can you please review the changes?

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the handling of cancelResult for tool calls, moving the responsibility of providing cancellation details from the SchedulerStateManager to individual tools. The cancelResult field has been added to various SerializableConfirmationDetails types and ToolEditConfirmationDetails, and the WriteFileTool is updated to populate this field. The SchedulerStateManager now directly uses the cancelResult provided by the tool. New tests were added to verify this behavior. The review feedback indicates that the diffStat is missing from the cancelResult provided by the WriteFileTool, which is a regression, and suggests adding assertions for diffStat in the new test cases for WriteFileTool to ensure full data contract coverage.

Comment on lines +260 to +266
cancelResult: {
fileDiff,
fileName,
filePath: this.resolvedPath,
originalContent,
newContent: correctedContent,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This refactoring correctly moves the responsibility of creating the cancelResult to the tool. However, it seems to have missed including the diffStat in the cancelResult for file edits. The previous logic in SchedulerStateManager derived these stats, and other parts of the system (like the UI and tests) may rely on them being present.

To fix this regression, please calculate and include the diffStat in the cancelResult.

      cancelResult: {
        fileDiff,
        fileName,
        filePath: this.resolvedPath,
        originalContent,
        newContent: correctedContent,
        diffStat: getDiffStat(
          fileName,
          originalContent,
          correctedContent,
          correctedContent,
        ),
      },

Comment on lines +664 to +672
expect(confirmation.cancelResult).toEqual(
expect.objectContaining({
fileDiff: expect.any(String),
fileName: 'cancel_result_file.txt',
filePath,
originalContent,
newContent: correctedContent,
}),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This test is a great addition to verify that cancelResult is populated. To make it more robust and ensure it covers the full data contract, please also assert that cancelResult.diffStat is populated correctly. The state-manager.test.ts file includes a similar check, which confirms that diffStat is an expected part of the result.

        expect(confirmation.cancelResult).toEqual(
          expect.objectContaining({
            fileDiff: expect.any(String),
            fileName: 'cancel_result_file.txt',
            filePath,
            originalContent,
            newContent: correctedContent,
            diffStat: expect.objectContaining({
              model_added_lines: expect.any(Number),
              model_removed_lines: expect.any(Number),
            }),
          }),
        );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] Decouple Tool-Specific Cancellation Logic from SchedulerStateManager

1 participant