Fix async compaction using unfiltered messages instead of local copy#1234
Open
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Open
Fix async compaction using unfiltered messages instead of local copy#1234MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
MaxwellCalkin wants to merge 1 commit intoanthropics:mainfrom
Conversation
…al copy In BaseAsyncToolRunner._check_and_compact(), the code copies self._params["messages"] to a local `messages` list and then filters out tool_use blocks from the last assistant message to avoid a 400 API error (tool_use blocks require corresponding tool_result blocks). However, when constructing the final messages list to send to the API, the async version incorrectly uses `*self._params["messages"]` (the original, unfiltered list) instead of `*messages` (the filtered local copy). This bug means the async compaction path always sends unfiltered messages, potentially including orphaned tool_use blocks, which can cause a 400 error from the API. The sync version (BaseSyncToolRunner._check_and_compact) correctly uses `*messages`. This fix aligns the async version with the sync version. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
BaseAsyncToolRunner._check_and_compact()uses*self._params["messages"]instead of the locally-filtered*messageswhen constructing the messages list for the compaction API calltool_useblocks without correspondingtool_resultblocks, which causes a 400 error from the API*self._params["messages"]with*messageson line 472, aligning the async version with the sync version which already correctly uses*messagesDetails
In
_check_and_compact(), lines 455-469 copyself._params["messages"]to a localmessageslist and filter outtool_useblocks from the last assistant message (or remove the entire message if all blocks aretool_use). This filtering is necessary becausetool_useblocks require correspondingtool_resultblocks, and sending them without results causes a 400 API error.However, line 472 in the async version (
BaseAsyncToolRunner) incorrectly discards this filtered copy by spreading from the originalself._params["messages"]instead of the localmessages.The sync version (
BaseSyncToolRunner._check_and_compact(), line 211) correctly uses*messages.Test plan
tool_useblocks🤖 Generated with Claude Code
AI Disclosure
This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).