{"record":{"id":"0526d67a8fddddef","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-0526d6","errorCode":"error-invalid-user","errorMessage":"error-invalid-user","messagePattern":"error-invalid-user","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts","lineNumber":18,"sourceCode":"import { LivechatInquiry, Users, OmnichannelServiceLevelAgreements } from '@rocket.chat/models';\n\nimport { updateRoomSLA } from './sla';\n\nexport async function setSLAToInquiry({ userId, roomId, sla }: { userId: string; roomId: string; sla?: string }): Promise<void> {\n\tconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\n\tif (!inquiry || inquiry.status !== 'queued') {\n\t\tthrow new Error('error-invalid-inquiry');\n\t}\n\n\tconst slaData = sla && (await OmnichannelServiceLevelAgreements.findOneByIdOrName(sla));\n\tif (!slaData) {\n\t\tthrow new Error('error-invalid-sla');\n\t}\n\n\tconst user = await Users.findOneById(userId, { projection: { _id: 1, username: 1, name: 1 } });\n\tif (!user?.username) {\n\t\tthrow new Error('error-invalid-user');\n\t}\n\n\tawait updateRoomSLA(\n\t\troomId,\n\t\t{\n\t\t\t_id: user._id,\n\t\t\tname: user.name || '',\n\t\t\tusername: user.username,\n\t\t},\n\t\tslaData,\n\t);\n}\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts#L1-L31","documentation":"setSLAToInquiry requires userId to resolve a user document that has a username (Users.findOneById with username projected). A deleted user, a malformed id, or a user record lacking username throws 'error-invalid-user'.","triggerScenarios":"userId from a stale session/PAT of a deleted user; a truncated or malformed id; user document without the username field (edge-case import).","commonSituations":"Tokens outliving their accounts; ids copied between environments (dev vs prod); automation storing user ids past user deletion.","solutions":["Re-authenticate and pass the current acting user's id","Verify the user with Users.findOneById before the call","If the user was deleted, route the SLA change through another agent"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { Users } from '@rocket.chat/models';\n\nconst user = await Users.findOneById(userId, { projection: { username: 1 } });\nif (!user?.username) {\n  throw new Error(`acting user ${userId} does not exist or has no username`);\n}\nawait setSLAToInquiry({ userId, roomId, sla });","typeGuard":null,"tryCatchPattern":"try {\n  await setSLAToInquiry({ userId, roomId, sla });\n} catch (error) {\n  if (error instanceof Error && error.message === 'error-invalid-user') {\n    throw new NotFoundError(`acting user ${userId} was deleted or is invalid - re-authenticate`);\n  }\n  throw error;\n}","preventionTips":["Do not cache acting user ids across sessions","Invalidate stored user ids on user-deletion events","Re-verify the caller identity in long-lived automation jobs"],"tags":["omnichannel","livechat","sla","user-lookup"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}