{"record":{"id":"1a5d7bef310ef7ba","repo":"RocketChat/Rocket.Chat","slug":"no-valid-agent-found","errorCode":null,"errorMessage":"No valid agent found","messagePattern":"No valid agent found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts","lineNumber":54,"sourceCode":"\t\tcbLogger.debug('Provided agent is not online');\n\t\tthrow new Error('Provided agent is not online');\n\t}\n\n\tif (!settings.get('Livechat_waiting_queue')) {\n\t\tcbLogger.info({ msg: 'Chat can be taken by Agent: waiting queue is disabled', agentId });\n\t\treturn agent;\n\t}\n\n\tif (await allowAgentSkipQueue(agent)) {\n\t\tcbLogger.info({ msg: 'Chat can be taken by Agent: agent can skip queue', agentId });\n\t\treturn agent;\n\t}\n\n\tconst { department: departmentId } = inquiry;\n\tconst user = await Users.getAgentAndAmountOngoingChats(agentId, departmentId);\n\tif (!user) {\n\t\tcbLogger.debug({ msg: 'No valid agent found', agentId });\n\t\tthrow new Error('No valid agent found');\n\t}\n\n\tconst { queueInfo: { chats = 0, chatsForDepartment = 0 } = {} } = user;\n\n\tif (await isAgentWithinChatLimits({ agentId, departmentId, totalChats: chats, departmentChats: chatsForDepartment })) {\n\t\treturn user;\n\t}\n\tthrow new Error('error-max-number-simultaneous-chats-reached');\n};\n\ncallbacks.add('livechat.checkAgentBeforeTakeInquiry', validateMaxChats, callbacks.priority.MEDIUM, 'livechat-before-take-inquiry');\n","sourceCodeStart":36,"sourceCodeEnd":66,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts#L36-L66","documentation":"Thrown by the `livechat.checkAgentBeforeTakeInquiry` callback when `Users.getAgentAndAmountOngoingChats(agentId, departmentId)` returns null — the agent could not be found as a livechat agent with queue info. It is a plain `Error`; logged at debug level with the agentId. It is distinct from the chat-limit error which throws when the agent exists but is over capacity.","triggerScenarios":"The take-inquiry callback, after confirming the agent is online and the waiting queue is enabled and the agent cannot skip queue, looks up the agent via `getAgentAndAmountOngoingChats` and gets null back.","commonSituations":"Agent user record lacks livechat agent metadata (not registered as a livechat agent); agent was deleted/deactivated between the online check and this lookup; departmentId points to a department the agent isn't part of.","solutions":["Confirm the user is registered as a livechat agent with a valid department assignment.","Re-fetch/refresh the agent record; ensure `livechat` agent info exists on the user document.","Verify the inquiry's `department` matches a department the agent belongs to."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { Users } from '../../../../server/models';\n\nasync function agentHasQueueInfo(agentId: string, departmentId: string): Promise<boolean> {\n\treturn Boolean(await Users.getAgentAndAmountOngoingChats(agentId, departmentId));\n}","typeGuard":"function isNoValidAgentError(e: unknown): boolean {\n\treturn e instanceof Error && e.message === 'No valid agent found';\n}","tryCatchPattern":"try {\n\tawait callbacks.run('livechat.checkAgentBeforeTakeInquiry', inquiry, agent);\n} catch (e) {\n\tif (e instanceof Error && e.message === 'No valid agent found') {\n\t\t// user is not a registered livechat agent for this department\n\t}\n\tthrow e;\n}","preventionTips":["Ensure the user is registered as a livechat agent with livechat metadata.","Verify the agent belongs to the inquiry's department.","Re-fetch the agent record to rule out deletion/deactivation races."],"tags":["omnichannel","livechat","agents","validation","ee"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}