fix: add missing tool_result blocks to prevent API errors #10015
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.
Problem
Users are encountering the following error when the API is called:
This error occurs when an assistant message contains
tool_useblocks but the subsequent user message is missing the correspondingtool_resultblocks entirely. This can happen during parallel tool execution scenarios (e.g., when the model tries to execute thenew_tasktool in parallel with other tools).Root Cause
The existing
validateAndFixToolResultIds()function only fixed ID mismatches betweentool_resultandtool_useblocks, but didn't handle the case wheretool_resultblocks are completely missing.Solution
Enhanced
validateAndFixToolResultIds()to:tool_resultblocks - Check if anytool_useIDs don't have correspondingtool_resultblocksMissingToolResultErrorclass for structured error trackingtool_resultblocks with content: "Tool execution was interrupted before completion."Changes
src/core/task/validateToolResultIds.tsMissingToolResultErrorclass for telemetry trackingtool_resultblockssrc/core/task/__tests__/validateToolResultIds.spec.tstool_resultfor single/multipletool_useblocksMissingToolResultErrorclassTesting
Important
Enhance
validateAndFixToolResultIds()to detect and add missingtool_resultblocks, with comprehensive tests and telemetry reporting.validateAndFixToolResultIds()invalidateToolResultIds.tsto detect and add missingtool_resultblocks.tool_resultblocks with content: "Tool execution was interrupted before completion."tool_resultblocks usingMissingToolResultError.validateToolResultIds.spec.tsfor scenarios with missingtool_resultblocks, partial matches, and telemetry reporting.tool_resultblocks and empty user content arrays.MissingToolResultErrorclass for structured error tracking.tool_resultblocks to telemetry.This description was created by
for a71427f. You can customize this summary. It will automatically update as commits are pushed.