Repository navigation
fix(cli): report error status and exit code in stream-json tool_result for failed shell commands - #30521
Conversation
|
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. |
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 failures were incorrectly reported as successful in the headless stream-json output format. By checking for the 'isError' flag and exit code metadata, the CLI now accurately reflects the failure status and provides descriptive error messages for downstream consumers. 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
|
|
📊 PR Size: size/M
|
There was a problem hiding this comment.
Code Review
This pull request updates the non-interactive CLI and agent session handlers to correctly detect and report errors when a shell tool execution fails with a non-zero exit code (indicated by isError and exitCode in the tool's response data). It ensures that the JSON stream formatter emits an error status and includes a descriptive error message containing the exit code. A corresponding unit test has been added to verify this behavior. I have no feedback to provide.
|
@googlebot I signed it! |
…t for failed shell commands
dd448ac to
8cd65b7
Compare
Summary
When
run_shell_commandexits with a non-zero exit code in headless--output-format stream-jsonmode,gemini-clicurrently emitstool_resultwith"status": "success"and omits both the error object and the non-zero exit code.This PR updates both non-interactive CLI entry points (
nonInteractiveCli.tsandnonInteractiveCliAgentSession.ts) so that whentoolResponse.data.isError === true(as set byShellToolInvocationon non-zero exit codes), the emittedstream-jsontool_resultevent accurately reports"status": "error"and includes anerrorpayload with the exit code (e.g.,Command exited with code 42).Details
Root Cause
packages/core/src/tools/shell.ts(ShellToolInvocation.execute), when a shell command terminates with a non-zero exit code, the tool returns structured metadatadata: { exitCode, isError: true }while keepingresultDisplayas the command's stdout/stderr output and leavingtoolResponse.errorunset (socompletedToolCall.statusstays'success').packages/cli/src/nonInteractiveCli.tsandpackages/cli/src/nonInteractiveCliAgentSession.ts,streamFormatter.emitEventpreviously checked onlycompletedToolCall.status === 'error'/event.isErrorandtoolResponse.error.--output-format stream-jsonsaw:{"type":"tool_result","tool_id":"run_shell_command-...","status":"success","output":"..."}42(or1,127, etc.) and had no stderr.Fix
data?.['isError'] === truein addition tocompletedToolCall.status === 'error'/event.isErrorwhen computingstatusforJsonStreamEventType.TOOL_RESULT.data.isError === trueandtoolResponse.erroris absent, populateerror: { type: errorType || 'TOOL_EXECUTION_ERROR', message: exitCode !== undefined ? 'Command exited with code <N>' : 'Tool execution failed' }.isError: false) and hard tool execution errors wheretoolResponse.erroris already set.packages/cli/src/nonInteractiveCli.test.tsverifying non-zero shell exit codes emitstatus: 'error'anderror.message: 'Command exited with code 42'.Related Issues
Fixes #30553
Related: #30542 (timeout) and #30543 (signal termination) cover other shell failure modes and are not fixed here.
How to Validate
should emit error status and exit code in stream-json tool_result when toolResponse.data.isError is true).Pre-Merge Checklist