RocketChat/Rocket.Chat · error · Error
No valid agent found
Error message
No valid agent found
What it means
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.
Source
Thrown at apps/meteor/ee/server/hooks/omnichannel/checkAgentBeforeTakeInquiry.ts:54
cbLogger.debug('Provided agent is not online');
throw new Error('Provided agent is not online');
}
if (!settings.get('Livechat_waiting_queue')) {
cbLogger.info({ msg: 'Chat can be taken by Agent: waiting queue is disabled', agentId });
return agent;
}
if (await allowAgentSkipQueue(agent)) {
cbLogger.info({ msg: 'Chat can be taken by Agent: agent can skip queue', agentId });
return agent;
}
const { department: departmentId } = inquiry;
const user = await Users.getAgentAndAmountOngoingChats(agentId, departmentId);
if (!user) {
cbLogger.debug({ msg: 'No valid agent found', agentId });
throw new Error('No valid agent found');
}
const { queueInfo: { chats = 0, chatsForDepartment = 0 } = {} } = user;
if (await isAgentWithinChatLimits({ agentId, departmentId, totalChats: chats, departmentChats: chatsForDepartment })) {
return user;
}
throw new Error('error-max-number-simultaneous-chats-reached');
};
callbacks.add('livechat.checkAgentBeforeTakeInquiry', validateMaxChats, callbacks.priority.MEDIUM, 'livechat-before-take-inquiry');
View on GitHub (pinned to f9d3ec372b)
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.
Defensive patterns
Strategy: validation
Validate before calling
import { Users } from '../../../../server/models';
async function agentHasQueueInfo(agentId: string, departmentId: string): Promise<boolean> {
return Boolean(await Users.getAgentAndAmountOngoingChats(agentId, departmentId));
} Type guard
function isNoValidAgentError(e: unknown): boolean {
return e instanceof Error && e.message === 'No valid agent found';
} Try / catch
try {
await callbacks.run('livechat.checkAgentBeforeTakeInquiry', inquiry, agent);
} catch (e) {
if (e instanceof Error && e.message === 'No valid agent found') {
// user is not a registered livechat agent for this department
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Provided agent is not online
- error-forwarding-department-target-not-allowed
- error-max-number-simultaneous-chats-reached
- error-invalid-sla
- error-invalid-priority
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/1a5d7bef310ef7ba.
Report an issue: GitHub.