Skip to content

fix(core): wire abort signal through chat compression LLM calls#20407

Open
Shiv-aurora wants to merge 4 commits intogoogle-gemini:mainfrom
Shiv-aurora:main
Open

fix(core): wire abort signal through chat compression LLM calls#20407
Shiv-aurora wants to merge 4 commits intogoogle-gemini:mainfrom
Shiv-aurora:main

Conversation

@Shiv-aurora
Copy link

Summary

Wire the parent abort signal through chat compression LLM calls so Ctrl+C actually cancels in-flight compression requests.

Details

The compression service's two LLM calls (summarization + verification) created throwaway AbortController signals that could never be aborted. This meant user cancellation didn't stop compression requests, wasting API tokens and blocking cancellation.

Changes:

  • Pass combinedSignal from executeTurn through tryCompressChat into the compression service in local-executor.ts
  • Pass signal from processTurn through tryCompressChat in client.ts
  • Make abortSignal required in compress() to prevent future regressions
  • The /compress command (no parent signal) gets a no-op fallback in GeminiClient.tryCompressChat
  • Remove the TODO(joshualitt) that called for this fix
  • Update all test call sites

Related Issues

Fixes #20405

How to Validate

  1. Start a long conversation to trigger compression
  2. Press Ctrl+C during compression -- it should cancel immediately
  3. Run /compress manually -- should still work (no-op fallback signal)
  4. npm test -- packages/core/src/services/chatCompressionService.test.ts passes

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

The compression service's two LLM calls (summarization + verification)
were using throwaway AbortController signals that could never be
aborted. This meant Ctrl+C / user cancellation didn't stop in-flight
compression requests, wasting API tokens and blocking cancellation.

Wire the parent abort signal from processTurn and executeTurn through
tryCompressChat into the compression service. Make the abortSignal
parameter required in compress() to prevent future regressions. The
/compress command (which has no parent signal) gets a no-op fallback
in GeminiClient.tryCompressChat.

Resolves TODO(joshualitt) in chatCompressionService.ts.
@Shiv-aurora Shiv-aurora requested a review from a team as a code owner February 26, 2026 08:37
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Shiv-aurora, 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 significantly enhances the responsiveness and resource efficiency of the chat compression feature. Previously, LLM calls made during chat compression were not cancellable, leading to wasted API tokens and a poor user experience when attempting to interrupt ongoing operations. The changes ensure that user-initiated cancellation signals are properly propagated to these LLM calls, allowing for immediate termination of compression requests and preventing unnecessary resource consumption.

Highlights

  • Abort Signal Propagation: The parent abort signal is now correctly wired through chat compression LLM calls, allowing user cancellation (e.g., Ctrl+C) to immediately stop in-flight compression requests.
  • API Token Efficiency: By enabling cancellation, the system avoids wasting API tokens on compression requests that are no longer needed due to user intervention.
  • Improved User Experience: User cancellation now functions as expected during chat compression, preventing the application from being blocked while waiting for unneeded LLM responses.
  • Robustness for Compression Service: The compress() method in ChatCompressionService now explicitly requires an AbortSignal, preventing future regressions where cancellation might be overlooked.
  • Fallback for Manual Compression: A no-op AbortSignal is provided for the /compress command, ensuring it continues to function correctly without a parent signal.
Changelog
  • packages/core/src/agents/local-executor.ts
    • Updated the tryCompressChat method signature to accept an AbortSignal.
    • Passed the combinedSignal to the tryCompressChat call within executeTurn.
  • packages/core/src/core/client.ts
    • Modified the tryCompressChat method to accept an optional AbortSignal.
    • Implemented a fallback mechanism to use a provided AbortSignal or create a new no-op signal for callers without one (e.g., the /compress command).
    • Passed the signal to the compressionService.compress call.
  • packages/core/src/services/chatCompressionService.test.ts
    • Introduced a mockAbortSignal for testing purposes.
    • Updated all test calls to the compressionService.compress method to include the mockAbortSignal.
  • packages/core/src/services/chatCompressionService.ts
    • Changed the compress method signature to make abortSignal a required parameter.
    • Removed the TODO(joshualitt) comment related to wiring up an abort signal.
    • Directly utilized the provided abortSignal for LLM generateContent calls, removing the previous fallback to a new AbortController().signal.
Activity
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@google-cla
Copy link

google-cla bot commented Feb 26, 2026

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.

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 correctly wires the parent abort signal through the chat compression service's LLM calls, preventing orphaned in-flight compression requests and improving responsiveness. The implementation is solid, making abortSignal a required parameter in chatCompressionService.compress() to prevent regressions and gracefully handling manual /compress calls, with updated test files. A security audit of packages/core/src/agents/local-executor.ts, packages/core/src/core/client.ts, and packages/core/src/services/chatCompressionService.ts found no vulnerabilities.

@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Feb 26, 2026
The compression service's two LLM calls (summarization + verification)
were using throwaway AbortController signals that could never be
aborted. This meant Ctrl+C / user cancellation didn't stop in-flight
compression requests, wasting API tokens and blocking cancellation.

Wire the parent abort signal from processTurn and executeTurn through
tryCompressChat into the compression service. Make the abortSignal
parameter required in compress() to prevent future regressions. The
/compress command (which has no parent signal) gets a no-op fallback
in GeminiClient.tryCompressChat.

Resolves TODO(joshualitt) in chatCompressionService.ts.
@Shiv-aurora Shiv-aurora reopened this Feb 26, 2026
@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Feb 26, 2026
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 help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Ctrl+C doesn't cancel in-flight chat compression requests

1 participant