{"record":{"id":"f13cfd53ac6317ee","repo":"Budibase/budibase","slug":"failed-to-create-agent-file-storage","errorCode":null,"errorMessage":"Failed to create agent file storage","messagePattern":"Failed to create agent file storage","errorType":"http","errorClass":"HTTPError","httpStatus":500,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts","lineNumber":772,"sourceCode":"    runAt: lastRunAt,\n    sourceScope,\n  })\n  throwIfSyncAborted(signal)\n\n  if (!sourceDatasourceId || !sourceAuthConfigId) {\n    throw new HTTPError(\"SharePoint is not connected for this workspace\", 400)\n  }\n  const bearerToken = await getSharePointBearerToken(\n    sourceDatasourceId,\n    sourceAuthConfigId\n  )\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 agent file storage\", 500)\n  }\n\n  const existingFiles =\n    await knowledgeBaseSdk.listKnowledgeBaseFiles(knowledgeBaseId)\n  const existingSharePointFilesByExternalId = new Map<\n    string,\n    {\n      fileId: string\n      siteId: string\n      knowledgeSourceId?: string\n      status?: KnowledgeBaseFileStatus\n      etag?: string\n      lastModifiedAt?: string\n      remoteSize?: number\n    }\n  >()\n  for (const file of existingFiles) {\n    const fileId = file._id","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts#L754-L790","documentation":"Before syncing files, the code calls ensureKnowledgeBaseForOperation to create/obtain the knowledge base backing the operation's file storage. If the returned document has no _id, this 500 HTTPError is thrown — creation nominally succeeded but produced no usable identifier, so sync cannot proceed.","triggerScenarios":"ensureKnowledgeBaseForOperation returns a document without _id — e.g. a DB write/creation path returning an unexpected shape, or a race where the KB record exists but is not persisted with an id.","commonSituations":"CouchDB/DB issues during KB creation; concurrent syncs racing to create the same knowledge base; a bug or version mismatch in the knowledge-base SDK; corrupted agent operation records.","solutions":["Retry the sync (may be a transient DB race); if recurring, investigate ensureKnowledgeBaseForOperation","Check server logs and CouchDB for errors around knowledge base creation at that timestamp","Verify the knowledge-base SDK version in use matches the server code","Re-run sync with a single worker to avoid concurrent creation races"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const kb = await ensureKnowledgeBaseForOperation(agentId, operationId)\nif (!kb?._id) {\n  throw new Error(\"Knowledge base creation returned no id\")\n}","typeGuard":"const hasKnowledgeBaseId = (\n  kb: KnowledgeBase | undefined\n): kb is KnowledgeBase & { _id: string } =>\n  typeof kb?._id === \"string\" && kb._id.length > 0","tryCatchPattern":"try {\n  await syncSharePointSourceForAgent(agentId, sourceId)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 500 && err.message.includes(\"agent file storage\")) {\n    // retry once after short backoff, then alert/inspect logs\n  } else { throw err }\n}","preventionTips":["Serialize syncs per agent/operation to avoid concurrent KB creation races","Monitor DB health where knowledge bases are stored","Verify KB SDK versions match server code","Alert on ensureKnowledgeBaseForOperation returning docs without _id"],"tags":["knowledge-base","storage","server-error"],"backgroundTag":"resource-creation-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}