Repository navigation
fix: match parallel tool calls by tool use id instead of tool name - #110
Conversation
Parallel calls to the same tool collapsed into one node (deduped by name inside the 3 s window) and a result could complete the wrong call (first running call with that name). The ids already existed but never reached the web view. - Emit toolUseId on tool_call_start / tool_call_end from the transcript (tool_use id / tool_use_id), the hook server (tool_use_id) and Codex rollouts (call_id). - Key, dedupe and finish tool calls on it in handle-tool-events.ts. The hook server and the transcript report the same id, so the duplicate is dropped by id rather than by time window. - Keep name-based matching as the fallback when either side has no id (older recordings, hook payloads without tool_use_id). - Run the web tests with web/tsconfig.json so they can import modules that use the @/ alias. Fixes patoles#107 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for picking this up, and for such a thorough write-up! The approach is exactly what we discussed, and the fallback for events without ids is handled carefully. One small request: the new root Optional, only if you feel like it: |
TSX_TSCONFIG_PATH=... inline does not work in the Windows default shell. Also start a real HookServer, like request-guard.test.ts does, to check that tool_use_id reaches tool_call_start and tool_call_end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review! Both are in the latest commit:
|
|
Merged, thanks a lot! Great work on this, especially adding the hook-server test even though it was optional. It will ship in the next release. |
|
Thanks for the quick review and the helpful pointers, glad I could help! Looking forward to the release. |
What does this PR do?
Fixes #107
Parallel calls to the same tool were deduplicated by agent + tool name inside the 3 s window, so three parallel
Readcalls became one node with only the first file in file attention. Results were also matched by name, so finishing the second call completed the first one. This follows the direction in the issue thread: the ids already exist, so this change sends them to the web view and matches on them.Extension (emit
toolUseIdontool_call_startandtool_call_end)transcript-parser.ts: thetool_useblock'sidon start, and thetool_result'stool_use_idon end.hook-server.ts: the hook payload'stool_use_idon PreToolUse, PostToolUse and PostToolUseFailure.codex-rollout-parser.ts:call_idforfunction_call/custom_tool_calland their outputs.web_search_callhas no id, so it keeps name matching (start and end are emitted together anyway).protocol.ts: documents the new payload field. Payloads are stillRecord<string, unknown>, so this is a doc comment and not a new type.Web view (
handle-tool-events.ts)tool-<agent>-<toolUseId>when an id is present, and storetoolUseId(new optional field onToolCallNode). Parallel calls processed in the same frame no longer overwrite each other.tool_use_id), the old agent + tool name matching and the 3 s window apply unchanged.Test setup (
package.json)testscript now runs theweb/tests withTSX_TSCONFIG_PATH=web/tsconfig.json.handle-tool-events.tsimports through the@/alias, which tsx can't resolve without the web tsconfig. Thescripts/andapp/tests still run as before, in a separate command. Happy to change this if you'd prefer another setup.How to test
New tests:
web/hooks/simulation/handle-tool-events.test.ts:Readcalls with different ids stay three nodes with three file-attention entriesextension/test/transcript-parser.test.ts:toolUseIdon start and end, with results arriving out of order.extension/test/codex-rollout-parser.test.ts:toolUseIdequalscall_idforexec_commandandapply_patch.There is no hook-server test file.
HookServerimportsvscode, so the hook change is covered by the typecheck only.Results (local, Node 24.14.1, pnpm 10.34.9):
toolUseId(two extended Codex tests and one new transcript test). The fallback test passed.pnpm test39/39 + 12/12, extension tests 79/79, extensionlintandlint:test(tsc) clean, webtsc --noEmitclean.I did not test this against a live Claude Code or Codex session in VS Code.
Checklist
AI assistance
The code, tests and this description were written with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code