fix(ai): repair interrupted tool result ordering - #1102
Closed
junhoyeo wants to merge 1 commit into
Closed
Conversation
junhoyeo
force-pushed
the
fix/interrupted-tool-result-ordering-upstream
branch
from
August 9, 2026 23:13
27e182d to
0e0452c
Compare
Contributor
|
Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1165, authored independently from We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1165 and is being closed. The complete review stack is #1158–#1165. It is being left unmerged for human review after CI and review-bot findings are cleared. |
sethkarten
added a commit
that referenced
this pull request
Aug 10, 2026
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
Root cause
An update restart can persist this temporal order while aborting an in-flight tool:
The marker becomes a user message in model context. The existing transform synthesized a replacement result before that user boundary but later emitted the real result too. Anthropic then rejected the late result because its immediately preceding message had no matching
tool_use, permanently blocking every subsequent request that replayed the same history.The provider transform is the shared repair boundary for this invariant. Matching is bounded at the next assistant message, occurs after tool-call ID normalization, preserves real results over synthetic ones, and is a no-op for well-formed turns.
Validation
cd packages/ai && npx tsx ../../node_modules/vitest/dist/cli.js --run test/transform-messages-copilot-openai-to-anthropic.test.ts— 10 passednpm run check— passed on the upstreammainbase; Biome checked 900 files with no fixes, type checking and installer/browser smoke checks passedbuildSessionContext→convertToLlm→ patchedtransformMessages: 1,904 persisted entries, 377 transformed messages, the real interrupted result preserved, and zero tool-pairing violationsNote
Fix tool result ordering when an assistant turn is interrupted by a user message
transformMessagesto correctly handle tool results that arrive after an interposed user message during an interrupted assistant turn.assistant,toolResult, anduserare no longer forwarded in the second pass.Macroscope summarized 0e0452c.