Skip to content

fix: add missing JSON output for AgentExecutionStopped in non-interactive mode#20454

Open
SUNDRAM07 wants to merge 2 commits intogoogle-gemini:mainfrom
SUNDRAM07:fix/agent-execution-stopped-json-output
Open

fix: add missing JSON output for AgentExecutionStopped in non-interactive mode#20454
SUNDRAM07 wants to merge 2 commits intogoogle-gemini:mainfrom
SUNDRAM07:fix/agent-execution-stopped-json-output

Conversation

@SUNDRAM07
Copy link

Description

Fixes #20453
The AgentExecutionStopped event 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.ts

  • Added else if (OutputFormat.JSON) branch to the AgentExecutionStopped event handler, using JsonFormatter to produce proper JSON output with session ID, response text, and stats
  • Added else branch with ensureTrailingNewline() for TEXT mode consistency
  • This matches the existing pattern used by the STOP_EXECUTION tool error handler

packages/cli/src/nonInteractiveCli.test.ts

  • Added test: should write JSON output when AgentExecutionStopped event is received in JSON mode
  • Added test: should emit result event when AgentExecutionStopped event is received in streaming JSON mode

Testing

  • All 47 tests pass (45 existing + 2 new)
  • New tests verify JSON and STREAM_JSON output for AgentExecutionStopped events
  • Existing TEXT mode test continues to pass unchanged

Before/After

Before (JSON mode + AgentExecutionStopped): No output — silent exit
After (JSON mode + AgentExecutionStopped): Proper JSON output with session_id, response, and stats

@SUNDRAM07 SUNDRAM07 requested a review from a team as a code owner February 26, 2026 16:21
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • JSON Output Fix: Resolved an issue where the AgentExecutionStopped event handler in non-interactive mode failed to produce JSON output, leading to silent exits when --output-format json was used.
  • Handler Logic Enhancement: Implemented a new else if (OutputFormat.JSON) branch within the AgentExecutionStopped event handler to correctly format and output session ID, response text, and stats using JsonFormatter.
  • Text Mode Consistency: Added an else branch to the event handler to ensure a trailing newline for text output, maintaining consistency with existing patterns.
  • Test Coverage Expansion: Introduced two new tests in nonInteractiveCli.test.ts to verify proper JSON and streaming JSON output when an AgentExecutionStopped event is received.
Changelog
  • packages/cli/src/nonInteractiveCli.test.ts
    • Added a test case to verify that JSON output is correctly written when an AgentExecutionStopped event is received in JSON mode.
    • Added a test case to confirm that a result event is emitted in streaming JSON mode when an AgentExecutionStopped event occurs.
  • packages/cli/src/nonInteractiveCli.ts
    • Added an else if (OutputFormat.JSON) block to the AgentExecutionStopped event handler to format output as JSON, including session ID, response, and stats.
    • Included an else block to ensure a trailing newline for non-JSON output formats.
Activity
  • No human activity has been recorded for this pull request.
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.

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

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.

@gemini-cli gemini-cli bot added the area/non-interactive Issues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation label Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/non-interactive Issues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: AgentExecutionStopped produces no output in non-interactive JSON mode

1 participant