{"record":{"id":"fa786d537eb0ce95","repo":"n8n-io/n8n","slug":"file-input-path-is-not-loaded-fa786d","errorCode":null,"errorMessage":"File \"${input.path}\" is not loaded.","messagePattern":"File \"(.+?)\" is not loaded\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@n8n/agents/src/workspace/tools/str-replace-file.ts","lineNumber":52,"sourceCode":"\t\t)\n\t\t.input(inputSchema)\n\t\t.output(outputSchema)\n\t\t.handler(async (input, ctx) => {\n\t\t\ttry {\n\t\t\t\tconst content = await filesystem.readFile(input.path, {\n\t\t\t\t\tencoding: 'utf-8',\n\t\t\t\t\tabortSignal: ctx.abortSignal,\n\t\t\t\t});\n\t\t\t\tconst editor = new TextEditorDocument({ initialText: content.toString() });\n\t\t\t\tconst result = editor.execute({\n\t\t\t\t\tcommand: 'str_replace',\n\t\t\t\t\tpath: input.path,\n\t\t\t\t\told_str: input.old_str,\n\t\t\t\t\tnew_str: input.new_str,\n\t\t\t\t});\n\t\t\t\tconst editedContent = editor.getText();\n\t\t\t\tif (editedContent === null) {\n\t\t\t\t\tthrow new Error(`File \"${input.path}\" is not loaded.`);\n\t\t\t\t}\n\n\t\t\t\tawait filesystem.writeFile(input.path, editedContent, {\n\t\t\t\t\toverwrite: true,\n\t\t\t\t\tabortSignal: ctx.abortSignal,\n\t\t\t\t});\n\t\t\t\treturn { success: true, result };\n\t\t\t} catch (error) {\n\t\t\t\tif (isAbortError(error)) throw error;\n\t\t\t\treturn createErrorOutput(error);\n\t\t\t}\n\t\t})\n\t\t.build();\n}\n","sourceCodeStart":34,"sourceCodeEnd":67,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/agents/src/workspace/tools/str-replace-file.ts#L34-L67","documentation":"In the str-replace-file tool, after readFile sets initialText and editor.execute() runs the 'str_replace' command, getText() must return the edited string. If it returns null the document is somehow unloaded — an invariant violation of TextEditorDocument that is not reachable in normal flow (initialText was just provided). The throw prevents writing `null` to the file.","triggerScenarios":"Not reachable in normal use — initialText is set from the file content immediately before. Would only fire on a TextEditorDocument regression where execute() clears the buffer, or if the editor instance is shared/concurrently mutated.","commonSituations":"A bug in TextEditorDocument.execute() that nulls internal state; reusing one editor across files; future refactor breaking the loaded-text invariant.","solutions":["Report as an internal bug in @n8n/agents with the path and old_str/new_str.","Retry with a fresh TextEditorDocument instance.","Confirm old_str actually exists in the file — a no-op match shouldn't null the buffer, but verify the editor version is current."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await strReplaceFile(...);\n} catch (e) {\n  if (e instanceof Error && /is not loaded/.test(e.message)) {\n    // internal invariant — retry with a fresh TextEditorDocument\n  } else throw e;\n}","preventionTips":["Treat 'is not loaded' as an internal bug — report it with path + old_str/new_str.","Don't share a TextEditorDocument instance across operations.","Verify old_str exists in the file before calling."],"tags":["tools","text-editor","invariant","agents"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}