{"record":{"id":"8b12a3c99cc2331b","repo":"Budibase/budibase","slug":"failed-to-create-operation-file-storage","errorCode":null,"errorMessage":"Failed to create operation file storage","messagePattern":"Failed to create operation file storage","errorType":"http","errorClass":"HTTPError","httpStatus":500,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/rag/files.ts","lineNumber":210,"sourceCode":"  return (\n    await Promise.all(\n      knowledgeBaseIds.map(id => knowledgeBaseSdk.listKnowledgeBaseFiles(id))\n    )\n  ).flat()\n}\n\nexport const uploadFileForOperation = async (\n  agentId: string,\n  operationId: string,\n  input: UploadKnowledgeFileInput\n): Promise<KnowledgeBaseFile> => {\n  const knowledgeBase = await ensureKnowledgeBaseForOperation(\n    agentId,\n    operationId\n  )\n  const knowledgeBaseId = knowledgeBase._id\n  if (!knowledgeBaseId) {\n    throw new HTTPError(\"Failed to create operation file storage\", 500)\n  }\n\n  return await knowledgeBaseSdk.uploadKnowledgeBaseFile({\n    knowledgeBaseId,\n    filename: input.filename,\n    mimetype: input.mimetype,\n    size: input.size ?? input.buffer.byteLength,\n    buffer: input.buffer,\n    uploadedBy: input.uploadedBy,\n  })\n}\n\nexport const deleteFileForOperation = async (\n  agentId: string,\n  operationId: string,\n  fileId: string\n): Promise<void> => {\n  const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/rag/files.ts#L192-L228","documentation":"uploadFileForOperation ensures a knowledge base exists for the agent operation, then uploads the file into it. If the ensured knowledge base comes back without an _id, the SDK cannot target storage, so it throws HTTPError 500 \"Failed to create operation file storage\" — an internal invariant failure meaning storage provisioning silently failed.","triggerScenarios":"Calling uploadFileForOperation when ensureKnowledgeBaseForOperation returns a knowledge base document lacking _id — e.g. the underlying knowledge-base creation call failed or returned an unexpected/empty document.","commonSituations":"Database (CouchDB) write issues during knowledge base creation; provider/backend misconfiguration causing the knowledge base SDK to return a stub; concurrent creation races returning incomplete documents.","solutions":["Check server logs and CouchDB health for failures during knowledge base creation.","Verify the knowledge base backend/provider configuration is correct and the service is reachable.","Retry the upload — creation may have been a transient failure.","If reproducible, inspect ensureKnowledgeBaseForOperation for a path that returns a document without persisting it."],"exampleFix":"// before\nawait uploadFileForOperation(agentId, operationId, input)\n// after\ntry {\n  await uploadFileForOperation(agentId, operationId, input)\n} catch (e) {\n  if (e instanceof HTTPError && e.status === 500) {\n    // log and retry or report knowledge base provisioning failure\n  }\n  throw e\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await uploadFileForOperation(agentId, operationId, input)\n} catch (e) {\n  if (e instanceof HTTPError && e.status === 500 && e.message === \"Failed to create operation file storage\") {\n    // log provisioning failure, retry once, else surface infra error\n  }\n  throw e\n}","preventionTips":["Monitor CouchDB/DB health; provisioning failures usually trace back to it","Retry uploads on 500s — creation may be transient","Verify knowledge base provider configuration in self-hosted setups","Alert on this error since it indicates a backend invariant break, not user error"],"tags":["ai","rag","storage","http-error-500"],"backgroundTag":"knowledge-base-provisioning-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}