{"record":{"id":"6e058853d97ad052","repo":"RocketChat/Rocket.Chat","slug":"invalid-agent","errorCode":null,"errorMessage":"invalid-agent","messagePattern":"invalid-agent","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/agent.ts","lineNumber":38,"sourceCode":"import { saveAgentInfo } from '../../../lib/omnichannel/omni-users';\nimport { setUserStatusLivechat, allowAgentChangeServiceStatus } from '../../../lib/omnichannel/utils';\nimport type { ExtractRoutesFromAPI } from '../../ApiClass';\n\nAPI.v1.addRoute('livechat/agent.info/:rid/:token', {\n\tasync get() {\n\t\tconst visitor = await findGuest(this.urlParams.token);\n\t\tif (!visitor) {\n\t\t\tthrow new Error('invalid-token');\n\t\t}\n\n\t\tconst room = await findRoom(this.urlParams.token, this.urlParams.rid);\n\t\tif (!room) {\n\t\t\tthrow new Error('invalid-room');\n\t\t}\n\n\t\tconst agent = room?.servedBy && (await findAgent(room.servedBy._id));\n\t\tif (!agent) {\n\t\t\tthrow new Error('invalid-agent');\n\t\t}\n\n\t\treturn API.v1.success({ agent });\n\t},\n});\n\nAPI.v1.addRoute(\n\t'livechat/agent.next/:token',\n\t{ validateParams: isGETAgentNextToken },\n\t{\n\t\tasync get() {\n\t\t\tconst { token } = this.urlParams;\n\t\t\tconst room = await findOpenRoom(token, undefined, this.userId);\n\t\t\tif (room) {\n\t\t\t\treturn API.v1.success();\n\t\t\t}\n\n\t\t\tlet { department } = this.queryParams;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/agent.ts#L20-L56","documentation":"Thrown by GET /api/v1/livechat/agent.info/:rid/:token when findAgent(room.servedBy._id) returns null. The room has a servedBy reference (indicating an agent was assigned) but the agent's user record cannot be found via normalizeAgent. This indicates a data integrity issue — the room references an agent who no longer exists.","triggerScenarios":"A livechat room has servedBy._id set but the referenced agent user has been deleted, deactivated and removed from the livechat-agent role, or the user document is otherwise invalid for agent normalization.","commonSituations":"Agent user was deleted after the room was created; agent was removed from the livechat-agent role after assignment; data migration corrupted the servedBy reference.","solutions":["Verify the agent user referenced in room.servedBy._id still exists in the Users collection.","Re-assign the livechat room to an active agent.","Check that the referenced user still has the livechat-agent role."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await getAgentInfo(rid, token);\n} catch (e) {\n  if (e.message === 'invalid-agent') {\n    console.error('The assigned agent for this room no longer exists. Contact an admin to reassign the room.');\n    // Optionally trigger a re-routing request\n    return;\n  }\n  throw e;\n}","preventionTips":["Monitor for deleted agents that still have livechat room assignments (servedBy references).","Run periodic data integrity checks between rooms.servedBy and the Users collection.","When deleting an agent, reassign or close their livechat rooms first."],"tags":["omnichannel","livechat","agent","data-integrity"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}