{"record":{"id":"e3a807c741b0468c","repo":"RocketChat/Rocket.Chat","slug":"provided-agent-is-not-online","errorCode":null,"errorMessage":"Provided agent is not online","messagePattern":"Provided agent is not online","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts","lineNumber":37,"sourceCode":"\t\tdepartment: string;\n\t};\n\toptions: {\n\t\tforwardingToDepartment?: {\n\t\t\toldDepartmentId: string;\n\t\t\ttransferData: any;\n\t\t};\n\t\tclientAction?: boolean;\n\t};\n}) => {\n\tif (!inquiry?._id || !agent?.agentId) {\n\t\tcbLogger.debug('No inquiry or agent provided');\n\t\tthrow new Error('No inquiry or agent provided');\n\t}\n\tconst { agentId } = agent;\n\n\tif (!(await checkOnlineAgents(undefined, agent))) {\n\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}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts#L19-L55","documentation":"Plain Error thrown by validateMaxChats on 'livechat.checkAgentBeforeTakeInquiry' when checkOnlineAgents(undefined, agent) reports the target agent as not online. An agent must be online (available status) at the moment of taking an inquiry from the waiting queue.","triggerScenarios":"Taking a queued inquiry while the agent's status is away/busy/offline or the agent lacks livechat-agent availability; races where the agent went offline between the UI action and the server check.","commonSituations":"Agents forgetting to switch back to Online after a break; status sync delays after reconnects; automation trying to auto-assign to agents whose livechat status is not online.","solutions":["Set the agent's Livechat status to Online (statusLivechat 'available' and a synchronous status) and retry","Verify the user actually has the livechat-agent role and appears in the online agents registry","If automating takes, poll for agent online state before issuing the take action"],"exampleFix":"// before: taking the inquiry blindly\nawait callbacks.run('livechat.checkAgentBeforeTakeInquiry', inquiry, agent);\n\n// after: apply the same online gate first\nif (!(await checkOnlineAgents(undefined, agent))) {\n  throw new Error('Agent must be online to take an inquiry');\n}\nawait callbacks.run('livechat.checkAgentBeforeTakeInquiry', inquiry, agent);","handlingStrategy":"validation","validationCode":"const agentIsOnline = async (agent: { agentId: string; status?: string }): Promise<boolean> =>\n  Boolean(await checkOnlineAgents(undefined, agent));","typeGuard":null,"tryCatchPattern":"try {\n  await takeInquiry(inquiry, agent);\n} catch (err: any) {\n  if (err?.message === 'Provided agent is not online') {\n    // prompt agent to go online; retry only after statusLivechat is available\n  }\n  throw err;\n}","preventionTips":["Gate the take action in the UI on the agent's livechat online status","Re-check status server-side right before automated takes","Train agents that queue takes require Online (not away/busy) status"],"tags":["omnichannel","livechat","agent-status","availability"],"backgroundTag":"agent-offline","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"}