This repository was archived by the owner on May 15, 2026. It is now read-only.
fix: filter orphan tool_result blocks after sliding window truncation - #11030
Open
dwebster123 wants to merge 1 commit into
Open
fix: filter orphan tool_result blocks after sliding window truncation#11030dwebster123 wants to merge 1 commit into
dwebster123 wants to merge 1 commit into
Conversation
… (no summary) When sliding window truncation removes assistant messages containing tool_use blocks, user messages with tool_result blocks referencing those removed IDs were being sent to the API, causing Anthropic to reject the request with 'unexpected tool_use_id in tool_result blocks'. The existing orphan filtering logic only ran in the summary (condensation) code path. This adds the same filtering to the no-summary code path in getEffectiveApiHistory(), ensuring tool_use/tool_result pairs remain atomic regardless of how truncation occurs. Fixes RooCodeInc#11029
Review complete. No issues found. The implementation correctly adds orphan Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
ghost
approved these changes
Jan 27, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Fixes #11029
When sliding window truncation removes assistant messages containing
tool_useblocks, user messages withtool_resultblocks referencing those removedtool_use_ids were still being sent to the API. Anthropic's API requires everytool_resultto have a correspondingtool_usein the immediately preceding assistant message, so these orphaned references cause the request to be rejected with:Root Cause
The existing orphan
tool_resultfiltering logic ingetEffectiveApiHistory()only ran in the summary (condensation) code path. When there was no summary and only sliding window truncation had been applied, orphantool_resultblocks were not filtered out.Fix
Added the same orphan
tool_resultfiltering to the no-summary code path ingetEffectiveApiHistory():tool_useIDs from visible assistant messagestool_resultblocks in visible user messages that referencetool_use_ids not in the visible setThis mirrors the existing pattern already used in the condensation code path.
Tests
Added 3 test cases:
tool_resultfiltered when both assistant and user messages are truncated bytruncationParenttool_resultfiltered when user message survives truncation but referenced assistant is truncatedtool_resultblocks are strippedAll 5161 existing tests continue to pass.
Important
Adds orphan
tool_resultfiltering togetEffectiveApiHistory()for sliding window truncation inindex.ts.tool_resultfiltering to the no-summary path ingetEffectiveApiHistory()inindex.ts.tool_resultblocks referencing non-visibletool_useIDs and removes empty user messages.index.spec.tsfor orphantool_resultfiltering when assistant messages are truncated, user messages survive truncation, and mixed content in user messages.This description was created by
for ac1d172. You can customize this summary. It will automatically update as commits are pushed.