fix: handle transport close race condition in control request responses#492
Open
drillan wants to merge 1 commit intoanthropics:mainfrom
Open
fix: handle transport close race condition in control request responses#492drillan wants to merge 1 commit intoanthropics:mainfrom
drillan wants to merge 1 commit intoanthropics:mainfrom
Conversation
This was referenced Jan 19, 2026
drillan
added a commit
to drillan/claudecode-model
that referenced
this pull request
Jan 19, 2026
Use forked branch to resolve ProcessTransport error when using SDK MCP servers with string prompts. - Add [tool.uv.sources] to use forked branch - Bump version from 0.0.3 to 0.0.4 Upstream PR: anthropics/claude-agent-sdk-python#492 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When the CLI process exits immediately after processing the final message, the transport may close before we can send the control response. This caused unhandled CLIConnectionError exceptions. Wrap transport.write calls in _handle_control_request with try/except to gracefully handle the race condition when the transport is already closed. Other exceptions still propagate normally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
c1b9f8d to
f57ed08
Compare
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
CLIConnectionErrorexceptions during_handle_control_requesttransport.writecalls withtry/except CLIConnectionErrorto gracefully handle the race conditionChanges
CLIConnectionErrorimport toquery.pytransport.writecalls in_handle_control_requestwithtry/exceptto handle transport close race conditionTest plan
test_query_control_request.pywith 6 test cases:Related to #386
🤖 Generated with Claude Code