Budibase/budibase · error · Error
escalation gate: missing workspace context
Error message
escalation gate: missing workspace context
What it means
The escalation gate runtime needs to know which workspace (app) the escalation approval card belongs to. It reads the workspace ID from the ambient request context; when the context has no workspace ID it cannot scope the approval, so it throws a plain Error before building the card. This is an internal invariant failure: the SDK is being used outside a properly established workspace context.
Source
Thrown at packages/server/src/sdk/workspace/ai/agents/escalationGate.ts:116
const rule = matchRule(rules)
if (!rule) {
return unavailableResult(label)
}
const policy = resolvePolicy(operation, rule.policyId)
const notifications: AgentEscalationConfig | undefined =
policy?.notifications
if (!policy || !notifications?.recipients?.length) {
return unavailableResult(label)
}
const frozenMessages = messages?.length
? messages
: gateContext.getMessages()
const appId = context.getWorkspaceId()
const tenantId = context.getTenantId()
if (!appId) {
throw new Error("escalation gate: missing workspace context")
}
let title = `Approval required: ${label}`
let summary = summariseArgs(label, input)
try {
const copy = await gateContext.generateCardCopy?.({
label,
args: input,
})
if (copy?.title && copy?.summary) {
title = copy.title
summary = copy.summary
}
} catch (error) {
console.warn("escalation gate: card copy generation failed", {
toolName,
error: error instanceof Error ? error.message : String(error),
})View on GitHub (pinned to a81a902e9a)
Solutions
- Ensure the escalation gate is invoked within a request/job that has a workspace context set (context.withContext / the server API routes).
- Verify the agent run path passes the app ID so getWorkspaceId() resolves; do not call the SDK raw in worker jobs without context.
- If writing tests, set up a workspace context middleware/helper before calling the gate runtime.
Example fix
// before
await gateRuntime.run(...) // called outside any workspace context
// after
await context.doInWorkspaceContext(appId, async () => {
await gateRuntime.run(...)
}) Defensive patterns
Strategy: validation
Validate before calling
import context from "@budibase/backend-core/context"
const canRun = () => !!context.getWorkspaceId()
if (!canRun()) throw new Error("Call must run inside a workspace context") Type guard
const hasWorkspaceContext = (): boolean => typeof context.getWorkspaceId() === "string" && context.getWorkspaceId().length > 0
Try / catch
try {
await gateRuntime.run(...)
} catch (err) {
if ((err as Error).message === "escalation gate: missing workspace context") {
// re-invoke inside a workspace context or fail the run with a clear message
}
} Prevention
- Only invoke agent SDK runtimes from request/job handlers that install workspace context.
- Add a startup assertion in scripts/tests that a workspace context wrapper is used.
- Never call gate runtimes at module top-level.
When it happens
Trigger: Calling createEscalationGateRuntime (e.g. during an agent run that hits an escalation-enabled operation) when context.getWorkspaceId() returns undefined - typically when the agent is invoked outside an HTTP request scoped to an app, or in a job/test with no workspace context installed.
Common situations: Running agent escalations from background scripts, automation triggers, or tests without wrapping the call in a workspace context; calling the SDK directly rather than through the server API routes that install the context.
Related errors
- Agent execution context is required
- Agent not found
- Operation not found
- workspaceId is required
- Invalid Teams app package version
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/097663bb95058501.
Report an issue: GitHub.