fix(anthropic): skip primary OpenAI client swap on stale stream retry to prevent 15-min hang - #33855
Conversation
|
Thanks, triage. Comparison with #28240 for dedupe: Both PRs make the same core fix — on the Anthropic stream-cleanup path, rebuild the Anthropic client ( What this PR adds: the #28240 makes the equivalent fix without a test. Either works for me — if maintainers prefer the minimal one, the test here can be cherry-picked. Happy to consolidate whichever is easier to review. |
50d9ead to
3b33e9f
Compare
|
CI note — the red checks are inherited from This branch was just rebased onto the latest
This PR only changes Happy to rebase again once |
3b33e9f to
fd3f45c
Compare
06e9450 to
e85ee15
Compare
|
Closed in favor of #53926, now merged to main (commit a0b9663). This was a popular bug — 12 independent PRs fixed the same issue (#28161): the three stream-cleanup paths in the streaming code rebuilt the OpenAI primary client unconditionally, which on Anthropic-native sessions both failed (no OPENAI_API_KEY) and left the wedged stream open, causing the ~15-minute hang. We salvaged @EloquentBrush0x's #28240 (the earliest dedicated fix for this issue) onto current main, resolved the conflict against the newer request-client cleanup helper, repointed the bug-encoding regression test, and added coverage for the two reachable Anthropic cleanup sites. Verified live: stale stream torn down in <1s instead of ~900s, Anthropic client closed+rebuilt, OpenAI rebuild never called on the Anthropic path. Thank you for the fix — closing as a duplicate of the merged work. Credit to everyone who reported and fixed this. |
Summary
api_mode == "anthropic_messages", stream cleanup paths now close and rebuild the Anthropic client instead of swapping the primary OpenAI client.tool_usenames fromcontent_block_startso text + tool-use + transient disconnect enters the mid-tool retry path instead of returning a partial-text stub.upstream/mainatd0e017bac; latest merge-tree check againstb1af653bfremains clean.Review notes
TDD / verification
.venv\Scripts\python.exe -m pytest tests\run_agent\test_streaming.py::TestAnthropicStreamCallbacks::test_anthropic_tool_use_start_marks_partial_tool_for_mid_tool_retry -q --timeout-method=threadfailed on currentupstream/main; the call returned the partial-stream stub instead of retrying through to the final Anthropic tool-use message.rebuild_calls == []), proving the Anthropic cleanup parent change was required too..venv\Scripts\python.exe -m pytest tests\run_agent\test_streaming.py::TestAnthropicStreamCallbacks::test_anthropic_stream_parser_valueerror_retries_before_delivery tests\run_agent\test_streaming.py::TestAnthropicStreamCallbacks::test_anthropic_stale_stream_does_not_swap_openai_client tests\run_agent\test_streaming.py::TestAnthropicStreamCallbacks::test_anthropic_tool_use_start_marks_partial_tool_for_mid_tool_retry -q --timeout-method=thread-> 3 passed, 1 existing Discordaudioopdeprecation warning..venv\Scripts\python.exe -m pytest tests\run_agent\test_streaming.py -q --timeout-method=thread-> 38 passed, 1 existing Discordaudioopdeprecation warning..venv\Scripts\ruff.exe check agent\chat_completion_helpers.py tests\run_agent\test_streaming.py-> passed..venv\Scripts\python.exe -m py_compile agent\chat_completion_helpers.py tests\run_agent\test_streaming.py-> passed.git diff --check-> passed.git merge-tree --write-tree upstream/main HEAD-> clean (2602ff6df085a817f4ac99d10aa8dff726f74cce).