{"record":{"id":"9a78724fff2dd0c8","repo":"Mintplex-Labs/anything-llm","slug":"source-file-not-found","errorCode":null,"errorMessage":"Source file not found","messagePattern":"Source file not found","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/models/workspaceParsedFiles.js","lineNumber":126,"sourceCode":"   * @returns {Promise<{ success: boolean, error: string | null, document: import(\"@prisma/client\").workspace_documents | null }>} The result of the operation.\n   */\n  moveToDocumentsAndEmbed: async function (user = null, fileId, workspace) {\n    try {\n      const parsedFile = await this.get({\n        id: parseInt(fileId),\n        ...(user ? { userId: user.id } : {}),\n        workspaceId: workspace.id,\n      });\n      if (!parsedFile) throw new Error(\"File not found\");\n\n      // Get file location from metadata\n      const metadata = safeJsonParse(parsedFile.metadata, {});\n      const location = metadata.location;\n      if (!location) throw new Error(\"No file location in metadata\");\n\n      // Get file from metadata location\n      const sourceFile = path.join(directUploadsPath, path.basename(location));\n      if (!fs.existsSync(sourceFile)) throw new Error(\"Source file not found\");\n\n      // Move to custom-documents\n      const customDocsPath = path.join(documentsPath, \"custom-documents\");\n      if (!fs.existsSync(customDocsPath))\n        fs.mkdirSync(customDocsPath, { recursive: true });\n\n      // Copy the file to custom-documents\n      const targetPath = path.join(customDocsPath, path.basename(location));\n      fs.copyFileSync(sourceFile, targetPath);\n      fs.unlinkSync(sourceFile);\n\n      const {\n        failedToEmbed = [],\n        errors = [],\n        embedded = [],\n      } = await Document.addDocuments(\n        workspace,\n        [`custom-documents/${path.basename(location)}`],","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/models/workspaceParsedFiles.js#L108-L144","documentation":"Thrown when the file named by metadata.location no longer exists under the direct-uploads storage directory: the code joins directUploadsPath with path.basename(location) and checks fs.existsSync before copying. The bytes were expected at upload time but vanished before the move-to-documents step. Caught internally and returned as { success: false, error, document: null }.","triggerScenarios":"STORAGE_DIR changed or the storage folder moved between upload and embed; the container/pod was recreated without the storage volume; a cleanup job (tmp cleaner, cron) deleted the upload; multi-node deployments where the worker lacks the shared volume.","commonSituations":"Ephemeral container filesystems (no mounted volume for /app/storage or STORAGE_DIR); Kubernetes pods without PVCs; sysadmin tmpwatch hitting the uploads directory; storage migrated to a new path while old rows still point to the previous layout.","solutions":["Make the storage directory persistent and identical across restarts (mount the volume, keep STORAGE_DIR stable)","Pre-check fs.existsSync(path.join(directUploadsPath, path.basename(location))) before calling","Re-upload the file if the bytes are gone","On multi-node setups, put direct uploads on shared storage reachable by every worker"],"exampleFix":"# before - storage lost on every recreate\ndocker run -p 3001:3001 mintplexlabs/anythingllm\n\n# after - persist the storage directory\ndocker run -p 3001:3001 -v anythingllm_storage:/app/storage mintplexlabs/anythingllm","handlingStrategy":"validation","validationCode":"const location = safeJsonParse(parsed.metadata, {}).location;\nconst sourceFile = path.join(directUploadsPath, path.basename(location));\nif (!fs.existsSync(sourceFile)) {\n  return res.status(410).json({ error: \"Source file missing from storage - re-upload\" });\n}","typeGuard":null,"tryCatchPattern":"const { success, error } = await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);\nif (!success && /Source file not found/i.test(error)) {\n  // storage drifted: verify STORAGE_DIR / volume mounts before retrying with a new upload\n}","preventionTips":["Keep uploads on persistent storage mounted at the same STORAGE_DIR everywhere","Exclude the direct-uploads directory from tmp cleaners","On multi-node deployments, use shared storage for uploads"],"tags":["filesystem","file","storage","workspace"],"backgroundTag":"file-not-found","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}