Fail pending control requests promptly when Query closes #1364
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 341 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.349
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1364"
general
weight: 0.35
tonydzi
Fixes #1094.
Summary
Pending outgoing control requests already fail fast when the message reader exits with an error, but two shutdown paths could still leave callers waiting for the full control-request timeout:
Query.close()/ClaudeSDKClient.disconnect();This change makes both paths fail pending control requests promptly while preserving any response or richer error that was already recorded.
Prior art
#1095 identified the same user-facing hang and correctly covered reader shutdown with a
finallywakeup. That PR was opened against an older July base and is currently non-mergeable.This PR keeps that reader-exit coverage, preserves the newer typed error handling now on
main, and also rejects control requests started after the query is already closed.Changes
Query.close()starts;Validation
Regression proof against the unchanged base used for this branch:
With this branch:
pytest -q tests/test_query.py— passed;ruff check src/claude_agent_sdk/_internal/query.py tests/test_query.py— passed;ruff format --check src/claude_agent_sdk/_internal/query.py tests/test_query.py— passed;mypy src/claude_agent_sdk/_internal/query.py— passed.Additional synthetic verification, kept out of the diff to avoid expanding the PR just for test volume:
ProcessErroris preserved rather than replaced by the generic shutdown error;ClaudeSDKClient.disconnect()fails an in-flight control request promptly under both asyncio and trio;tests/test_query.py tests/test_client.pyrun passes;query.pyandclient.py.The branch contains 2 commits. Upstream
mainhas since advanced independently, and GitHub still reports this PR mergeable.