RocketChat/Rocket.Chat · error · Error

No valid agent found

Error message

No valid agent found

What it means

Plain Error thrown by validateMaxChats on 'livechat.checkAgentBeforeTakeInquiry' when Users.getAgentAndAmountOngoingChats(agentId, departmentId) returns null — the agentId does not resolve to an existing livechat agent user (with queue statistics). This is a data-resolution failure, distinct from capacity: the agent record itself could not be found.

Solutions

  1. Confirm the agent exists and holds the livechat-agent role (Administration > Omnichannel > Agents)
  2. Re-add the user as an omnichannel agent so getAgentAndAmountOngoingChats can resolve them, then retry
  3. If the agent was deleted intentionally, route/forward the inquiry to a valid agent instead

Example fix

// before: passing an unverified agentId into the take flow
await callbacks.run('livechat.checkAgentBeforeTakeInquiry', inquiry, { agentId });

// after: resolve the agent record first, mirroring the hook's lookup
const user = await Users.getAgentAndAmountOngoingChats(agentId, inquiry.department);
if (!user) throw new Error('agentId does not resolve to a livechat agent: ' + agentId);
await callbacks.run('livechat.checkAgentBeforeTakeInquiry', inquiry, { agentId });
Defensive patterns

Strategy: validation

Validate before calling

const agentResolves = async (agentId: string, departmentId?: string): Promise<boolean> =>
  Boolean(await Users.getAgentAndAmountOngoingChats(agentId, departmentId));

Try / catch

try {
  await takeInquiry(inquiry, { agentId });
} catch (err: any) {
  if (err?.message === 'No valid agent found') {
    // agent deleted or not a livechat agent; reassign the inquiry to a valid agent
  }
  throw err;
}

Prevention

When it happens

Trigger: Taking an inquiry with an agentId that was deleted, lacks the livechat-agent role, or is malformed; department-scoped lookup where the agent exists but is not registered as an agent.

Common situations: Agent users removed while their inquiries were still queued; agentId taken from stale UI state; agents created as bots without proper roles.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/1a5d7bef310ef7ba. Report an issue: GitHub.

Appendix: 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 b2c16d5842)