Budibase/budibase · error · Error
workspaceId is required
Error message
workspaceId is required
What it means
enqueueRequestTracking only runs request tracking for production workspaces, and afterwards requires a workspace id from the request context in order to enqueue the tracking job. If context.getWorkspaceId() returns falsy (no workspace/app context on the request) the guard throws this plain Error rather than silently skipping tracking.
Source
Thrown at packages/server/src/sdk/workspace/ai/agentRequests/queue.ts:121
role: "user" | "assistant"
content: string
}>
operation?: {
name: string
prompt: string
}
userId: string
existingRequestId?: string
}) {
if (!(await features.isEnabled(FeatureFlag.AI_AGENT_ACTIVITY))) {
return
}
if (!context.isProdWorkspace()) {
return
}
const workspaceId = context.getWorkspaceId()
if (!workspaceId) {
throw new Error("workspaceId is required")
}
await enqueue({
workspaceId,
agentId,
sessionId,
latestUserPrompt,
recentChatContext,
operation,
source: determineTrigger(sessionId),
userId,
existingRequestId,
})
}
View on GitHub (pinned to a81a902e9a)
Solutions
- Ensure the caller runs inside a workspace-scoped context (e.g. context.withWorkspace / the Koa workspace middleware) before invoking startAgentRequestTracking
- Check getWorkspaceId() yourself before calling and skip/short-circuit tracking when absent if tracking is best-effort
- In tests, set up the workspace context fixture the same way server request tests do
- Confirm isProdWorkspace() and getWorkspaceId() derive from the same context state — a mismatch means context was partially initialized
Example fix
// before
await startAgentRequestTracking({ agentId, sessionId, prompt })
// after
await context.doInWorkspaceContext(workspaceId, () =>
startAgentRequestTracking({ agentId, sessionId, prompt })
) Defensive patterns
Strategy: validation
Validate before calling
import context from "@budibase/backend-core/context"
const workspaceId = context.getWorkspaceId()
if (!workspaceId) {
// skip or defer tracking; do not call enqueueRequestTracking
} Try / catch
try {
await startAgentRequestTracking({...})
} catch (err) {
if (err.message === "workspaceId is required") {
// request ran outside a workspace context; tracking is best-effort
} else { throw err }
} Prevention
- Always call tracking helpers inside workspace-scoped context (middleware or context.withWorkspace)
- In tests, set up workspace context fixtures before invoking
- Remember tracking only applies to prod workspaces; dev workspaces return early
When it happens
Trigger: Calling enqueueRequestTracking (directly or via startAgentRequestTracking) from a context where isProdWorkspace() is true but getWorkspaceId() returns undefined — i.e. a request scoped to no workspace, or context not initialized (e.g. running outside an HTTP request, background job, script, or tests without setContext).
Common situations: Calling the tracking helper in a unit/integration test without wrapping in context.withWorkspace; an automation or cron job lacking workspace context; calling before the context middleware has run; mixing dev/prod workspace checks so the early return no longer applies.
Related errors
- Workspace context is required
- workspaceId is required
- Could not determine workspace for Project import
- Error getting status
- Unable to remove doc without a valid _id and _rev.
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/a1fc3ead8b6cb847.
Report an issue: GitHub.