fix: add missing JSON output for AgentExecutionStopped in non-interactive mode#20454
fix: add missing JSON output for AgentExecutionStopped in non-interactive mode#20454SUNDRAM07 wants to merge 2 commits intogoogle-gemini:mainfrom
Conversation
Summary of ChangesHello @SUNDRAM07, 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 critical bug in the non-interactive CLI where agent execution stopping events (AgentExecutionStopped) would result in a silent exit when JSON output format was requested. The changes ensure that when an agent stops, the CLI now correctly outputs a structured JSON response containing session details, partial content, and metrics, thereby preventing silent failures and providing clear feedback to users. Highlights
Changelog
Activity
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 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 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
|
There was a problem hiding this comment.
Code Review
The pull request correctly identifies and fixes a bug where non-interactive mode with JSON output would fail silently for AgentExecutionStopped events. The addition of an else if branch for OutputFormat.JSON is the right approach. The new tests are also good as they cover both JSON and streaming JSON formats. However, in both cases, the implementation misses the opportunity to include the reason for the agent's stoppage in the machine-readable output. I've added comments with suggestions on how to include this valuable information in the JSON and streaming JSON outputs by utilizing the existing error field in the respective schemas.
Description
Fixes #20453
The
AgentExecutionStoppedevent handler in non-interactive mode was missing JSON output format handling. When using--output-format json, the CLI would exit silently with no output when the agent was stopped by hooks or policies.Changes
packages/cli/src/nonInteractiveCli.tselse if (OutputFormat.JSON)branch to theAgentExecutionStoppedevent handler, usingJsonFormatterto produce proper JSON output with session ID, response text, and statselsebranch withensureTrailingNewline()for TEXT mode consistencySTOP_EXECUTIONtool error handlerpackages/cli/src/nonInteractiveCli.test.tsshould write JSON output when AgentExecutionStopped event is received in JSON modeshould emit result event when AgentExecutionStopped event is received in streaming JSON modeTesting
AgentExecutionStoppedeventsBefore/After
Before (JSON mode + AgentExecutionStopped): No output — silent exit
After (JSON mode + AgentExecutionStopped): Proper JSON output with session_id, response, and stats