{"record":{"id":"10a0346bde42a498","repo":"n8n-io/n8n","slug":"file-too-large-stat-size-bytes-max-max-file","errorCode":null,"errorMessage":"File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use write_file to replace the entire content.","messagePattern":"File too large: (.+?) bytes \\(max (.+?) bytes\\)\\. Use write_file to replace the entire content\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/@n8n/computer-use/src/tools/filesystem/edit-file.ts","lineNumber":33,"sourceCode":"export const editFileTool: ToolDefinition<typeof inputSchema> = {\n\tname: 'edit_file',\n\tdescription:\n\t\t'Apply a targeted search-and-replace to a file. Replaces the first occurrence of oldString with newString. Fails if oldString is not found.',\n\tinputSchema,\n\tannotations: {},\n\tasync getAffectedResources({ filePath }, { dir }) {\n\t\treturn [\n\t\t\tawait buildFilesystemResource(dir, filePath, 'filesystemRead', `Read file: ${filePath}`),\n\t\t\tawait buildFilesystemResource(dir, filePath, 'filesystemWrite', `Edit file: ${filePath}`),\n\t\t];\n\t},\n\tasync execute({ filePath, oldString, newString }, { dir }) {\n\t\tconst resolvedReadablePath = await resolveReadablePath(dir, filePath);\n\t\tconst resolvedWritablePath = await resolveSafePath(dir, filePath);\n\n\t\tconst stat = await fs.stat(resolvedReadablePath);\n\t\tif (stat.size > MAX_FILE_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use write_file to replace the entire content.`,\n\t\t\t);\n\t\t}\n\n\t\tconst content = await fs.readFile(resolvedReadablePath, 'utf-8');\n\n\t\tif (!content.includes(oldString)) {\n\t\t\tthrow new Error(`oldString not found in file: ${filePath}`);\n\t\t}\n\n\t\tawait fs.writeFile(resolvedWritablePath, content.replace(oldString, newString), 'utf-8');\n\n\t\treturn formatCallToolResult({ path: filePath });\n\t},\n};\n","sourceCodeStart":15,"sourceCodeEnd":49,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/computer-use/src/tools/filesystem/edit-file.ts#L15-L49","documentation":"Thrown by the edit_file tool when the target file's size exceeds MAX_FILE_SIZE (1,048,576 bytes = 1 MB, defined in constants.ts). The guard runs after resolving the path but before reading the file content, preventing large files from being loaded into memory. The message suggests using write_file to replace the entire content instead.","triggerScenarios":"Calling edit_file on a file larger than 1 MB — a large data file (JSON/CSV export), a minified JavaScript bundle, a log file, or a large generated source file.","commonSituations":"Agent attempts to edit a large generated file, a minified production bundle, a data export, or a compiled output.","solutions":["Use write_file to replace the entire file content instead of editing in place","Use search_files to locate the specific content, then write_file with the full updated content","Split the large file into smaller modules if ongoing edits are needed"],"exampleFix":"// before (edit_file fails on a large file):\nawait edit_file({ filePath: 'large-bundle.js', oldString: 'foo', newString: 'bar' });\n\n// after (use write_file for full replacement):\nconst content = await read_file({ filePath: 'large-bundle.js' });\nawait write_file({ filePath: 'large-bundle.js', content: content.replace('foo', 'bar') });","handlingStrategy":"validation","validationCode":"import * as fs from 'node:fs/promises';\nimport { MAX_FILE_SIZE } from './constants';\n\nasync function canEditFile(filePath: string): Promise<boolean> {\n  const stat = await fs.stat(filePath);\n  return stat.size <= MAX_FILE_SIZE;\n}\n\n// Before calling edit_file:\nif (!(await canEditFile(resolvedPath))) {\n  // Use write_file instead\n  const content = await fs.readFile(resolvedPath, 'utf-8');\n  await write_file({ filePath, content: content.replace(oldStr, newStr) });\n}","typeGuard":"function isFileTooLargeError(e: unknown): boolean {\n  return e instanceof Error && e.message.startsWith('File too large:') && e.message.includes('Use write_file');\n}","tryCatchPattern":null,"preventionTips":["Check file size with fs.stat before calling edit_file on unknown files","Use write_file for full content replacement when files are known to be large","Use search_files to locate specific content in large files rather than editing them"],"tags":["filesystem","validation","computer-use"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}