Skip to content

fix(cli): propagate AbortSignal in /compress command - #28506

Closed
kunalrawat425 wants to merge 4 commits into
google-gemini:mainfrom
kunalrawat425:fix/compress-command-abort-signal
Closed

fix(cli): propagate AbortSignal in /compress command#28506
kunalrawat425 wants to merge 4 commits into
google-gemini:mainfrom
kunalrawat425:fix/compress-command-abort-signal

Conversation

@kunalrawat425

Copy link
Copy Markdown

Summary

The /compress command fired tryCompressChat without an AbortSignal, making the background compression impossible to cancel. This could leave dangling network requests when the user starts a new prompt or presses Escape.

Changes

  • Create an AbortController and pass its signal to tryCompressChat
  • Check signal.aborted after await to discard stale results
  • Swallow AbortError in catch when signal is aborted
  • Export abortActiveCompression() for external cancellation

Context

Addresses review feedback raised in #28483 (comment)

The asynchronous auto-compression task runs in the background without proper cancellation handling. Asynchronous operations that can be cancelled by the user should accept and propagate an AbortSignal to ensure cancellability and prevent dangling processes or network requests, rather than relying on checking a ref like turnCancelledRef.current after the operation has already run.

Testing

All 8 tests pass (6 existing updated + 2 new):

  • Verifies AbortSignal is passed to tryCompressChat
  • Silently bails out if aborted during compression
  • Swallows errors when aborted

The /compress command fired tryCompressChat without an AbortSignal,
making the background compression impossible to cancel. This could
leave dangling network requests when the user starts a new prompt
or presses Escape.

Changes:
- Create an AbortController and pass its signal to tryCompressChat
- Check signal.aborted after await to discard stale results
- Swallow AbortError in catch when signal is aborted
- Export abortActiveCompression() for external cancellation

Addresses review feedback from:
google-gemini#28483 (comment)
@kunalrawat425
kunalrawat425 requested a review from a team as a code owner July 22, 2026 19:30
@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 improves the reliability and responsiveness of the /compress command by implementing proper cancellation handling. By propagating an AbortSignal to the compression service, the application can now cleanly terminate background network requests when a user initiates a new action or cancels the current operation, preventing dangling processes and UI inconsistencies.

Highlights

  • AbortSignal Integration: Introduced an AbortController to the /compress command to allow for proper cancellation of background compression tasks.
  • Graceful Cancellation: Added logic to check for signal abortion after asynchronous operations and to swallow AbortErrors, ensuring the UI does not process stale results or display unnecessary error messages.
  • External API: Exported an abortActiveCompression function to allow external components to trigger cancellation of ongoing compression processes.
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.

@github-actions github-actions Bot added the size/m A medium sized PR label Jul 22, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/M

  • Lines changed: 98
  • Additions: +96
  • Deletions: -2
  • Files changed: 2

@github-actions

Copy link
Copy Markdown

You already have 7 pull requests open. Please work on getting existing PRs merged before opening more.

@github-actions github-actions Bot closed this Jul 22, 2026

@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 introduces the ability to abort in-flight chat compression operations in the CLI by integrating an AbortController into the /compress command and updating the corresponding unit tests. A review comment points out a potential race condition in the finally block where ui.setPendingItem(null) is called; if a new prompt has already set its own pending item, this will incorrectly clear it. The reviewer suggests only clearing the pending item if it matches the current command's message instance.

Comment on lines 101 to 106
} finally {
if (activeAbortController === abortController) {
activeAbortController = null;
}
ui.setPendingItem(null);
}

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.

high

There is a potential race condition here. If the compression is aborted (e.g., because the user started a new prompt or cancelled), the finally block will still execute and call ui.setPendingItem(null). If a new prompt has already set its own pending item in the meantime, this will incorrectly clear the new pending item, breaking the UI state.

To prevent this, only clear the pending item if it is still the same pendingMessage instance that was set by this command.

      } finally {
        if (activeAbortController === abortController) {
          activeAbortController = null;
        }
        if (ui.pendingItem === pendingMessage) {
          ui.setPendingItem(null);
        }
      }

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

Labels

size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant