Repository navigation
fix(agent): pair parallel tool calls by internal call id - #266
Merged
gi-dellav merged 1 commit intoAug 27, 2026
Merged
Conversation
xavierforge
force-pushed
the
fix/parallel-tool-call-pairing
branch
from
August 27, 2026 07:12
23ef156 to
d9f7c82
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
rig 0.40 streams a parallel tool-call batch as all ToolCall items first, then their ToolResult items, but zerostack tracked the in-flight call in single "most recent call" slots. With more than one call in flight, the first result was recorded under the last call's name and args, and later results under an empty name. This PR keys the pairing on rig's
internal_call_idin all four consumers: the headlessrun_printloop, thespawn_agentevent loop, the TUI session recorder, and the ACP bridge.Motivation
Session JSON tool records are the structured record of what a turn actually did, and any provider that emits parallel tool calls corrupts them today: wrong name and args on the first result, empty name on the rest. The TUI tool-result display and ACP tool-call notifications mispair the same way. Anthropic, OpenAI, and Gemini all emit parallel batches in normal operation, so this is not an edge case.
Design decisions
internal_call_id, not the provider-suppliedToolCall.id: Gemini and Ollama setToolCall.idto the function name, so it is not unique within a batch, whileinternal_call_idis rig-generated, unique, and carried on both the ToolCall and ToolResult stream items.AgentEvent::ToolCallandAgentEvent::ToolResultgained acall_idfield so every consumer pairs by id instead of by arrival order. The TUI keeps its pending calls in one insertion-ordered Vec behindAgentRunStatemethods, which derives "newest still-pending" for subagent attribution and gives every run-teardown path (done, error, abort, Ctrl-C, mid-turn compaction respawn, context-exhausted stop) a single clear call so a stranded entry cannot leak into the next run.tasktool is a follow-up noted below.Testing
src/tests/parallel_tool_call_tests.rs(7 tests): a two-call batch through two distinct tools asserts correct name/args/output pairing inrun_print's recorded interactions and id-keyed pairing inspawn_agent's event stream, with an ordered-log assertion that the batch shape (both calls before the first result) is what the test exercises; unit tests for theAgentRunStatepending-call helpers (pairing in either result order, newest-pending degradation, duplicate-id replacement, clear); an orphan-result test asserting call 0's record stays untouched.cargo test --all-features: 1079 passed, 0 failed.cargo clippy --all-targets --all-features -- -D warnings: clean.Reviewing
Start with
src/event.rsfor the event contract, thensrc/agent/runner.rs(thespawn_agentandrun_printloops are the two recording paths), thensrc/ui/state.rsplussrc/ui/event_handler.rsfor the TUI pending-call state and teardown coverage, thensrc/extras/acp/mod.rs. The test file states the intended pairing semantics and is the fastest way to see the behavior change. LoC breakdown: production +232/-57 (runner 70/18, TUI 117/30, ACP 35/8, event 9/0, docs 1/1), tests +375/0.Notes
internal_call_idthrough thetasktool via rig's hook stack; this PR keeps the pre-existing best-effort heuristic and documents it accurately on both paths.AgentRunStatehelpers instead.ToolResultcarries no name field; the recorded pair is self-consistent under its own freshly stamped id.