claude-code-proxy
claude-code-proxy copied to clipboard
Reliability Hardening: Fixed tool_use conversion, streaming bridge, and upstream retries
Overview
This issue documents the root cause analysis and resolution of several critical reliability and performance issues discovered during development.
Issues Resolved
1. Tool Use Conversion Gate (ISSUE-004)
- Problem: Many OpenAI-compatible models (qwen, deepseek, minimax) were returning tool calls as plain text or were being suppressed by a model-prefix gate.
- Fix: Removed the model-prefix gate in
convert_litellm_to_anthropicand added a parser fallback for manual tool calls incontent_text. - Result: Models like
deepseek-v3.1now correctly produce structuredtool_useblocks.
2. Streaming Response RuntimeError
- Problem: Agent would 'stall' or connections would drop during streaming.
- Root Cause:
HTTPExceptionwas being raised after the first SSE blocks were yielded. - Fix: Implemented a
response_startedflag. Any errors occurring after headers are sent are now yielded as standard Anthropic SSEerrorevents.
3. Upstream Stalls (502/504 Errors)
- Problem: Transient 502/504 errors from upstream providers were not being handled gracefully.
- Fix: Implemented
retry_with_backofffor both non-streaming and the initial phase of streaming requests.
4. Streaming Lifecycle Fix
- Problem:
AsyncClientcreated outside the generator lifecycle was being closed prematurely. - Fix: Moved
AsyncClientlifecycle inside the stream generator.
Status
All fixes have been implemented and verified with complex tool-use tests. We have prepared a PR with these changes.