google-gemini/gemini-cli

Improve diagnostics and error handling for malformed streaming responses

Closed

#22351 opened on Mar 13, 2026

View on GitHub
 (3 comments) (0 reactions) (1 assignee)TypeScript (103,992 stars) (13,657 forks)batch import
area/coreeffort/mediumhelp wantedkind/bugpriority/p2status/bot-triagedstatus/need-information

Description

Summary

The core streaming pipeline currently handles some malformed or incomplete streamed responses too quietly, which makes debugging harder and can hide failures in realtime response flows.

This is especially important for streaming-heavy features, including future voice / multimodal interaction, where reliable chunk handling and clear diagnostics are foundational.

Problem

A few places in the streaming path can fail or degrade silently:

  • In packages/core/src/core/turn.ts, stream events with no response body are skipped without any diagnostic.
  • In packages/core/src/core/geminiChat.ts, invalid stream chunks can be skipped without explicit warning.
  • In packages/core/src/code_assist/server.ts, the SSE parser drops the final buffered data: chunk if the stream ends without a trailing blank line.

This makes malformed or truncated streams harder to diagnose and can hide issues during real-world usage.

Proposed Change

Improve robustness and diagnostics in the streaming path by:

  • warning when response-less stream events are skipped
  • warning when invalid chunks are skipped during stream processing
  • flushing and parsing the final buffered SSE chunk even if the stream ends without a trailing blank line
  • adding focused tests for these edge cases

Scope

  • packages/core/src/core/turn.ts
  • packages/core/src/core/geminiChat.ts
  • packages/core/src/code_assist/server.ts

Why This Matters

This improves the reliability of the existing streaming pipeline and strengthens the foundation for future low-latency / voice-style interactions.

Expected Outcome

  • malformed or incomplete chunks no longer fail silently
  • the final SSE event is preserved in more cases
  • better diagnostics for stream degradation
  • no behavior change for healthy streams

Contributor guide