Repository navigation
fix(cli): propagate cancellation into shell command injections - #29459
FanouZeng-TT wants to merge 2 commits into
Conversation
ShellProcessor executed every !{...} injection with a fresh AbortController
signal, so nothing could ever abort a command: the caller's cancellation never
reached the subprocess, and no injection had a budget of its own. A custom
command containing a hung command therefore blocked the whole prompt pipeline
with no way out, even though the processor already handles `aborted` results.
Injunctions now run under the caller's signal (threaded through a new optional
`CommandContext.signal`, wired from the non-interactive abort controller) combined
with a per-command timeout, so cancelling or exceeding the ceiling terminates the
command and the pipeline continues with the existing aborted marker.
|
📊 PR Size: size/M
|
Summary of ChangesHello, 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 an issue where shell command injections (e.g., Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces command cancellation and execution timeouts for shell command injections by propagating an AbortSignal from the CLI command context to the shell execution processor. Feedback on the changes highlights compatibility issues with AbortSignal.any in older Node.js 20.x versions, as well as potential memory and timer leaks from AbortSignal.timeout. It is recommended to refactor the signal creation using standard setTimeout with proper cleanup, and to update the corresponding unit tests to use Vitest's fake timers.
|
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. |
|
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. |
Summary
!{...}shell injections inside custom commands were executed with a brand-newAbortController().signal, so nothing could ever abort them: the caller's cancellation never reached the subprocess, and no injection had a budget of its own. A custom command containing a hung command (for example!{sleep 600}) therefore blocked the whole prompt pipeline with no way out — even thoughShellProcessoralready handlesabortedresults and appends[Shell command '…' aborted], which is what a cancelled command was always meant to produce.Details
Each injection now runs under the caller's signal combined with a per-command ceiling (
AbortSignal.any([timeout, caller]), the pattern already used elsewhere in this repo, e.g.gitUtils.ts):The caller's signal is threaded through a new optional
CommandContext.signal, wired from the non-interactive abort controller innonInteractiveCliCommands.ts.IPromptProcessor.processis unchanged, so there is no cross-package interface change.Two deliberate choices worth your review: the
60_000ceiling matches the existingCOMMAND_TIMEOUT_MSused by core's auth value resolver, and a pipeline with no per-command budget is precisely what made the hang unrecoverable — but it is a new bound on injections, so say the word if you would rather keep this PR to signal propagation only, or make the ceiling configurable. The interactive path has no signal to hand yet, so there the ceiling is the only escape; wiring the interactive abort signal through toCommandContextis a natural follow-up and is left out here to keep the change small.Related Issues
Fixes #29314
How to Validate
Red before the source change (only the new tests added):
Green after:
Regression surfaces:
src/ui/hooks/slashCommandProcessor.test.tsx,src/nonInteractiveCli.test.ts,src/ui/commands,src/services→ 690 passed;src/services/FileCommandLoader.test.ts+src/services/prompt-processors→ 118 passed. Manual: a custom command containing!{sleep 600}no longer holds the prompt pipeline open — cancelling (headless) or exceeding the ceiling terminates the command and processing continues with the aborted marker.Pre-Merge Checklist
🤖 Generated with Claude Code