fix(run-agent): rebuild anthropic client on stream retry#23678
Open
LeonSGP43 wants to merge 1 commit into
Open
fix(run-agent): rebuild anthropic client on stream retry#23678LeonSGP43 wants to merge 1 commit into
LeonSGP43 wants to merge 1 commit into
Conversation
4 tasks
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.
What does this PR do?
Fixes the credential-loss half of #23286 for Anthropic-wire providers like DeepSeek's
/anthropicendpoint.When a streaming retry is triggered after a transient stream drop, the retry cleanup path currently rebuilds the shared OpenAI client unconditionally. In
api_mode == "anthropic_messages", that is the wrong transport: these providers stream throughself._anthropic_client, and third-party Anthropic endpoints often leaveself._client_kwargsempty. The result is a misleadingMissing credentialsrebuild failure during retry cleanup.This change routes stream-retry cleanup through the Anthropic client when the active transport is
anthropic_messages, so retries reset the correct client instead of trying to rebuild an unused OpenAI one.It does not claim to solve DeepSeek's upstream ~600s server-side stream limit; it only fixes the retry-side credential loss / wrong-client rebuild.
Related Issue
Related to #23286
Type of Change
Changes Made
AIAgent._refresh_primary_stream_retry_client()in/run_agent.pyto branch retry cleanup by active transport.api_mode == "anthropic_messages"instead of calling_replace_primary_openai_client().stream_retry_pool_cleanupandstream_mid_tool_retry_pool_cleanup) to use the new helper./tests/run_agent/test_streaming.pythat proves Anthropic stream retries rebuild the Anthropic client and do not try to rebuild the OpenAI client.How to Test
uv run --frozen pytest -q -o addopts='' tests/run_agent/test_streaming.py -k 'AnthropicStreamRetryCleanup or test_anthropic_stream_refreshes_activity_on_every_event'uv run --frozen ruff check run_agent.py tests/run_agent/test_streaming.pyFailed to rebuild shared OpenAI client ... Missing credentials.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Targeted regression test:
2 passed, 33 deselectedRepo smoke:
uv run --frozen pytest -q -o addopts='' --collect-only tests/run_agent/test_streaming.py35 tests collected