{"record":{"id":"18bfabb835f2601e","repo":"Budibase/budibase","slug":"agent-log-detail-not-found-18bfab","errorCode":null,"errorMessage":"Agent log detail not found","messagePattern":"Agent log detail not found","errorType":"http","errorClass":"HTTPError","httpStatus":404,"severity":"warning","filePath":"packages/server/src/sdk/workspace/ai/agentLogs/shared.ts","lineNumber":314,"sourceCode":"\n  throw new HTTPError(\"Invalid environment query\", 400)\n}\n\nexport function getLiteLLMRequestUser(\n  data: LiteLLMRequestDetail | AgentLogSessionIndexDoc\n): string | undefined {\n  if (\"proxy_server_request\" in data || \"end_user\" in data || \"user\" in data) {\n    return data.proxy_server_request?.user || data.end_user || data.user\n  }\n  return undefined\n}\n\nexport function validateLiteLLMRequestOwnership(\n  agentId: string,\n  data: LiteLLMRequestDetail\n) {\n  if (getLiteLLMRequestUser(data) !== getExpectedEndUser(agentId)) {\n    throw new HTTPError(\"Agent log detail not found\", 404)\n  }\n}\n","sourceCodeStart":296,"sourceCodeEnd":317,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agentLogs/shared.ts#L296-L317","documentation":"validateLiteLLMRequestOwnership enforces that a fetched LiteLLM request detail actually belongs to the given agent by comparing the request's end user (proxy_server_request.user / end_user / user) with the expected `bb-agent:<agentId>` value. On mismatch it throws HTTPError(\"Agent log detail not found\", 404) — deliberately a 404, not 403, to avoid leaking the existence of other agents' log entries.","triggerScenarios":"Looking up a LiteLLM request detail whose user field does not equal `bb-agent:<agentId>` — e.g. querying another agent's request ID, a request with no end-user metadata, or a stale/mismatched agentId.","commonSituations":"A UI passes the wrong agentId in the route while showing another agent's log entry; LiteLLM records lack end_user tagging (older LiteLLM version or missing litellm user config); cross-workspace access attempts.","solutions":["Verify the agentId in the request path matches the agent that made the LiteLLM call","Ensure LiteLLM requests are tagged with the bb-agent:<agentId> end user when sent","Confirm the request detail source (LiteLLM proxy) actually stores the user metadata; check getLiteLLMRequestUser extraction","Catch the 404 and show a not-found view rather than retrying with the same IDs"],"exampleFix":"// before\nconst detail = await fetchLiteLLMRequestRaw(requestId)\nvalidateLiteLLMRequestOwnership(agentId, detail) // 404 if agent mismatch\n// after\nconst expected = `bb-agent:${agentId}`\nconst user = detail.proxy_server_request?.user || detail.end_user || detail.user\nif (user !== expected) {\n  throw new HTTPError(\"Agent log detail not found\", 404)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isOwnedByAgent(agentId: string, data: LiteLLMRequestDetail): boolean {\n  const user = data.proxy_server_request?.user || data.end_user || data.user\n  return user === `bb-agent:${agentId}`\n}","tryCatchPattern":"try {\n  validateLiteLLMRequestOwnership(agentId, detail)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 404) {\n    // render not-found: the request belongs to another agent or lacks user metadata\n  }\n}","preventionTips":["Always tag LiteLLM calls with end user bb-agent:<agentId>","Confirm agentId in the route matches the agent whose logs you are viewing","Check LiteLLM version/proxy config stores proxy_server_request.user metadata"],"tags":["authorization","ownership-check","http-404","agent-logs"],"backgroundTag":"resource-ownership-mismatch","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}