docs: say that a deferred tool call runs at least once #1577
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.39) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 251 lines diff across 3 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
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.331
Real PR Conversation Timeline
1 comments
"Review active on #1577"
general
weight: 0.35
tonydzi
Summary
A tool call deferred by a
PreToolUsehook runs at least once, not exactly once. The process can stop after the tool starts and before its result is saved. Then the next resume firesPreToolUseagain for the same call, and the tool can run a second time. Nothing in the SDK says this today.This adds a note to the
DeferredToolUsedocstring. The note says:idas an idempotency key. The hook receives the same value astool_use_idand can pass it to the tool throughupdatedInput.id.The last two points come from @gioherazo in #1549.
No behavior changes.
Evidence
Reproduced with the stub-model script from #1549 (a local fake API, no real model), 5 runs per row:
| Kill point after the resumed tool starts | Tool runs after a second resume | With the
tool_use_idkey ||---|---:|---:|
| In the tool, after the side effect | 2 (5 of 5) | 1 effect (5 of 5) |
| In a
PostToolUsehook | 2 (5 of 5) | 1 effect (5 of 5) || No kill (control) | 1 (5 of 5) | 1 (5 of 5) |
Platforms: Windows 11 with SDK 0.2.182 (CLI 2.1.325), and Linux with SDK 0.2.187 (CLI 2.1.330). Both gave the same results. The hook saw the same
tool_use_idin all three runs of every test, and it was equal todeferred_tool_use.id. Details are in this comment.Testing
ruff checkandruff format --checkpass onsrc/claude_agent_sdk/types.py.mypy src/claude_agent_sdk/types.pypasses.pytest tests/passes (1740 passed, 21 skipped, on Windows with Python 3.13).Refs #1549