fix(streaming): tool calls and race conditions for SDK mode#31
Merged
CaddyGlow merged 2 commits intoCaddyGlow:dev/v0.2from Jan 4, 2026
Merged
Conversation
This commit ports critical bug fixes to the dev/v0.2 architecture: 1. **Tool calls SSE-only bug** (processors.py) - Removed `output_format == "sse"` condition that excluded dict format - Tool calls now work in both SSE and dict (SDK) output formats - Added proper tool call indexing with enumerate() - Added debug logging for tool call yielding 2. **Non-atomic broadcast race condition** (stream_worker.py) - Removed racy has_listeners() check before broadcast() - Now always broadcasts and checks delivered count afterward - Fixes message loss with fast STDIO tools like filesystem 3. **Listener pre-registration race** (stream_handle.py) - Worker is now created but not started until listener is registered - Prevents messages from being lost before listener is ready - Fixes first-message loss with rapid tool responses 4. **Orphaned tool_result sanitization** (requests.py) - Added _sanitize_tool_results() function - Removes tool_result blocks that lack matching tool_use blocks - Converts orphaned results to text to preserve information - Prevents "unexpected tool_use_id" API errors Tests added: - test_tool_call_streaming.py: 4 tests for tool call streaming - test_tool_result_sanitization.py: 17 tests for sanitization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove unused _ensure_worker_created method (dead code) - Change tool call logging from debug to trace level for consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
Ports critical bug fixes to dev/v0.2 architecture:
Test plan
Files Changed
ccproxy/llms/streaming/processors.py- Remove SSE-only conditionccproxy/plugins/claude_sdk/stream_worker.py- Atomic broadcastccproxy/plugins/claude_sdk/stream_handle.py- Pre-register listenerccproxy/llms/formatters/openai_to_anthropic/requests.py- Add sanitization🤖 Generated with Claude Code