fix: sanitize tool_use_id in tool_result blocks to match API history #11131
+16
−7
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 ToolResultIdMismatchError where tool_result IDs didn't match tool_use IDs in API conversation history.
Problem
PostHog reported 926 ToolResultIdMismatchError occurrences in v3.46.0 where
tool_resultIDs (e.g.,functions.read_file:0) didn't matchtool_useIDs (e.g.,functions_read_file_0).Root Cause
In
Task.ts, when savingtool_useblocks to API conversation history, IDs were sanitized usingsanitizeToolUseId(). However, inpresentAssistantMessage.ts, when creatingtool_resultblocks, the original unsanitizedtoolCallIdwas used.Solution
Updated
presentAssistantMessage.tsto sanitizetoolCallIdusingsanitizeToolUseId()when creatingtool_resultblocks, ensuring consistency with howtool_useIDs are stored in history.Changes
sanitizeToolUseIdinpresentAssistantMessage.tstool_use_id: toolCallIdtotool_use_id: sanitizeToolUseId(toolCallId)Testing
functions.read_file:0→functions_read_file_0sanitizationLinear Issue
Fixes EXT-711
Important
Fixes
ToolResultIdMismatchErrorby sanitizingtoolCallIdinpresentAssistantMessage.tsto ensure consistent ID format.ToolResultIdMismatchErrorby sanitizingtoolCallIdinpresentAssistantMessage.tsusingsanitizeToolUseId().tool_resultIDs matchtool_useIDs in API history.tool-id.spec.tsfor sanitizingfunctions.read_file:0tofunctions_read_file_0.This description was created by
for fe85422. You can customize this summary. It will automatically update as commits are pushed.