Skip to content

fix: progressive error for write_to_file missing content to break retry loops#11909

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/write-to-file-missing-content-progressive-error
Draft

fix: progressive error for write_to_file missing content to break retry loops#11909
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/write-to-file-missing-content-progressive-error

Conversation

@roomote-v0
Copy link
Contributor

@roomote-v0 roomote-v0 bot commented Mar 11, 2026

Related GitHub Issue

Closes: #11861

Description

This PR attempts to address Issue #11861, adapting the approach from cline/cline#9276 for Roo Code. Feedback and guidance are welcome.

Problem: When the model's output is truncated (due to output token limits or high context usage), write_to_file tool calls arrive with an empty content parameter. The current error handler returns a generic "Missing value for required parameter content. Please retry with complete response." which the model interprets literally and retries identically, creating an infinite retry loop.

Solution: Replace the generic missing parameter error for write_to_file content with a progressive, tiered error message system:

  • Tier 1 (first failure): Helpful suggestions -- use apply_diff/edit, break into smaller steps, write a skeleton first
  • Tier 2 (second failure): Stronger guidance -- must use a different strategy, do NOT retry full write
  • Tier 3 (third+ failure): Critical stop -- do NOT retry write_to_file, required actions listed

The error also includes context window awareness -- when context usage exceeds 50%, the message warns the model that output capacity is reduced.

Changes

  • src/core/prompts/responses.ts -- Added writeToFileMissingContentError(relPath, failureCount, contextUsagePercent?) with tiered progressive guidance
  • src/core/tools/WriteToFileTool.ts -- Replaced generic sayAndCreateMissingParamError for missing content with the new specialized error, computing context window usage from API metrics
  • src/core/prompts/__tests__/writeToFileMissingContentError.spec.ts -- 21 unit tests covering all tiers and context window awareness
  • src/core/tools/__tests__/writeToFileTool.spec.ts -- Updated mocks to support the new error path

Test Procedure

cd src && npx vitest run core/prompts/__tests__/writeToFileMissingContentError.spec.ts
cd src && npx vitest run core/tools/__tests__/writeToFileTool.spec.ts

All 45 tests passing (21 new + 24 existing).

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue
  • Scope: Changes are focused on the linked issue
  • Self-Review: I have performed a thorough self-review of my code
  • Testing: New and updated tests have been added to cover changes
  • Documentation Impact: No documentation updates required
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines

Documentation Updates

  • No documentation updates are required.

Additional Notes

This adapts the approach from cline/cline#9276 for Roo Code, using Roo's tool names (apply_diff, edit) instead of Cline's (replace_in_file) and integrating with Roo's existing getApiMetrics utility and Task architecture.

Interactively review PR in Roo Code Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] write_to_file tool, if issue, creates shell scripts (not ideal)

1 participant