{"record":{"id":"2e57de5e604b461a","repo":"RocketChat/Rocket.Chat","slug":"error-max-number-simultaneous-chats-reached-2e57de","errorCode":"error-max-number-simultaneous-chats-reached","errorMessage":"error-max-number-simultaneous-chats-reached","messagePattern":"error-max-number-simultaneous-chats-reached","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts","lineNumber":62,"sourceCode":"\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":44,"sourceCodeEnd":66,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts#L44-L66","documentation":"Thrown at the end of validateMaxChats ('livechat.checkAgentBeforeTakeInquiry') when the agent resolves and is online but isAgentWithinChatLimits reports they are already at their simultaneous-chat limit (total and/or department scope). Same business rule as the before-join-room hook, enforced on the take-inquiry path when the waiting queue is enabled and the agent cannot skip the queue.","triggerScenarios":"Taking an inquiry from the waiting queue while ongoing chats (total or per-department) already equal the configured maximums; Livechat_waiting_queue enabled and allowAgentSkipQueue false for the agent.","commonSituations":"Agents at capacity clicking queued chats; limits lowered below current load; departments with tighter limits than the agent's global load.","solutions":["Close or return some of the agent's ongoing chats, then take the inquiry","Raise the per-agent and per-department simultaneous chat limits in Omnichannel settings","Enable 'agent skip queue' for eligible agents or route the inquiry to an agent with spare capacity"],"exampleFix":"// before: taking a queued inquiry at capacity throws\nawait takeInquiry(inquiry, { agentId });\n\n// after: replicate the hook's capacity check first\nconst user = await Users.getAgentAndAmountOngoingChats(agentId, inquiry.department);\nconst { chats = 0, chatsForDepartment = 0 } = user?.queueInfo ?? {};\nif (!(await isAgentWithinChatLimits({ agentId, departmentId: inquiry.department, totalChats: chats, departmentChats: chatsForDepartment }))) {\n  throw new Error('Agent at max simultaneous chats');\n}\nawait takeInquiry(inquiry, { agentId });","handlingStrategy":"validation","validationCode":"const agentHasCapacity = async (agentId: string, departmentId?: string): Promise<boolean> => {\n  const user = await Users.getAgentAndAmountOngoingChats(agentId, departmentId);\n  if (!user) return false;\n  const { chats = 0, chatsForDepartment = 0 } = user.queueInfo ?? {};\n  return isAgentWithinChatLimits({ agentId, departmentId, totalChats: chats, departmentChats: chatsForDepartment });\n};","typeGuard":null,"tryCatchPattern":"try {\n  await takeInquiry(inquiry, agent);\n} catch (err: any) {\n  if (err?.message === 'error-max-number-simultaneous-chats-reached') {\n    // stop the take; close a chat or raise limits before retrying\n  }\n  throw err;\n}","preventionTips":["Surface current chats/max in the agent queue view","For auto-take flows, pick the agent with the most remaining capacity","Raise limits before campaigns that spike concurrent chat volume"],"tags":["omnichannel","livechat","agent-capacity","waiting-queue"],"backgroundTag":"capacity-limit-reached","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"}