Skip to content

shelley/loop: repair missing tool results in tool-call order - #362

Open
AndrewFribush wants to merge 1 commit into
boldsoftware:mainfrom
AndrewFribush:fix/ordered-tool-result-repair
Open

AndrewFribush wants to merge 1 commit into
boldsoftware:mainfrom
AndrewFribush:fix/ordered-tool-result-repair

Conversation

@AndrewFribush

Copy link
Copy Markdown

When a turn is interrupted after the model asks for several tools and the next user message lacks some of their results, insertMissingToolResults prepends synthetic "not executed" results for the missing ones. It found them by ranging over a map, so they came out in a different order on each request.

The repair is recomputed for every request and never written back to the history, so the same conversation produced different request bytes each time, and the prompt cache missed from the interrupted turn onward on every later request in that conversation.

Walk the assistant message's tool calls in their original order instead. A repeated tool-call ID still gets a single result, as before. The new test interrupts six tool calls with one answered and checks the order across 50 repairs; it fails against the old code.

🤖 Generated with Claude Code

When a turn is interrupted after the model asks for several tools and
the next user message lacks some of their results, insertMissingToolResults
prepends synthetic "not executed" results for the missing ones. It found
them by ranging over a map, so they came out in a different order on each
request.

The repair is recomputed for every request and never written back to the
history, so the same conversation produced different request bytes each
time, and the prompt cache missed from the interrupted turn onward on
every later request in that conversation.

Walk the assistant message's tool calls in their original order instead.
A repeated tool-call ID still gets a single result, as before.
The new test interrupts six tool calls with one answered and checks the
order across 50 repairs; it fails against the old code.
@cla-bot cla-bot Bot added the cla-signed label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant