You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: detect and handle truncated write_to_file operations for large files
- Add detection for files >7000 lines when line_count is missing
- Add validation to compare actual vs predicted line count with 10% tolerance
- Provide clear error messages when truncation is detected
- Add comprehensive tests for large file handling
Fixes#6247
`The file content appears to be very large (${actualLineCount} lines). The assistant may have reached its output limit and the content could be truncated. Please verify the file is complete or consider using a different approach for large files.`,
86
+
)
87
+
88
+
pushToolResult(
89
+
formatResponse.toolError(
90
+
`Large file detected (${actualLineCount} lines). The content may be truncated due to output limits. Consider breaking the file into smaller chunks or using a different approach.`,
91
+
),
92
+
)
93
+
awaitcline.diffViewProvider.reset()
94
+
return
95
+
}
96
+
74
97
// pre-processing newContent for cases where weaker models might add artifacts like markdown codeblock markers (deepseek/llama) or extra escape characters (gemini)
75
98
if(newContent.startsWith("```")){
76
99
// cline handles cases where it includes language specifiers like ```python ```js
@@ -147,6 +170,42 @@ export async function writeToFileTool(
`Content appears to be truncated. The file should have ${predictedLineCount} lines but only ${actualLineCount} lines were provided. This often happens when files exceed ~7000 lines due to output token limits. Consider using apply_diff for large file modifications or breaking the content into smaller chunks.`,
195
+
),
196
+
)
197
+
}else{
198
+
pushToolResult(
199
+
formatResponse.toolError(
200
+
`Line count mismatch: expected ${predictedLineCount} lines but got ${actualLineCount} lines. Please verify the content is complete.`,
201
+
),
202
+
)
203
+
}
204
+
205
+
awaitcline.diffViewProvider.revertChanges()
206
+
return
207
+
}
208
+
150
209
cline.consecutiveMistakeCount=0
151
210
152
211
// if isEditingFile false, that means we have the full contents of the file already.
0 commit comments