{"record":{"id":"45330f263900c671","repo":"RocketChat/Rocket.Chat","slug":"error-selected-agent-room-agent-are-same","errorCode":"error-selected-agent-room-agent-are-same","errorMessage":"error-selected-agent-room-agent-are-same","messagePattern":"error-selected-agent-room-agent-are-same","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/omnichannel/Helper.ts","lineNumber":524,"sourceCode":"\t\tlogger.debug({\n\t\t\tmsg: 'Agent is offline. Cannot forward',\n\t\t\tagentId,\n\t\t});\n\t\tthrow new Error('error-user-is-offline');\n\t}\n\n\tconst { _id: rid, servedBy: oldServedBy } = room;\n\tconst inquiry = await LivechatInquiry.findOneByRoomId(rid, {});\n\tif (!inquiry) {\n\t\tlogger.debug({\n\t\t\tmsg: 'No inquiries found for room. Cannot forward',\n\t\t\troomId: room._id,\n\t\t});\n\t\tthrow new Error('error-invalid-inquiry');\n\t}\n\n\tif (oldServedBy && agentId === oldServedBy._id) {\n\t\tthrow new Error('error-selected-agent-room-agent-are-same');\n\t}\n\n\tconst { username } = user;\n\tconst agent = { agentId, username };\n\t// Remove department from inquiry to make sure the routing algorithm treat this as forwarding to agent and not as forwarding to department\n\tdelete inquiry.department;\n\t// There are some Enterprise features that may interrupt the forwarding process\n\t// Due to that we need to check whether the agent has been changed or not\n\tlogger.debug({\n\t\tmsg: 'Forwarding inquiry to agent',\n\t\tinquiryId: inquiry._id,\n\t\tagentId: agent.agentId,\n\t});\n\tconst roomTaken = await RoutingManager.takeInquiry(\n\t\tinquiry,\n\t\tagent,\n\t\t{\n\t\t\t...(clientAction && { clientAction }),","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/Helper.ts#L506-L542","documentation":"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.","triggerScenarios":"The transfer dialog defaults to or the user re-picks the agent currently serving the room; automation copies room.servedBy._id into transferData.userId.","commonSituations":"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.","solutions":["Choose a different agent or a department as the forward target","In the UI, filter the currently serving agent out of the target list","In automation, compare room.servedBy?._id with the target userId before calling"],"exampleFix":"// before\nawait forwardRoomToAgent(room, { userId: room.servedBy?._id, clientAction: 'forward' }, guest);\n\n// after\nif (room.servedBy?._id === targetAgentId) {\n  throw new Error('error-selected-agent-room-agent-are-same');\n}\nawait forwardRoomToAgent(room, { userId: targetAgentId, clientAction: 'forward' }, guest);","handlingStrategy":"validation","validationCode":"const targetId = transferData.userId;\nif (room.servedBy && targetId === room.servedBy._id) {\n  // selecting the current agent is a no-op; block it in the UI\n  throw new Error('error-selected-agent-room-agent-are-same');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await forwardRoomToAgent(room, transferData, guest);\n} catch (err) {\n  if (err instanceof Error && err.message === 'error-selected-agent-room-agent-are-same') {\n    // benign: prompt the user to pick a different target\n  } else throw err;\n}","preventionTips":["Filter the currently serving agent out of forward target lists","Never copy room.servedBy into transferData in automation"],"tags":["omnichannel","livechat","transfer","duplicate","rocket-chat"],"backgroundTag":"duplicate-operation","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}