Repository navigation
fix(codex): retry terminal-only live completions - #70
Merged
Merged
Conversation
HM-Silvey
approved these changes
Jul 20, 2026
Aotricx
marked this pull request as ready for review
July 20, 2026 15:12
Contributor
Author
|
Reviewed the full diff (all three commits) plus an independent second-model pass. Approving. Correctness — verified in code:
Test evidence (ran locally on this branch):
Noted, non-blocking:
|
Add a smoke test where the upstream answers every attempt with a terminal-only completion: the proxy must stop after the initial attempt plus MAX_RETRYABLE_LIVE_STREAM_RETRIES full-context retries and surface the explicit 503 instead of an empty end_turn. A zero-delay test hook in retry::sleep (same pattern as the existing *_for_tests helpers) keeps the exhaustion run instant; a Drop guard restores real backoff even on panic. Also document the pending_chunk single-flush invariant.
Live stream translation writes traffic artifacts while initial Anthropic framing is still buffered. Empty completion retries discard those bytes, but the capture previously presented them as events delivered to the client. Translate the buffered prefix without a live capture sink, then parse and record its Anthropic SSE events only when the prefix is committed downstream. Later stream events continue to use direct capture. Extend the retry smoke test to prove discarded end-turn framing stays out of downstream artifacts. Client-visible streaming and retry behavior is unchanged.
Owner
|
Thanks |
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
* fix(codex): retry empty live completions * test(codex): preserve signature-only live output * test(codex): prove bounded 503 on repeated empty completions Add a smoke test where the upstream answers every attempt with a terminal-only completion: the proxy must stop after the initial attempt plus MAX_RETRYABLE_LIVE_STREAM_RETRIES full-context retries and surface the explicit 503 instead of an empty end_turn. A zero-delay test hook in retry::sleep (same pattern as the existing *_for_tests helpers) keeps the exhaustion run instant; a Drop guard restores real backoff even on panic. Also document the pending_chunk single-flush invariant. * codex: capture only committed live events Live stream translation writes traffic artifacts while initial Anthropic framing is still buffered. Empty completion retries discard those bytes, but the capture previously presented them as events delivered to the client. Translate the buffered prefix without a live capture sink, then parse and record its Anthropic SSE events only when the prefix is committed downstream. Later stream events continue to use direct capture. Extend the retry smoke test to prove discarded end-turn framing stays out of downstream artifacts. Client-visible streaming and retry behavior is unchanged. --------- Co-authored-by: Hunter Moore <[email protected]> Co-authored-by: Raine Virta <[email protected]>
rikbrown
pushed a commit
to rikbrown/claude-code-proxy
that referenced
this pull request
Sep 28, 2026
Claude Code tells a subagent to call SubagentHandback last and then stop. A Codex model obeys with an empty final_answer message, which the proxy classified as empty_codex_completion: ten full-context retries, the same empty reply each time, and a 503 that made Claude Code mark the subagent as failed after its report was delivered. Decide the exemption from the translated request before compaction and context replay: the last input is a function_call_output whose call_id answers a function_call named SubagentHandback. Both the live stream and the buffered path then translate the empty completion into a normal end_turn response, with continuation and compaction state updated as on any successful terminal, and log empty_completion_after_handback. Every other empty completion keeps the retry and 503 from raine#70 and raine#71. Co-Authored-By: Claude Fable 5.1 <[email protected]>
srnnkls
added a commit
to srnnkls/claude-code-proxy
that referenced
this pull request
Sep 30, 2026
…back Claude Code tells a subagent to stop after it calls SubagentHandback, so the turn answering that tool result is legitimately empty. The empty-completion retries from raine#70/raine#71 treated it as a dropped response: ten full-context retries, then a 503 on every subagent that had already delivered its report. A request whose last user turn answers a SubagentHandback call now passes an empty completion through as an end_turn on both the live and the buffered path. Every other request keeps the bounded retry and the 503.
rikbrown
pushed a commit
to rikbrown/claude-code-proxy
that referenced
this pull request
Oct 27, 2026
Claude Code tells a subagent to call SubagentHandback last and then stop. A Codex model obeys with an empty final_answer message, which the proxy classified as empty_codex_completion: ten full-context retries, the same empty reply each time, and a 503 that made Claude Code mark the subagent as failed after its report was delivered. Decide the exemption from the translated request before compaction and context replay: the last input is a function_call_output whose call_id answers a function_call named SubagentHandback. Both the live stream and the buffered path then translate the empty completion into a normal end_turn response, with continuation and compaction state updated as on any successful terminal, and log empty_completion_after_handback. Every other empty completion keeps the retry and 503 from raine#70 and raine#71. Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.doneevents as retryable empty completionsprevious_response_idso retries send full contextend_turn*_for_testspattern as the websocket pool/continuation helpers)Scope: this covers the WebSocket live-stream path (
CCP_CODEX_TRANSPORT=websocket, the default). The buffered HTTP transport translates a terminal-only completion through the reducer and would still return an empty 200; left untouched here since the failure was only ever observed on the live path.Failure mode
A live Codex request could end with only
response.completed. The proxy translated that into HTTP 200 SSE containingmessage_startwithcontent: [], followed byend_turn. Claude Code then exited mid-turn; its resume repair inserted the syntheticNo response requested.message, making the failure look like model nonsense.The new smoke fixture reproduces that exact empty response before the fix and proves a full-context retry afterward.
TDD evidence
RED:
GREEN:
Assertions cover retry text, three upstream attempts, prior-response use on the failed attempt, and full-context retry without
previous_response_id.Verification
cargo fmt --all --checkcargo test --all— 600 tests passed across unit and integration suites (includes the new exhaustion smoke test,smoke_codex_websocket_empty_completions_exhaust_to_service_unavailable, 0.03s)cargo build --release --lockedpatched-proxy-okand normalend_turncargo clippy --all-targets -- -D warningsremains blocked by 33 pre-existing stable-1.97 warnings outside changed files.Independent from #68; no merge or deployment performed.