{"record":{"id":"a6d475e4fb1fa8dd","repo":"hcengineering/platform","slug":"internalservererror-a6d475","errorCode":"InternalServerError","errorMessage":"InternalServerError","messagePattern":"InternalServerError","errorType":"error_code","errorClass":"PlatformError","httpStatus":500,"severity":"error","filePath":"server/account/src/utils.ts","lineNumber":901,"sourceCode":"    if (extra == null) {\n      extra = {}\n    }\n    extra.readonly = 'true'\n  }\n\n  const wsStatus = await db.workspaceStatus.findOne({ workspaceUuid: workspace.uuid })\n\n  if (wsStatus != null) {\n    if (wsStatus.isDisabled && isActiveMode(wsStatus.mode)) {\n      ctx.error('Selecting a disabled workspace', { workspaceUrl, accountUuid })\n\n      throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUrl }))\n    }\n  }\n\n  const person = await db.person.findOne({ uuid: accountUuid })\n  if (person == null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.InternalServerError, {}))\n  }\n\n  return {\n    account: accountUuid,\n    token: generateToken(accountUuid, workspace.uuid, extra, undefined, {\n      grant,\n      sub,\n      exp,\n      nbf\n    }),\n    endpoint: getEndpoint(workspace.uuid, workspace.region, getKind(workspace.region)),\n    workspace: workspace.uuid,\n    workspaceUrl: workspace.url,\n    workspaceDataId: workspace.dataId,\n    allowGuestSignUp: workspace.allowReadOnlyGuest && workspace.allowGuestSignUp,\n    role\n  }\n}","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/utils.ts#L883-L919","documentation":"Near the end of selectWorkspace (server/account/src/utils.ts), after role, account and workspace-status checks pass, the service loads the corresponding person document (db.person.findOne({ uuid: accountUuid })). If it is null the internal invariant 'every account with a workspace role has a person record' is broken, so it throws InternalServerError. This is a data-integrity failure inside the account database, not a client mistake.","triggerScenarios":"db.person.findOne({ uuid: accountUuid }) returns null although the account passed earlier checks — e.g. the person record was deleted while account/role rows remain, a backup was partially restored, or a migration wrote accounts/roles without persons.","commonSituations":"Partial DB restores, custom scripts removing person documents, region-merge tooling copying account data without person data, corrupted workspaces after failed migrations.","solutions":["Inspect the person collection for the missing uuid and restore/recreate the person record (firstName/lastName) matching the account.","Restore DB consistency from a backup or run a repair script that re-creates person rows for orphan accounts.","Audit any custom tooling/migrations that delete or move account data so person and account records stay in sync.","Report to the platform operators if this occurs on a managed instance — it signals internal data corruption."],"exampleFix":"// before: orphan account with no person row -> InternalServerError on select\nawait accountClient.selectWorkspace(token, url)\n\n// after: repair the DB first (admin side)\nawait db.person.insertOne({ uuid: orphanAccountUuid, firstName: 'Jane', lastName: 'Doe' })\nawait db.account.findOne({ uuid: orphanAccountUuid }) // ensure account row exists\n// then retry selection","handlingStrategy":"try-catch","validationCode":"// admin-side precheck that the account's person row exists\nconst person = await db.person.findOne({ uuid: accountUuid })\nif (person == null) {\n  throw new Error('Person record missing for account; repair DB before selecting workspace')\n}","typeGuard":"function personExists(p: { uuid: string } | null | undefined): p is { uuid: string } {\n  return p != null\n}","tryCatchPattern":"try {\n  await accountClient.selectWorkspace(token, url)\n} catch (e) {\n  if ((e as PlatformError).status.code === platform.status.InternalServerError) {\n    reportToOps('selectWorkspace invariant violated: person record missing')\n  } else throw e\n}","preventionTips":["Never delete person rows without removing dependent account/role rows","Validate migrations/restores include person, account and role collections together","Alert on orphan accounts (account without person) via periodic consistency checks","Escalate InternalServerError from the account service to operators — it signals data corruption"],"tags":["data-integrity","account-service","database","internal-error"],"backgroundTag":"internal-server-error","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}