Skip to content

fix: keep parallel tool calls in one response when writing pi and Claude Code sessions - #110

Merged
NishantJoshi00 merged 4 commits into
mainfrom
fix/parallel-tool-calls
Nov 18, 2026
Merged

NishantJoshi00 merged 4 commits into
mainfrom
fix/parallel-tool-calls

Conversation

@NishantJoshi00

Copy link
Copy Markdown
Collaborator

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.

  • pi: the writer emitted one pi message per assistant message, so call a's turn ended without its result and pi filled in a fake "No result provided".
  • Claude Code: the writer gave those lines no 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:

  • pi merges them into a single message.
  • Claude Code keeps one line per message (so uuids and range selection don't change) and gives the lines a shared deterministic msg_ id.

Sequential sessions (no parallel calls) come out byte-identical to before.

Tests

  • New tests/regression/parallel_tool_calls.rs (3 tests): 2 fail on main, all pass here.
  • Byte-identical output vs main checked on real sessions without parallel calls (export/convert into pi and Claude Code).
  • A real Codex parallel-tools session continued with --with pi / --with claude_code keeps both results.
  • cargo fmt --check, cargo clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace --all-features pass.

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.

…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.
@NishantJoshi00
NishantJoshi00 merged commit 2bf712e into main Nov 18, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant