fix(responses): raise failed results with their error code for retry routing - #56
Merged
zhanghanduo merged 1 commit intoOct 1, 2026
Conversation
…routing A failed Responses result was parsed like a successful one, so its partial output (including tool calls) was returned as an answer, and a streamed response.failed event was ignored. Raise instead, keeping the provider code on the error and mapping it to the equivalent status (rate_limit_exceeded 429, server_error 500, vector_store_timeout 504, other SDK codes 400; unknown codes keep generic retry) so the shared retry classifier routes it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
zhanghanduo
approved these changes
Oct 1, 2026
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
OpenAIResponsesClientmishandles a Responses result whosestatusisfailed:_parse_responses_outputparses a failed result as if it were a normal answer. The partial output is returned to the caller, including anyfunction_callitems, so the agent loop can execute tool calls from a response that the server itself reported as failed.response.failedevent matches no branch and is silently ignored.LLMErrorcarries no status code. The shared retry classifier therefore cannot tell a rate limit from a permanent 400-class error. Rate limits get generic backoff, and errors such asinvalid_promptare retried pointlessly.This PR raises on failed results and keeps the provider's error code on the error. The code is mapped to the equivalent HTTP status so that the existing
call_llmladder routes it:rate_limit_exceededserver_errorvector_store_timeoutinvalid_prompt,bio_policy,invalid_image*)non_transient)The table's key set is exactly the
ResponseError.codeliteral in openai 3.7.0. The existing text-based rules still take precedence: safety refusals advance the fallback chain, and upstream-timeout wording stays transient. For example,image_content_policy_violationadvances the chain through the existingcontent_policy_violationrule.Changes
agent_core/providers/openai_responses.py:_ResponsesError(LLMError)withcodeandstatus_code. Its message is"<code>: <provider message>", falling back toResponses request failed.response.failedevent raises the same error.tests/test_responses_error_routing.py(new):call_llm: reason, call count and backoff band.response.failedevent raises the same error as the parsed result.changes/responses-failed-error-routing.fix.md: changelog fragment.Test plan
Run on this branch, which is
mainplus this commit:python -m pytest tests -q: 1715 passed (openai 3.7.0, anthropic 1.3.0).ruff checkon the changed files: clean.main: 99 failed. With this commit: 99 passed.pyright agent_corereports 6 errors, all inagent_core/runtime/loop/agent_loop.py. Unmodifiedmainreports the same 6, and this PR does not touch that file.🤖 Generated with Claude Code