Skip to content

fix(core): settle queued tool calls on scheduler disposal - #29432

Closed
andreivince wants to merge 5 commits into
google-gemini:mainfrom
andreivince:fix/settle-queued-tools-on-dispose
Closed

andreivince wants to merge 5 commits into
google-gemini:mainfrom
andreivince:fix/settle-queued-tools-on-dispose

Conversation

@andreivince

@andreivince andreivince commented Sep 20, 2026 •

Copy link
Copy Markdown

Summary

Reject queued tool batches when their scheduler is disposed, cancel unstarted tools, and avoid requesting approval for work that can no longer run.

Details

Queued callers receive Scheduler disposed and release their abort listeners. Remaining tools in the active batch are cancelled. Disposal is checked before execution and before entering a new confirmation flow after policy evaluation.

If a running tool returns a sandbox error after disposal, preserve its error and output without requesting extra permissions for a retry. Running tools and confirmation flows already underway retain caller-controlled cancellation.

Related Issues

Fixes #29030

How to Validate

With Node.js 20.19.6, run CI=true GEMINI_CLI_TRUST_WORKSPACE=true npm run preflight.

  • Full preflight passed: clean dependency installation, formatting, build, lint, type checking, and 15,798 tests passed with 65 skips.
  • The queued-caller and disposal regressions fail against the unchanged scheduler and pass with the fix. After merging current main, the scheduler, confirmation-bus, and tool integration suites passed 180 tests on macOS. The earlier revision also passed 185 related tests on Linux arm64.
  • Consumer checks covered disposal during policy evaluation, existing confirmations, parallel execution, sandbox failure after disposal, and ordinary sandbox approval/retry.
  • The bundled CLI passed the recorded-response interactive parallel read/write approval test and session resume test.

The merged revision was revalidated on macOS; Linux checks cover the earlier revision. Windows, live model calls, and actual Docker, Podman, or Seatbelt CLI sandbox modes were not tested. MCP execution is not counted as validated: the existing replay test reported success despite a missing-tool error, reproduced without these changes. No user-facing commands, flags, or settings changed, so no documentation update is needed.

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

@andreivince
andreivince requested a review from a team as a code owner September 20, 2026 23:59
@github-actions github-actions Bot added the size/m A medium sized PR label Sep 21, 2026
@google-cla

google-cla Bot commented Sep 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 306
  • Additions: +301
  • Deletions: -5
  • Files changed: 2

@gemini-code-assist

Copy link
Copy Markdown
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 addresses a resource management issue where queued tool calls remained pending indefinitely after the scheduler was disposed. By clearing the request queue and implementing a disposal check during the scheduling phase, the system now ensures that all callers receive timely feedback and that no unauthorized work is processed post-disposal.

Highlights

  • Scheduler Disposal Logic: Updated the scheduler's disposal process to explicitly reject all pending requests in the queue, ensuring callers are notified immediately when the scheduler is shut down.
  • New Request Validation: Added a check to the scheduling logic to prevent new work from being accepted if the scheduler has already been disposed.
  • Regression Testing: Introduced comprehensive tests to verify that queued batches are correctly rejected, abort listeners are cleaned up, and no further execution occurs after disposal.
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 the 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 counterproductive. 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-code-assist gemini-code-assist Bot 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.

Code Review

This pull request enhances the Scheduler class by ensuring that queued requests are rejected and new batches are blocked when the scheduler is disposed, accompanied by comprehensive unit tests validating these cleanup behaviors. The feedback highlights an improvement opportunity: while the changes successfully prevent new batches from starting, they do not stop an active batch from executing its remaining queued tool calls if dispose() is called mid-batch. It is recommended to update _processNextItem to check the disposal signal and immediately terminate the active processing loop.

Comment thread packages/core/src/scheduler/scheduler.ts
@gemini-cli gemini-cli Bot added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Sep 21, 2026
@gemini-cli

gemini-cli Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'.

This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

@andreivince

Copy link
Copy Markdown
Author

fix for #29030 here. review feedback is addressed in 59886f3. still needs the help wanted label to survive the stale bot — asked on the issue, no response so far.

@gemini-cli

gemini-cli Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding.

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

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality size/l A large sized PR size/m A medium sized PR status/pr-nudge-sent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: CoreToolScheduler.dispose() leaves queued schedule() callers pending forever with leaked abort listeners

1 participant