Budibase/budibase · error · HTTPError

Agent file storage not found

Error message

Agent file storage not found

What it means

Thrown by deleteFileForAgent after ownership passes but knowledgeBaseSdk.find() cannot locate the knowledge base referenced by the file. The file is still blocked from deletion because its parent storage entity is gone or unreadable.

Source

Thrown at packages/server/src/sdk/workspace/ai/rag/files.ts:384

}

export const deleteFileForAgent = async (
  agentId: string,
  fileId: string
): Promise<void> => {
  const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
  const fileKnowledgeBaseId = file.knowledgeBaseId
  if (!fileKnowledgeBaseId) {
    throw new HTTPError("Invalid knowledge base file id", 400)
  }
  const knowledgeBaseIds = await getKnowledgeBaseIdsForAgent(agentId)
  if (!knowledgeBaseIds.includes(fileKnowledgeBaseId)) {
    throw new HTTPError("File does not belong to this agent", 404)
  }

  const knowledgeBase = await knowledgeBaseSdk.find(fileKnowledgeBaseId)
  if (!knowledgeBase) {
    throw new HTTPError("Agent file storage not found", 404)
  }
  await knowledgeBaseSdk.removeKnowledgeBaseFile(knowledgeBase, file)
}

export const getFileUrlForAgent = async (
  agentId: string,
  fileId: string
): Promise<string> => {
  const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
  const fileKnowledgeBaseId = file.knowledgeBaseId
  if (!fileKnowledgeBaseId) {
    throw new HTTPError("Invalid knowledge base file id", 400)
  }

  const knowledgeBaseIds = await getKnowledgeBaseIdsForAgent(agentId)
  if (!knowledgeBaseIds.includes(fileKnowledgeBaseId)) {
    throw new HTTPError("File does not belong to this agent", 404)
  }

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Check whether the knowledge base still exists in this workspace before attempting deletion
  2. Clean up orphaned file records whose parent knowledge base no longer exists
  3. Re-create the knowledge base or use an admin cleanup routine to purge stale file records

Example fix

// before
await deleteFileForAgent(agentId, fileId) // 404 if KB was deleted
// after
const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
const kb = file.knowledgeBaseId ? await knowledgeBaseSdk.find(file.knowledgeBaseId) : null
if (!kb) {
  // KB gone - purge the orphaned file record via admin/cleanup API instead
} else {
  await deleteFileForAgent(agentId, fileId)
}
Defensive patterns

Strategy: validation

Validate before calling

const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
const kb = file.knowledgeBaseId ? await knowledgeBaseSdk.find(file.knowledgeBaseId) : null
if (!kb) throw new Error(`Parent knowledge base for ${fileId} no longer exists`)

Type guard

const kbExists = async (fileId: string): Promise<boolean> => {
  const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
  return !!file.knowledgeBaseId && !!(await knowledgeBaseSdk.find(file.knowledgeBaseId))
}

Try / catch

try {
  await deleteFileForAgent(agentId, fileId)
} catch (err) {
  if (err instanceof HTTPError && err.status === 404) {
    // parent KB missing - route to orphaned-record cleanup
  } else throw err
}

Prevention

When it happens

Trigger: Calling deleteFileForAgent when the file's knowledgeBaseId points to a knowledge base that was deleted or exists in a different workspace.

Common situations: A knowledge base deleted out-of-band while files remained, cross-workspace ID reuse, or eventual consistency after deletion.

Related errors


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