Budibase/budibase · error · HTTPError

Operation not found for this agent

Error message

Operation not found for this agent

What it means

getOperationOrThrow looks up an AgentOperation by id within an agent's operations array. Agents hold knowledge sources and settings per operation; when the given operationId does not match any operation on the agent, the helpers throw a 404 'Operation not found for this agent'. It is used by SharePoint source listing and the knowledge-source download permission check.

Source

Thrown at packages/server/src/api/controllers/ai/files.ts:61

  if (!path) {
    return
  }
  try {
    await unlink(path)
  } catch (error) {
    console.log("Failed to delete temp file", error)
  }
}

const sanitizeSharePointSourceId = (operationId: string, siteId: string) =>
  `sharepoint_site_${operationId.replace(/[^a-zA-Z0-9_-]/g, "_")}_${siteId.replace(/[^a-zA-Z0-9_-]/g, "_")}`

const getOperationOrThrow = (agent: Agent, operationId: string) => {
  const operation = agent.operations?.find(
    operation => operation.id === operationId
  )
  if (!operation) {
    throw new HTTPError("Operation not found for this agent", 404)
  }
  return operation
}

const getSharePointSourcesForOperation = (agent: Agent, operationId: string) =>
  (getOperationOrThrow(agent, operationId).knowledgeSources || []).filter(
    source => source.type === AgentKnowledgeSourceType.SHAREPOINT
  )

const allowsKnowledgeSourceDownload = (agent: Agent, operationId: string) =>
  getOperationOrThrow(agent, operationId).allowKnowledgeSourceDownload

const fetchSharePointOptionsForDatasourceAuthConfig = async (
  datasourceId: string,
  authConfigId: string
): Promise<FetchAgentKnowledgeSourceOptionsResponse> => {
  const options = await fetchSharePointSitesByDatasourceAuthConfig(
    datasourceId,

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Re-fetch the agent (GET agent) and use an id from its operations array.
  2. Verify you are passing operation.id (not knowledge source id or agent id) to the endpoint.
  3. If the operation was deleted/recreated, redo the flow against the new operation id.
  4. Confirm the agent document was fetched from the correct workspace/app context.
  5. Refresh stale client caches after any agent edit in the builder.

Example fix

// before
const opId = cachedOperationId
await api.get(`/api/agents/${agentId}/operations/${opId}/sharepoint/sources`)
// after
const agent = (await api.get(`/api/agents/${agentId}`)).data
const opId = agent.operations?.[0]?.id
if (!opId) return
await api.get(`/api/agents/${agentId}/operations/${opId}/sharepoint/sources`)
Defensive patterns

Strategy: type-guard

Validate before calling

const op = agent.operations?.find(o => o.id === operationId)
if (!op) throw new Error(`Operation ${operationId} not on agent ${agent._id}; refresh agent and pick a valid id`)

Type guard

const hasOperation = (agent: Agent, operationId: string): operationId is string =>
  Boolean(agent.operations?.some(o => o.id === operationId))

Try / catch

try {
  await api.get(`/api/agents/${agentId}/operations/${operationId}/sharepoint/sources`)
} catch (e) {
  if (e.status === 404 && e.message.includes("Operation not found")) {
    const agent = (await api.get(`/api/agents/${agentId}`)).data
    // re-resolve operationId from agent.operations and retry once
  }
}

Prevention

When it happens

Trigger: GET/POST agent files endpoints (SharePoint sources for an operation, download-allowed check) with an operationId that is not in agent.operations — e.g. the operation was deleted, renamed/re-created with a new id, the agent record is stale, or the caller passes a knowledge-source id instead of an operation id.

Common situations: Client caches an operation id from before the agent was edited; agent updated in the builder while a UI tab still references the old operation; confusing operation ids with knowledge source ids or agent ids; agent document fetched from a different workspace than the operation belongs to.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/8a9a015273e9b8ac. Report an issue: GitHub.