fix(codex): surface streaming fatal errors#60
Conversation
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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()
})
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
codex_stream_errorhelper to build terminal error chunks for Responses, Chat Completions, and Anthropic Messages adapters.CodexUpstreamErrorClass.Verification
CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo test -p llm-access --jobs 4 -- --test-threads=1CARGO_TARGET_DIR=/mnt/wsl/data4tb/static-flow-data/cargo-target/static_flow cargo clippy -p llm-access --jobs 4 -- -D warnings