fix: prevent premature tool execution with truncated arguments #10407
+17
−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.
Related GitHub Issue
Closes: #10328
Roo Code Task Context (Optional)
View task on Roo Code Cloud
Description
This PR adds a safety net to prevent tools from executing with truncated/corrupted arguments during native tool call streaming.
Observed Symptom:
pathandcontent)"path":"sr"instead of"src/core/prompts/sections/skills.ts")Current Fix:
When
finalizeStreamingToolCall()returns null (indicating the accumulated JSON arguments could not be parsed), we now clear the potentially truncated params in bothtool_call_endhandling paths:When finalization fails:
paramsare cleared to{}nativeArgsare set toundefinedInvestigation Notes:
The root cause appears to be related to when
tool_call_endevents are emitted. TheprocessFinishReason()method (called from API providers) emitstool_call_endwhenfinish_reason === "tool_calls"is received. If this fires before all argument chunks have been accumulated inargumentsAccumulator, the tool would finalize with incomplete data.This fix provides a safety net for the JSON.parse failure case. A more thorough fix may require:
processFinishReason()calls from providers and relying only onfinalizeRawChunks()at stream endTest Procedure
All existing tests pass:
cd src && npx vitest run core/task- 124 tests passcd src && npx vitest run core/assistant-message- 91 tests passThe fix prevents tools from executing with truncated arguments when JSON parsing fails during streaming. Instead of executing with corrupted data, the tool will fail validation with a "missing parameter" error.
Pre-Submission Checklist
Screenshots / Videos
N/A - This is a backend streaming bug fix with no UI changes.
Documentation Updates
Additional Notes
This fix provides a defensive measure that ensures tool validation catches malformed/incomplete arguments rather than allowing them to propagate through to tool execution. Further investigation may be needed to address the root cause of premature
tool_call_endemission.Get in Touch
N/A - Automated fix via Roo Code task