{"record":{"id":"7cd9503c9cbf6f1d","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-inquiry","errorCode":"error-invalid-inquiry","errorMessage":"error-invalid-inquiry","messagePattern":"error-invalid-inquiry","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts","lineNumber":8,"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,","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/api/v1/omnichannel/lib/inquiries.ts#L1-L26","documentation":"setSLAToInquiry requires the room's livechat inquiry to exist and have status 'queued'. A missing inquiry (roomId is not an omnichannel room, or no inquiry was created) or any non-queued status (taken, closed) throws 'error-invalid-inquiry' before the SLA is even resolved.","triggerScenarios":"Setting SLA on a room whose inquiry was already taken by an agent or whose conversation is closed; roomId of a non-omnichannel room; racing another agent accepting the queued chat between check and call.","commonSituations":"Automation assigning SLA at the same moment the chat gets picked up; retrying after the queue moved on; wrong room id passed by the integration.","solutions":["Re-check the inquiry is still queued immediately before the call (inquiry/queue lookup)","Treat taken/closed as a benign race: skip the room instead of retrying the same call","Set SLA at routing time (department-level SLA) rather than post-hoc on live inquiries"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { LivechatInquiry } from '@rocket.chat/models';\n\nconst inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } });\nif (!inquiry || inquiry.status !== 'queued') {\n  throw new Error(`room ${roomId} has no queued inquiry - skip SLA assignment`);\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-inquiry') {\n    // queue state raced us (taken/closed): benign, do not retry the same room\n    logger.info('inquiry no longer queued', { roomId });\n    return;\n  }\n  throw error;\n}","preventionTips":["Check inquiry status immediately before the call, but still handle the race","Prefer department/routing-time SLA configuration over live inquiry mutation","Confirm roomId is an omnichannel room before SLA operations"],"tags":["omnichannel","livechat","sla","invalid-state"],"backgroundTag":"invalid-resource-state","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"}