fix(codex): retry empty buffered completions - #71
Merged
Conversation
Buffered Codex transports translated successful terminal events with no semantic output into empty HTTP 200 end_turn responses. Retry these responses instead so callers receive a usable completion or an explicit failure. Use reducer events to distinguish output text, thinking, tool calls, and web searches from terminal-only bodies. Message item framing without a text delta remains empty because the accumulator omits such blocks. Drop previous_response_id before each retry so WebSocket requests resend full context. Bound retries to ten after the initial attempt and return 503 after exhaustion. Abort continuation and pending compaction state when processing fails. Tests remove retry delays and cover buffered streaming, non-streaming, exhaustion, and empty message scaffolding. This changes empty successful completions from HTTP 200 end_turn responses to bounded retries and a 503.
raine
force-pushed
the
agent/retry-empty-buffered-completion
branch
from
July 28, 2026 14:12
7b932b4 to
1d9d216
Compare
dmitryanchikov
added a commit
to dmitryanchikov/claude-code-proxy
that referenced
this pull request
Aug 26, 2026
…_result tail as a valid end_turn When a conversation ends assistant:tool_use -> user:tool_result and the tool call itself delivered the user-visible answer (a messaging/reply tool), the model legitimately ends the follow-up turn with zero output items. The empty-completion protection (raine#70/raine#71) treated this as a failure: ~11 retries, ~3 minutes, then 503 'Codex completed without producing output' — and the Anthropic client retries on top. For a channel bot whose reply tool IS the answer, ~68% of real turns failed this way (measured 2026-08-25); a 3-message repro is deterministic: 503 @ 175s before, 200 @ 1.7s after. Scope is deliberately narrow, in both dimensions: - The tail predicate runs on the ORIGINAL Anthropic body and requires a tool_result WITHOUT is_error — an error result demands a model reaction, so a deterministic empty there stays a loud failure. - A qualifying tail alone is not proof: an internal tool (Read/Bash) has the same tail shape and can meet a transient upstream glitch. One retry is the discriminator — a glitch clears on resend, a semantic empty repeats — so the empty is accepted only on the SECOND consecutive occurrence, on both the buffered and live-stream paths (shared accept_empty_completion()). Empty completions without a qualifying tail keep the full retry-then-503 behavior unchanged. Tests: tail predicate (success/error/non-tool/ordering/empty), the accept truth table, and live-path behavioral pair (no flag -> Retry with the empty-completion detail; flag -> delivered stream ending in message_stop).
bp0lr
pushed a commit
to bp0lr/claude-code-proxy
that referenced
this pull request
Aug 29, 2026
Buffered Codex transports translated successful terminal events with no semantic output into empty HTTP 200 end_turn responses. Retry these responses instead so callers receive a usable completion or an explicit failure. Use reducer events to distinguish output text, thinking, tool calls, and web searches from terminal-only bodies. Message item framing without a text delta remains empty because the accumulator omits such blocks. Drop previous_response_id before each retry so WebSocket requests resend full context. Bound retries to ten after the initial attempt and return 503 after exhaustion. Abort continuation and pending compaction state when processing fails. Tests remove retry delays and cover buffered streaming, non-streaming, exhaustion, and empty message scaffolding. This changes empty successful completions from HTTP 200 end_turn responses to bounded retries and a 503. Co-authored-by: Hunter Moore <hmoore@silvey.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
response.completed/response.done) with no semantic output, using the existing reducer (text, thinking, tool, and web-search events all count as semantic)previous_response_iddropped so the resend carries full context, bounded at 1 + 10 attemptsCodex completed without producing output) after exhaustion instead of a successful emptyend_turnresponse.incompletestays non-retryable (a max-tokens truncation would not improve on resend)Failure mode
The buffered transport path —
CCP_CODEX_TRANSPORT=http, and non-streaming client requests generally — translated a terminal-only upstream body into HTTP 200 with"content": []andstop_reason: "end_turn". Same class of failure as the live-stream path fixed in #70, on the other transport.TDD evidence
RED (all three smoke tests before the fix):
GREEN:
The detection helper was also grown test-first: six unit tests (terminal-only completed/done → empty; text / tool-call / incomplete-only / no-terminal → not empty) written against a stub and watched fail before implementation.
Relationship to #70
Independent branch from
main; complementary to #70 (live WebSocket path). Two hunks are intentionally identical to #70 so a later merge dedupes trivially: theEMPTY_CODEX_COMPLETION_DETAIL503 mapping branch, and the zero-delay retry test hook inretry.rs(same*_for_testspattern as the websocket pool/continuation helpers).Verification
cargo fmt --all -- --checkcargo test— 604 passed, 0 failed across unit and integration suites🤖 Generated with Claude Code