Repository navigation
fix: keep parallel tool calls in one response when writing pi and Claude Code sessions - #110
Merged
Merged
Conversation
…r results replay Sources that record one block per message (Codex function_call items, Claude Code's one-line-per-block JSONL) give a parallel call batch as consecutive assistant messages with every result after them. The pi and Claude Code writers replayed each call as its own assistant message, so the first call was no longer followed by its result: - pi paired it with a synthetic "No result provided" error and left the real result orphaned; - Claude Code replaced its result with "[Tool result missing due to internal error]", so the real output never reached the model. A run of consecutive assistant messages with a tool call before its last message is now treated as one model response, written in each target's native shape: pi merges the run into one assistant message (blocks in order, first timestamp/model, last stop reason/usage), and Claude Code keeps one line per message but gives the run's lines a shared deterministic message.id, which Claude Code merges back into one API message on resume. Sequential calls and other runs are written exactly as before.
# Conflicts: # tests/regression/main.rs
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.
Problem
When a Codex or Claude Code session in which the model ran tools in parallel is continued in pi or Claude Code, the resumed model is told its first call failed.
Codex and Claude Code record a parallel batch as separate assistant messages (text, call a, call b) followed by result a and result b.
message.id. Claude Code only merges assistant lines that share an id, so call a's result was replaced with "[Tool result missing…]".The native shapes were confirmed from real CLI sessions: pi stores the batch as one message, and Claude Code as several lines sharing one
msg_…id.Fix
A run of consecutive assistant messages with a tool call before the last one is written as one response:
msg_id.Sequential sessions (no parallel calls) come out byte-identical to before.
Tests
tests/regression/parallel_tool_calls.rs(3 tests): 2 fail on main, all pass here.--with pi/--with claude_codekeeps both results.cargo fmt --check,cargo clippy --workspace --all-targets --all-features -D warnings,cargo test --workspace --all-featurespass.Try it
txcript continue <id> --from codex --with pi(or--with claude_code) on a session where the model issued two tool calls before any result, then resume; both results are present.