Skip to content

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

@SUNDRAM07

Description

@SUNDRAM07

What happened?

When running Gemini CLI in non-interactive mode with --output-format json, if an AgentExecutionStopped event occurs (triggered by hooks, policies, or the agent framework), no JSON output is produced. The CLI exits silently with zero output to stdout.
This affects any consumer parsing JSON output from gemini -p "..." --output-format json — they receive nothing when the agent is stopped.

Root Cause

In packages/cli/src/nonInteractiveCli.ts, the AgentExecutionStopped event handler (line ~367-386) handles:

  • TEXT mode: writes stop message to stderr
  • STREAM_JSON mode: emits a RESULT event via streamFormatter
  • JSON mode: missing — returns silently with no output
    The identical handler for STOP_EXECUTION tool errors (line ~464-492) correctly handles all three output formats, confirming this is an oversight rather than intentional behavior.

What did you expect to happen?

When --output-format json is used and AgentExecutionStopped occurs, the CLI should produce valid JSON output containing the session ID, any partial response text, and session stats — the same behavior as the STOP_EXECUTION tool handler.

Client information

Verified on latest main branch (commit 3db35812b).

Anything else we need to know?

The existing test at nonInteractiveCli.test.ts only covers TEXT mode for this event. There are no tests for JSON or STREAM_JSON output when AgentExecutionStopped is received.
For comparison, the STOP_EXECUTION tool error path has dedicated tests for all three formats:

  • should stop agent execution immediately when a tool call returns STOP_EXECUTION error (TEXT)
  • should write JSON output when a tool call returns STOP_EXECUTION error (JSON)
  • should emit result event when a tool call returns STOP_EXECUTION error in streaming JSON mode (STREAM_JSON)

Metadata

Metadata

Labels

area/non-interactiveIssues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automationstatus/need-triageIssues that need to be triaged by the triage automation.type/bug

Type

No fields configured for Bug.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions