{"record":{"id":"518bfdff0afdaf2d","repo":"Budibase/budibase","slug":"knowledge-source-downloads-are-disabled-for-this-o","errorCode":null,"errorMessage":"Knowledge source downloads are disabled for this operation","messagePattern":"Knowledge source downloads are disabled for this operation","errorType":"http","errorClass":"HTTPError","httpStatus":403,"severity":"warning","filePath":"packages/server/src/api/controllers/ai/files.ts","lineNumber":275,"sourceCode":"  >\n) {\n  const { agentId, operationId, fileId } = ctx.params\n  await sdk.ai.rag.deleteFileForOperation(agentId, operationId, fileId)\n  ctx.body = { deleted: true }\n  ctx.status = 200\n}\n\nexport async function fetchAgentFileUrl(\n  ctx: UserCtx<\n    void,\n    FetchAgentFileUrlResponse,\n    { agentId: string; operationId: string; fileId: string }\n  >\n) {\n  const { agentId, operationId, fileId } = ctx.params\n  const agent = await sdk.ai.agents.getOrThrow(agentId)\n  if (!allowsKnowledgeSourceDownload(agent, operationId)) {\n    throw new HTTPError(\n      \"Knowledge source downloads are disabled for this operation\",\n      403\n    )\n  }\n  const url = await sdk.ai.rag.getFileUrlForOperation(\n    agentId,\n    operationId,\n    fileId\n  )\n  ctx.body = { url }\n  ctx.status = 200\n}\n\nexport async function fetchAgentKnowledgeSourceOptions(\n  ctx: UserCtx<\n    void,\n    FetchAgentKnowledgeSourceOptionsResponse,\n    { datasourceId: string; authConfigId: string }","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/files.ts#L257-L293","documentation":"Thrown by fetchAgentFileUrl with HTTP 403 when allowsKnowledgeSourceDownload indicates the agent's operation is not permitted to download knowledge source files. This is a policy check on the agent config, not an authentication failure.","triggerScenarios":"Requesting a download URL for an operation whose configuration has knowledge source downloads disabled; using a stale operationId after the agent's operations were edited; calling the endpoint for an operation type that never allows downloads.","commonSituations":"UI exposing download buttons without checking the operation's download capability; clients caching agent config and hitting the endpoint after an admin disabled downloads; automation scripts assuming downloads are always allowed.","solutions":["Enable knowledge source downloads for the operation in the agent configuration.","Check the agent's operation config (via sdk.ai.agents.getOrThrow or the API) before exposing download actions.","Re-fetch the agent to ensure the operationId is current.","Handle 403 distinctly from 404 in client error handling (policy vs not-found)."],"exampleFix":"// before\nconst { url } = await api.getAgentFileUrl(agentId, operationId, fileId)\n// after\nconst agent = await api.getAgent(agentId)\nif (!agent.operations.find(op => op.id === operationId)?.knowledgeSourceDownloadEnabled) return null\nconst { url } = await api.getAgentFileUrl(agentId, operationId, fileId)","handlingStrategy":"validation","validationCode":"const agent = await api.getAgent(agentId)\nconst op = agent.operations?.find(op => op.id === operationId)\nif (!op?.knowledgeSourceDownloadEnabled) throw new Error(\"downloads disabled for this operation\")","typeGuard":"function canDownload(agent, operationId) {\n  return Boolean(agent?.operations?.some(op => op.id === operationId && op.knowledgeSourceDownloadEnabled))\n}","tryCatchPattern":"try {\n  const { url } = await api.getAgentFileUrl(agentId, operationId, fileId)\n} catch (err) {\n  if (err.status === 403) {\n    // enable knowledge source download for the operation or hide the UI action\n  } else throw err\n}","preventionTips":["Enable knowledge-source download in the operation's configuration before exposing download links.","Check the agent's operation config before rendering download buttons.","Distinguish 403 (policy) from 404 (wrong fileId) in client error handling.","Keep operation IDs current; stale IDs after agent edits can fail the policy check."],"tags":["http-403","authorization","permissions","knowledge-base"],"backgroundTag":"operation-not-permitted","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}