RocketChat/Rocket.Chat · warning

error-selected-agent-room-agent-are-same

error-selected-agent-room-agent-are-same

Error message

error-selected-agent-room-agent-are-same

What it means

forwardRoomToAgent refuses no-op transfers: if the room already has servedBy set and the requested agentId equals servedBy._id, it throws error-selected-agent-room-agent-are-same. It prevents routing work back to the agent currently handling it.

Source

Thrown at apps/meteor/server/lib/omnichannel/Helper.ts:524

		logger.debug({
			msg: 'Agent is offline. Cannot forward',
			agentId,
		});
		throw new Error('error-user-is-offline');
	}

	const { _id: rid, servedBy: oldServedBy } = room;
	const inquiry = await LivechatInquiry.findOneByRoomId(rid, {});
	if (!inquiry) {
		logger.debug({
			msg: 'No inquiries found for room. Cannot forward',
			roomId: room._id,
		});
		throw new Error('error-invalid-inquiry');
	}

	if (oldServedBy && agentId === oldServedBy._id) {
		throw new Error('error-selected-agent-room-agent-are-same');
	}

	const { username } = user;
	const agent = { agentId, username };
	// Remove department from inquiry to make sure the routing algorithm treat this as forwarding to agent and not as forwarding to department
	delete inquiry.department;
	// There are some Enterprise features that may interrupt the forwarding process
	// Due to that we need to check whether the agent has been changed or not
	logger.debug({
		msg: 'Forwarding inquiry to agent',
		inquiryId: inquiry._id,
		agentId: agent.agentId,
	});
	const roomTaken = await RoutingManager.takeInquiry(
		inquiry,
		agent,
		{
			...(clientAction && { clientAction }),

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Choose a different agent or a department as the forward target
  2. In the UI, filter the currently serving agent out of the target list
  3. In automation, compare room.servedBy?._id with the target userId before calling

Example fix

// before
await forwardRoomToAgent(room, { userId: room.servedBy?._id, clientAction: 'forward' }, guest);

// after
if (room.servedBy?._id === targetAgentId) {
  throw new Error('error-selected-agent-room-agent-are-same');
}
await forwardRoomToAgent(room, { userId: targetAgentId, clientAction: 'forward' }, guest);
Defensive patterns

Strategy: validation

Validate before calling

const targetId = transferData.userId;
if (room.servedBy && targetId === room.servedBy._id) {
  // selecting the current agent is a no-op; block it in the UI
  throw new Error('error-selected-agent-room-agent-are-same');
}

Try / catch

try {
  await forwardRoomToAgent(room, transferData, guest);
} catch (err) {
  if (err instanceof Error && err.message === 'error-selected-agent-room-agent-are-same') {
    // benign: prompt the user to pick a different target
  } else throw err;
}

Prevention

When it happens

Trigger: The transfer dialog defaults to or the user re-picks the agent currently serving the room; automation copies room.servedBy._id into transferData.userId.

Common situations: Transfer dialogs that preselect the serving agent; scripts forwarding back to the same agent to 'reset' the chat; agent lists where the current agent sorts first.

Related errors


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