{"record":{"id":"e685ed9848e04816","repo":"Budibase/budibase","slug":"escalation-context-doc-not-found-escalationid","errorCode":null,"errorMessage":"Escalation context doc not found: ${escalationId}","messagePattern":"Escalation context doc not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/agentRequests/crud.ts","lineNumber":324,"sourceCode":"      throw err\n    }\n  }\n}\n\nasync function recordEscalationRaised({\n  requestId,\n  sessionId,\n  escalationId,\n}: {\n  requestId: string\n  sessionId: string\n  escalationId: string\n}): Promise<void> {\n  const timestamp = nowIso()\n\n  const doc = await getContextDoc(escalationId)\n  if (!doc) {\n    throw new Error(`Escalation context doc not found: ${escalationId}`)\n  }\n  const recipients = await Promise.all(\n    (doc.recipients ?? []).map(async recipient => ({\n      type: recipient.type,\n      label: await resolveRecipientLabel(recipient),\n    }))\n  )\n\n  await appendAction(\n    requestId,\n    {\n      type: \"escalation_raised\",\n      escalationId,\n      recipients,\n      sessionId,\n    },\n    timestamp\n  )","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/agentRequests/crud.ts#L306-L342","documentation":"recordEscalationRaised loads an escalation context document by ID before recording an escalation-raised action for an agent request. If no document exists for escalationId, it throws Error(`Escalation context doc not found: ${escalationId}`) instead of recording an escalation against missing data.","triggerScenarios":"Calling recordEscalationRaised (via recordToolCall) with an escalationId whose context doc was never created, was already deleted, or belongs to a different workspace DB.","commonSituations":"The escalation context doc expired or was cleaned up before the escalation was recorded; a typo/stale ID passed between automation steps; the doc was written to dev DB but read from prod (or vice versa).","solutions":["Verify the escalation context doc is created before recordEscalationRaised is invoked with its ID","Check you are using the same workspace/environment DB for both the write and read","Catch the error and skip/defer the escalation recording, or recreate the context doc"],"exampleFix":"// before\nconst doc = await getContextDoc(escalationId)\nif (!doc) {\n  throw new Error(`Escalation context doc not found: ${escalationId}`)\n}\n// after\nconst doc = await getContextDoc(escalationId)\nif (!doc) {\n  console.warn(`Skipping escalation ${escalationId}: context doc missing`)\n  return\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await recordEscalationRaised({ requestId, escalationId })\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Escalation context doc not found\")) {\n    // recreate the escalation context doc or skip recording this escalation\n  }\n}","preventionTips":["Create the escalation context doc before raising the escalation and pass that exact ID","Keep write and read in the same workspace/environment DB","Avoid reusing escalation IDs across retries without verifying the doc exists"],"tags":["missing-document","database","agent-requests","escalations"],"backgroundTag":"document-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}