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)
What happened?
When running Gemini CLI in non-interactive mode with
--output-format json, if anAgentExecutionStoppedevent 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, theAgentExecutionStoppedevent handler (line ~367-386) handles:RESULTevent viastreamFormatterThe identical handler for
STOP_EXECUTIONtool 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 jsonis used andAgentExecutionStoppedoccurs, the CLI should produce valid JSON output containing the session ID, any partial response text, and session stats — the same behavior as theSTOP_EXECUTIONtool handler.Client information
Verified on latest
mainbranch (commit3db35812b).Anything else we need to know?
The existing test at
nonInteractiveCli.test.tsonly covers TEXT mode for this event. There are no tests for JSON or STREAM_JSON output whenAgentExecutionStoppedis received.For comparison, the
STOP_EXECUTIONtool 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)