-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: prevent write_to_file from creating files at truncated paths during streaming #10414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ing streaming During streaming, the partial-json library may return truncated string values when chunk boundaries fall mid-value (e.g., 'sr' instead of 'src/core/prompts/sections/skills.ts'). This fix: 1. Waits for the path to stabilize (same value in consecutive partial blocks) before creating files 2. Updates diffViewProvider.relPath in execute() when isEditing is already true 3. Re-reads fresh block data for non-partial tool_use blocks Fixes ROO-311
Review complete. No issues found. The fix for ROO-311 is well-implemented:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| if (block.type === "tool_use" && !block.partial) { | ||
| const freshBlock = cline.assistantMessageContent[cline.currentStreamingContentIndex] | ||
| if (freshBlock && freshBlock.type === "tool_use" && !freshBlock.partial) { | ||
| block = cloneDeep(freshBlock) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this part necessary?
| await task.ask("tool", partialMessage, block.partial).catch(() => {}) | ||
|
|
||
| if (newContent) { | ||
| // Only create the file and start streaming when the path has stabilized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're waiting to stream until the path stabilizes, do we still need the setRelPath?
| * | ||
| * The issue was that during streaming, partial-json parsing could produce truncated | ||
| * values (e.g., path "sr" instead of "src/core/prompts/sections/skills.ts"). | ||
| * These truncated values would be cloned by presentAssistantMessage before the | ||
| * final tool_call_end event updated the array with correct data. | ||
| * | ||
| * The fix ensures that for non-partial tool_use blocks, we re-read from | ||
| * assistantMessageContent to get the final data, not stale partial data. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is 100% accurate - we just want to make sure the path is stable.
| // creating the file. This ensures we have the complete, final path value. | ||
| const pathHasStabilized = this.lastSeenPartialPath !== undefined && this.lastSeenPartialPath === relPath | ||
| this.lastSeenPartialPath = relPath | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just return here if the path hasn't stabilized?
|
Closing in favor of #10415 |
Summary
Fixes ROO-311: write_to_file truncates filenames at special characters before file extension
During streaming, the partial-json library may return truncated string values when chunk boundaries fall mid-value (e.g., 'sr' instead of 'src/core/prompts/sections/skills.ts'). This caused files to be created at incorrect paths.
Changes
src/core/tools/WriteToFileTool.tslastSeenPartialPathtracking to detect path stabilization during streamingsetRelPath()call inexecute()to correct any stale path referenceresetPartialState()to clean up tracking state after tool completionsrc/integrations/editor/DiffViewProvider.tssetRelPath()method to update the relative path without re-opening the diff viewsrc/core/assistant-message/presentAssistantMessage.tsHow It Works
During streaming, the partial-json library may return truncated string values when chunk boundaries fall mid-value. The fix waits until the path stops changing between consecutive partial blocks before creating the file, ensuring we have the complete final path value.
Testing
presentAssistantMessage-stale-data.spec.ts(5 tests)writeToFileTool.spec.tsto account for path stabilization behaviorFixes ROO-311
Important
Fixes path truncation in
write_to_fileduring streaming by ensuring file creation only when paths stabilize, with updates inWriteToFileTool.ts,presentAssistantMessage.ts, andDiffViewProvider.ts.WriteToFileTool.tsby trackinglastSeenPartialPathand ensuring file creation only when paths stabilize.presentAssistantMessage.tsto re-read block data for non-partialtool_useblocks to ensure final data usage.setRelPath()inDiffViewProvider.tsto update paths without reopening views.presentAssistantMessage-stale-data.spec.tswith 5 new tests for path stabilization and data re-reading.writeToFileTool.spec.tsto test directory creation and content streaming after path stabilization.resetPartialState()inWriteToFileTool.tsto clear tracking state after execution or error.This description was created by
for 93f4fed. You can customize this summary. It will automatically update as commits are pushed.