{"record":{"id":"1464a2d6c6116c53","repo":"Budibase/budibase","slug":"operation-not-found-for-this-agent-1464a2","errorCode":null,"errorMessage":"Operation not found for this agent","messagePattern":"Operation not found for this agent","errorType":"http","errorClass":"HTTPError","httpStatus":404,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts","lineNumber":134,"sourceCode":"export const getSharePointFileDedupKey = ({\n  siteId,\n  driveId,\n  itemId,\n}: {\n  siteId: string\n  driveId: string\n  itemId: string\n}) => `${siteId}:${driveId}:${itemId}`\n\nconst getOperationOrThrow = (\n  agent: Agent,\n  operationId: string\n): AgentOperation => {\n  const operation = agent.operations?.find(\n    operation => operation.id === operationId\n  )\n  if (!operation) {\n    throw new HTTPError(\"Operation not found for this agent\", 404)\n  }\n  return operation\n}\n\nconst getSharePointSourcesForOperation = (agent: Agent, operationId: string) =>\n  (getOperationOrThrow(agent, operationId).knowledgeSources || []).filter(\n    source => source.type === \"sharepoint\"\n  )\n\nconst getSharePointSyncRunStatus = (\n  synced: number,\n  failed: number\n): AgentKnowledgeSourceSyncRunStatus => {\n  if (failed === 0) {\n    return AgentKnowledgeSourceSyncRunStatus.SUCCESS\n  }\n  if (synced === 0) {\n    return AgentKnowledgeSourceSyncRunStatus.FAILED","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts#L116-L152","documentation":"Thrown by getOperationOrThrow when the requested operationId does not exist on the given agent's operations array. Used by SharePoint source lookups to ensure the operation belongs to the agent.","triggerScenarios":"Calling getSharePointSourcesForOperation (or fetchSharePointEntriesForOperation) with an operationId that is not present in agent.operations.","commonSituations":"Hardcoded/stale operation IDs, an operation deleted after being saved elsewhere, or mixing operations between agents.","solutions":["Re-fetch the agent and enumerate agent.operations to get a valid operation id","Update any stored operationId references after deleting/re-creating operations","Verify you are passing the id, not a name or index"],"exampleFix":"// before\nawait fetchSharePointEntriesForOperation({ agentId, operationId: staleId }) // 404\n// after\nconst agent = await agentsSdk.getOrThrow(agentId)\nconst opId = agent.operations?.[0]?.id\nif (!opId) throw new Error('Agent has no operations configured')\nawait fetchSharePointEntriesForOperation({ agentId, operationId: opId })","handlingStrategy":"validation","validationCode":"const agent = await agentsSdk.getOrThrow(agentId)\nconst op = agent.operations?.find(o => o.id === operationId)\nif (!op) throw new Error(`Operation ${operationId} not found on agent ${agentId}`)","typeGuard":"const agentHasOperation = (agent: Agent, operationId: string): boolean =>\n  !!agent.operations?.some(o => o.id === operationId)","tryCatchPattern":"try {\n  const entries = await fetchSharePointEntriesForOperation({ agentId, operationId, siteId })\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 404) {\n    // re-fetch agent operations and pick a valid operationId\n  } else throw err\n}","preventionTips":["Always derive operationId from a recent agent fetch, not stored stale values","Update references after operations are deleted or recreated","Distinguish operation ids from names/indices in client code"],"tags":["not-found","agent","operation"],"backgroundTag":"resource-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}