{"record":{"id":"7907ffdc0aa1de7f","repo":"hcengineering/platform","slug":"workspacenotfound-7907ff","errorCode":"WorkspaceNotFound","errorMessage":"WorkspaceNotFound","messagePattern":"WorkspaceNotFound","errorType":"exception","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"server/account/src/serviceOperations.ts","lineNumber":327,"sourceCode":"    message?: string\n  }\n): Promise<void> {\n  const { workspaceUuid, event, version, message } = params\n\n  const { extra } = decodeTokenVerbose(ctx, token)\n  if (!['workspace', 'tool'].includes(extra?.service)) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))\n  }\n\n  if (workspaceUuid == null || workspaceUuid === '' || event == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))\n  }\n\n  let progress = params.progress\n\n  const wsExists = await db.workspace.exists({ uuid: workspaceUuid })\n  if (!wsExists) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUuid }))\n  }\n  progress = Math.round(progress)\n\n  const ts = Date.now()\n  const update: Partial<WorkspaceStatus> = {}\n  const wsUpdate: Partial<Workspace> = {}\n  const query: Query<WorkspaceStatus> = { workspaceUuid }\n\n  // Only read status for certain events because it is not needed for others\n  // and it interferes with status updates when concurrency is high\n  let wsStatus: WorkspaceStatus | null = null\n  if (['create-started', 'upgrade-started', 'migrate-clean-done'].includes(event)) {\n    wsStatus = await db.workspaceStatus.findOne({ workspaceUuid })\n  }\n  switch (event) {\n    case 'create-started':\n      update.mode = 'creating'\n      if (wsStatus != null && wsStatus.mode !== 'creating') {","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/serviceOperations.ts#L309-L345","documentation":"WorkspaceNotFound is thrown by updateWorkspaceInfo when no workspace exists in the account database with the given workspaceUuid. After validating auth and parameters, the service checks db.workspace.exists({ uuid }) and aborts with this status (including the requested workspaceUuid in the error data). The workspace was deleted, never created, or the UUID is wrong/foreign to this deployment.","triggerScenarios":"Calling updateWorkspaceInfo with a workspaceUuid that has no matching workspace row: workspace already deleted, UUID typo'd or from another environment/region, workspace creation rolled back, or stale ID cached by the caller after deletion.","commonSituations":"A tool service continues posting progress events for a workspace removed concurrently by a user; dev/staging UUIDs used against a prod account DB; tests reusing hard-coded workspace UUIDs; migrations or region failover leaving the account DB without the workspace record.","solutions":["Verify the workspaceUuid exists (query db.workspace or a get-workspace API) before sending updates, and skip/ignore updates for missing workspaces.","Check you are calling the correct deployment/database where the workspace was created.","Refresh the workspace ID from the create-workspace response instead of reusing cached values.","Treat this status as terminal in the worker: stop the update loop for that workspace rather than retrying."],"exampleFix":"// before\nawait accountClient.updateWorkspaceInfo(ctx, token, { workspaceUuid, event })\n\n// after\ntry {\n  await accountClient.updateWorkspaceInfo(ctx, token, { workspaceUuid, event })\n} catch (err) {\n  if (err instanceof PlatformError && err.status.code === platform.status.WorkspaceNotFound) {\n    return // workspace gone; drop the update instead of failing\n  }\n  throw err\n}","handlingStrategy":"try-catch","validationCode":"// Check the workspace exists before sending updates\nconst exists = await db.workspace.exists({ uuid: workspaceUuid })\nif (!exists) {\n  log.warn('Skipping update; workspace no longer exists', { workspaceUuid })\n  return\n}","typeGuard":"function isWorkspaceNotFoundError(err: unknown): err is PlatformError<WorkspaceNotFound> {\n  return err instanceof PlatformError && err.status.code === platform.status.WorkspaceNotFound\n}","tryCatchPattern":"try {\n  await updateWorkspaceInfo(ctx, token, { workspaceUuid, event })\n} catch (err) {\n  if (isWorkspaceNotFoundError(err)) {\n    log.warn('Workspace disappeared; dropping update', { workspaceUuid })\n    return\n  }\n  throw err\n}","preventionTips":["Treat WorkspaceNotFound as terminal for per-workspace workers — stop retrying that ID.","Handle concurrent workspace deletion gracefully (check existence or catch the status).","Avoid hard-coded workspace UUIDs in tests/config; always fetch fresh IDs.","Confirm deployment/region so the UUID is checked against the same account DB it was created in."],"tags":["workspace","not-found","state","concurrency"],"backgroundTag":"workspace-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}