Skip to content

fix(codex): surface streaming fatal errors#60

Merged
acking-you merged 2 commits into
masterfrom
fix/codex-streaming-fatal-errors
Jun 30, 2026
Merged

fix(codex): surface streaming fatal errors#60
acking-you merged 2 commits into
masterfrom
fix/codex-streaming-fatal-errors

Conversation

@acking-you

Copy link
Copy Markdown
Owner

Summary

Fix Codex streaming requests that encounter a classified fatal upstream error after the HTTP/SSE response has already started. Instead of silently ending the body and leaving clients waiting for a terminal signal, the gateway now emits a protocol-shaped streaming error.

Root cause

The post-write Codex SSE failure branch recorded the upstream failure server-side and then returned without forwarding an error frame or [DONE]. Chat-completion clients could experience this as an empty or hanging stream even though the usage event recorded the failure.

What changed

  • Added a small codex_stream_error helper to build terminal error chunks for Responses, Chat Completions, and Anthropic Messages adapters.
  • Reused the classified Codex surface error code mapping from CodexUpstreamErrorClass.
  • Updated the post-write stream failure branch to emit the error chunks while preserving usage recording and strict-session rejection caching.
  • Covered mid-stream fatal errors and preflight-buffer-cap overflow behavior with regression tests.

Verification

  • CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo test -p llm-access --jobs 4 -- --test-threads=1
  • CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo clippy -p llm-access --jobs 4 -- -D warnings

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the handling of mid-stream failures in Codex upstream responses. Instead of abruptly stopping the stream, it now formats and yields error chunks along with a terminal sentinel (such as [DONE]) tailored to the active response adapter. Additionally, error code mapping has been refactored directly into CodexUpstreamErrorClass. The review feedback suggests logging serialization errors in the new codex_stream_error.rs module rather than silently suppressing them with an empty JSON object.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

}

fn encode_json(value: &Value) -> String {
serde_json::to_string(value).unwrap_or_else(|_| "{}".to_string())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While serializing the JSON payload for an SSE event, any potential error is currently suppressed, and an empty JSON object {} is returned. This could hide underlying issues with payload construction.

It would be more robust to log the serialization error to aid in debugging, even if it's considered an unlikely event.

You can achieve this by using tracing::error!. You'll also need to add use tracing; at the top of the file.

    serde_json::to_string(value).unwrap_or_else(|e| {
        tracing::error!(error = %e, "failed to serialize stream error payload");
        "{}".to_string()
    })

@acking-you acking-you merged commit 4befb1a into master Jun 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant