Budibase/budibase · error · HTTPError
File does not belong to this agent
Error message
File does not belong to this agent
What it means
Thrown by deleteFileForAgent when the file's knowledgeBaseId is not among the knowledge bases linked to the given agent. This is an authorization/tenancy guard preventing an agent from deleting files it does not own.
Source
Thrown at packages/server/src/sdk/workspace/ai/rag/files.ts:379
filename: string
mimetype?: string
size?: number
buffer: Buffer
uploadedBy: string
}
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)
}View on GitHub (pinned to a81a902e9a)
Solutions
- Verify the knowledge base containing the file is actually attached to this agent's operation config
- Re-fetch the agent and its current file list to get valid fileIds
- Use the agentId that actually owns the knowledge base
Example fix
// before await deleteFileForAgent(wrongAgentId, fileId) // 404 // after const agent = await agentsSdk.getOrThrow(agentId) const kbIds = agent.operations?.flatMap(op => (op.knowledgeSources || []).map(s => s.knowledgeBaseId)) || [] // ensure fileId resolves to a knowledge base in kbIds before deleting await deleteFileForAgent(agentId, fileId)
Defensive patterns
Strategy: validation
Validate before calling
const agent = await agentsSdk.getOrThrow(agentId)
const kbIds = (agent.operations || []).flatMap(op => (op.knowledgeSources || []).map(s => s.knowledgeBaseId))
if (!kbIds.length) throw new Error(`Agent ${agentId} owns no knowledge bases`) Type guard
const agentOwnsFile = async (agentId: string, fileId: string): Promise<boolean> => {
const file = await knowledgeBaseSdk.getKnowledgeBaseFileOrThrow(fileId)
const kbIds = await getKnowledgeBaseIdsForAgent(agentId)
return !!file.knowledgeBaseId && kbIds.includes(file.knowledgeBaseId)
} Try / catch
try {
await deleteFileForAgent(agentId, fileId)
} catch (err) {
if (err instanceof HTTPError && err.status === 404) {
// file not owned by this agent - refresh file list before retrying
} else throw err
} Prevention
- Always source fileIds from a fresh fetch of the owning agent
- Never reuse fileIds across agents or workspaces
- Refresh UI file lists after any agent configuration change
When it happens
Trigger: Calling deleteFileForAgent(agentId, fileId) where fileId belongs to a knowledge base attached to a different agent or not attached to any agent.
Common situations: Passing a fileId cached from a previous agent configuration, mixing up IDs between agents, or the knowledge base was detached from the agent after the ID was obtained.
Related errors
- Knowledge source downloads are disabled for this operation
- Tool is not available in this security context
- Slack OAuth authorization failed
- Unsupported file type for knowledge ingestion
- ${error?.message} || Failed to process uploaded file
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/9273efe29fda15dd.
Report an issue: GitHub.