Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 6, 2026

Summary

This PR attempts to address Issue #10494 - the race condition where deleted queued messages create duplicate tool_result blocks.

Problem

When a user queues a message during tool execution and then deletes it before completion, the deleted message text can persist and create a second tool_result block in a subsequent user message that references a tool_use_id that was already paired in a previous message. This causes API protocol violations: "The number of toolResult blocks exceeds the number of toolUse blocks."

Solution

Enhanced validateAndFixToolResultIds() with cross-message orphan filtering:

  1. Scan conversation history after the previous assistant message to find which tool_use_ids have already been paired with tool_result blocks in previous user messages

  2. Filter out orphaned tool_results in the current message that reference already-paired tool_use_ids

  3. Exclude already-paired IDs from "missing" tool_result calculations so we do not add placeholder results for tool_uses that are already satisfied

Changes

  • src/core/task/validateToolResultIds.ts: Added cross-message orphan filtering logic
  • src/core/task/__tests__/validateToolResultIds.spec.ts: Added 5 comprehensive tests for cross-message scenarios

Testing

All 32 tests pass, including the new cross-message orphan filtering tests.

Feedback and guidance are welcome!

…es (GitHub #10494)

This fixes a race condition where deleted queued message text persists and
creates duplicate tool_result blocks in subsequent user messages for the same
tool_use_id that was already paired in a previous message.

Changes:
- Add cross-message orphan filtering in validateAndFixToolResultIds()
- Scan conversation history to find tool_use_ids already paired
- Filter out orphaned tool_results referencing already-paired IDs
- Exclude already-paired IDs from missing tool_result calculations
- Add comprehensive tests for cross-message scenarios
@roomote
Copy link
Contributor Author

roomote bot commented Jan 6, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly addresses the race condition where deleted queued messages can create duplicate tool_result blocks. The cross-message orphan filtering logic properly scans conversation history to identify already-paired tool_use_ids and filters out orphaned tool_results that would otherwise cause API protocol violations. Test coverage is comprehensive with 5 new tests for the cross-message scenarios.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

3 participants