[Headless stream-json] Terminal turn fails with SSE EOF after `finish` tool call on large context (>200K tokens), causing false ERROR status despite valid structured_output

Environment

  • Platform: Windows 11 (x64)
  • Tool / Component: Antigravity CLI (agy.exe, v0.154+ / latest build)
  • Execution Mode: Headless print mode (--input-format stream-json --output-format stream-json --json-schema <path>)
  • Selected Model: Gemini 3.8 Flash (High)
  • Backend Service: https://daily-cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse

Summary & Impact

In autonomous long-running agent tasks (e.g. 269 steps across 19 modified files and comprehensive Maven test execution, accumulating >230K prompt tokens):

  1. The agent successfully completes the task and calls the built-in finish tool at step 268, providing valid parameters strictly adhering to the specified JSON schema (125 tests passed, exitCode 0).
  2. The runtime engine executes the tool and returns: "Task is complete. Summarize what you did and do not call any more tools."
  3. AGY CLI then sends a subsequent streamGenerateContent?alt=sse request to obtain the final conversational summary.
  4. Due to the high token count (~231K tokens) and payload size, the upstream SSE streaming connection abruptly drops after ~4.7s with:
    API error (attempt 1): request failed: Post "https://daily-cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse": EOF
    (or "The stream was interrupted. Please continue the task you were working on.")
  5. The Critical Defect: AGY CLI’s execution loop treats this non-essential final conversational turn failure as a fatal error, overriding the entire session’s result.status to "ERROR". It completely ignores that the finish tool call succeeded and valid structured_output was already generated and persisted. Downstream callers parsing --output-format stream-json are forced to mark successful tasks as FAILED.

Trace IDs & Production Evidence for Google Backend Engineers

Incident 1 (Terminal Hard EOF):

  • Conversation ID: 28c4dafa-4d17-411e-8ed2-**
  • Failing Request Timestamp: 2026-09-20 23:44:45.486 CST (15:44:45.486 UTC)
  • Trace ID: 0x4f780ad9c***
  • ResponseID: af-vaqOMGYrM0-***
  • Context Size at Crash: 230,982 input tokens (cumulative turn tokens > 2.03M, cache read tokens > 14.1M)
  • Step Sequence: Step 268 (finish tool called) → Step 269 (tool response received) → Step 270 (streamGenerateContent failed with EOF after 4.768s)

Incident 2 (Stream Interrupted):

  • Conversation ID: 5424b0a7-802b-404b-8739-***
  • Failing Request Timestamp: 2026-09-20 23:29:45.578 CST (15:29:45.578 UTC)
  • Trace ID: 0x3849660ea***
  • ResponseID: 5vuvar2YKOP82**
  • Step Sequence: Step 128 (finish tool called) → Step 129 (tool response received) → Result emitted with "error": "The stream was interrupted. Please continue the task you were working on."

Root Cause Analysis

1. Mismatch Between Nominal Model Window and Streaming Gateway Stability

  • The Gemini model nominal context window is 1,048,576 tokens.
  • Internal compaction rules (CompactionConfig / checkpointNeeded) only evaluate threshold triggers at high utilization (typically ~70-80% of nominal window).
  • At 230K tokens (~22% utilization), automatic compaction is never triggered because AGY believes there is ample headroom.
  • However, the HTTP/2 SSE streaming gateway (daily-cloudcode-pa.googleapis.com) cannot sustain reliable connections when TTFT and prompt context reach hundreds of thousands of tokens, dropping the TCP/SSE stream prematurely.

Hi @Zanec ,

Thank you for taking the time to share this detailed root-cause analysis along with the production trace IDs.

We have shared your report and trace details with our engineering team to address how headless --output-format stream-json (--json-schema) execution handles upstream SSE EOF interruptions on the post-finish summary turn, ensuring that a completed finish tool call with valid structured_output is not overridden by a terminal ERROR status.

Additionally, since your environment notes v0.154+, we recommend updating Antigravity CLI (agy) to the latest v1.2.6 release from Google Antigravity - Download to ensure you have our latest headless execution and streaming stability improvements.

Please let us know how it goes after updating and if you still observe this behavior on the latest release.