Skip to content

fix(core): pair reused tool-call ids by transcript order - #7996

Merged
BenTaylorDev merged 1 commit into
CopilotKit:mainfrom
pei711:fix/7891-preserve-tool-result-pairing
Oct 28, 2026
Merged

BenTaylorDev merged 1 commit into
CopilotKit:mainfrom
pei711:fix/7891-preserve-tool-result-pairing

Conversation

@pei711

@pei711 pei711 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Pairs tool results with the nearest unmatched tool call when a conversation reuses a tool-call ID across turns. This prevents filtered message repair from attaching a result to the wrong call.

Related PRs and Issues

Part of #7891.

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation
  • If the PR contains a breaking change, the title has ! and the description includes a BREAKING CHANGE: line with migration steps
  • "Allow edits by maintainers" is checked

Summary by CodeRabbit

  • Bug Fixes
    • Improved conversation history handling for tool interactions that reuse the same call ID. Results now remain associated with the correct call across turns, including when filtering removes messages. When a result is retained without its original call, the closest preceding matching call is restored, helping preserve the intended sequence and context of tool interactions.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-26T12:09:50.110311Z
We couldn’t complete this review. Comment @codex review to try again.
5205f8d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 89629de and 5205f8d.

Files selected for processing: 2
  • packages/core/src/__tests__/message-filter.test.ts
  • packages/core/src/core/message-filter.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

ɵrepairToolCallPairs now pairs results with the nearest unmatched preceding assistant call when tool-call IDs are reused. Tests cover intact histories and restoration of the correct call when filtering results.

Changes: Tool-Call Pairing

Layer / File(s) Summary
Pairing and restoration
packages/core/src/core/message-filter.ts, packages/core/src/__tests__/message-filter.test.ts
The repair records results by issuer and call ID, emits all results associated with each call, and resolves kept results to their recorded issuer. Tests verify reused-ID pairing and restoration.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related issues

  • CopilotKit/CopilotKit issue 7891 describes mis-pairing when tool-call IDs are reused. This change addresses that behavior.

Possibly related PRs

Merge Risk: Minimal · up to 5205f

The pairing change appears mergeable after normal checks; no actionable risk remains identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(core): pair reused tool-call ids by transcript order" matches the main change. The change in message-filter.ts makes ɵrepairToolCallPairs pair each tool result with the nearest unmatche…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(core): pair reused tool-call ids by transcript order" matches the main change. The change in message-filter.ts makes ɵrepairToolCallPairs pair each tool result with the nearest unmatched preceding assistant call that has the same call ID, so reused IDs across turns resolve by transcript order. The test additions cover the same behavior. The title is specific, concise, and follows the conventional commit style. It is consistent with the PR objectives, which describe pairing tool results with the nearest unmatched tool call when IDs are reused.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026

Copy link
Copy Markdown
@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@7996

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@7996

@copilotkit/angular

pnpm add https://pkg.pr.new/@copilotkit/angular@7996

@copilotkit/channels

pnpm add https://pkg.pr.new/@copilotkit/channels@7996

@copilotkit/channels-core

pnpm add https://pkg.pr.new/@copilotkit/channels-core@7996

@copilotkit/channels-discord

pnpm add https://pkg.pr.new/@copilotkit/channels-discord@7996

@copilotkit/channels-intelligence

pnpm add https://pkg.pr.new/@copilotkit/channels-intelligence@7996

@copilotkit/channels-slack

pnpm add https://pkg.pr.new/@copilotkit/channels-slack@7996

@copilotkit/channels-teams

pnpm add https://pkg.pr.new/@copilotkit/channels-teams@7996

@copilotkit/channels-ui

pnpm add https://pkg.pr.new/@copilotkit/channels-ui@7996

@copilotkit/channels-whatsapp

pnpm add https://pkg.pr.new/@copilotkit/channels-whatsapp@7996

@copilotkit/core

pnpm add https://pkg.pr.new/@copilotkit/core@7996

@copilotkit/intelligence-langgraph

pnpm add https://pkg.pr.new/@copilotkit/intelligence-langgraph@7996

@copilotkit/intelligence-mastra

pnpm add https://pkg.pr.new/@copilotkit/intelligence-mastra@7996

@copilotkit/learning

pnpm add https://pkg.pr.new/@copilotkit/learning@7996

@copilotkit/mcp-apps-renderer

pnpm add https://pkg.pr.new/@copilotkit/mcp-apps-renderer@7996

@copilotkit/react-core

pnpm add https://pkg.pr.new/@copilotkit/react-core@7996

@copilotkit/react-native

pnpm add https://pkg.pr.new/@copilotkit/react-native@7996

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/@copilotkit/react-textarea@7996

@copilotkit/react-ui

pnpm add https://pkg.pr.new/@copilotkit/react-ui@7996

@copilotkit/runtime

pnpm add https://pkg.pr.new/@copilotkit/runtime@7996

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@7996

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/@copilotkit/sdk-js@7996

@copilotkit/shared

pnpm add https://pkg.pr.new/@copilotkit/shared@7996

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@7996

@copilotkit/voice

pnpm add https://pkg.pr.new/@copilotkit/voice@7996

@copilotkit/vue

pnpm add https://pkg.pr.new/@copilotkit/vue@7996

@copilotkit/web-components

pnpm add https://pkg.pr.new/@copilotkit/web-components@7996

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/@copilotkit/web-inspector@7996

commit: 5205f8d

@BenTaylorDev BenTaylorDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on current main merged with this branch and #7984: the message-filter tests pass (100) and the full core suite passes (1,479). Reverting message-filter.ts to main fails both new tests, including the issue's identity-filter repro. Pairing each result with the newest open call for its id matches ɵkeepToolResultsWithCalls. One edge for the record: with two same-id calls before both results (a1, a2, t1, t2), t1 pairs with a2. That case is ambiguous, and main drops t1 there, so this is still an improvement. Thanks!

I bless the code with a glad heart

@BenTaylorDev
BenTaylorDev added this pull request to the merge queue Oct 28, 2026
Merged via the queue into CopilotKit:main with commit c6124c7 Oct 28, 2026
63 of 64 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.

2 participants