Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 31, 2025

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.ts

  • Added lastSeenPartialPath tracking to detect path stabilization during streaming
  • Only create files when the path has stopped changing between consecutive partial blocks
  • Added setRelPath() call in execute() to correct any stale path reference
  • Added resetPartialState() to clean up tracking state after tool completion

src/integrations/editor/DiffViewProvider.ts

  • Added setRelPath() method to update the relative path without re-opening the diff view

src/core/assistant-message/presentAssistantMessage.ts

  • Re-read fresh block data for non-partial tool_use blocks to ensure we use the final values

How 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

  • All 5041 tests pass
  • New test file: presentAssistantMessage-stale-data.spec.ts (5 tests)
  • Updated existing tests in writeToFileTool.spec.ts to account for path stabilization behavior

Fixes ROO-311


Important

Fixes path truncation in write_to_file during streaming by ensuring file creation only when paths stabilize, with updates in WriteToFileTool.ts, presentAssistantMessage.ts, and DiffViewProvider.ts.

  • Behavior:
    • Fixes path truncation issue in WriteToFileTool.ts by tracking lastSeenPartialPath and ensuring file creation only when paths stabilize.
    • Updates presentAssistantMessage.ts to re-read block data for non-partial tool_use blocks to ensure final data usage.
    • Adds setRelPath() in DiffViewProvider.ts to update paths without reopening views.
  • Testing:
    • Adds presentAssistantMessage-stale-data.spec.ts with 5 new tests for path stabilization and data re-reading.
    • Updates writeToFileTool.spec.ts to test directory creation and content streaming after path stabilization.
  • Misc:
    • Adds resetPartialState() in WriteToFileTool.ts to clear tracking state after execution or error.

This description was created by Ellipsis for 93f4fed. You can customize this summary. It will automatically update as commits are pushed.

…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
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Dec 31, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 31, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The fix for ROO-311 is well-implemented:

  • Path stabilization logic correctly prevents file creation at truncated paths during streaming
  • State management is properly handled with resetPartialState() called in both success and error paths
  • Re-read in presentAssistantMessage ensures fresh data is used for tool execution
  • Test coverage appropriately updated to reflect the new behavior

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 Dec 31, 2025
Comment on lines +103 to +108
if (block.type === "tool_use" && !block.partial) {
const freshBlock = cline.assistantMessageContent[cline.currentStreamingContentIndex]
if (freshBlock && freshBlock.type === "tool_use" && !freshBlock.partial) {
block = cloneDeep(freshBlock)
}
}
Copy link
Collaborator

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
Copy link
Collaborator

@mrubens mrubens Dec 31, 2025

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?

Comment on lines +22 to +30
*
* 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.
*/
Copy link
Collaborator

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

Copy link
Collaborator

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?

@mrubens
Copy link
Collaborator

mrubens commented Dec 31, 2025

Closing in favor of #10415

@mrubens mrubens closed this Dec 31, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Dec 31, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants