{"record":{"id":"c5d83dfa77dc76ac","repo":"RocketChat/Rocket.Chat","slug":"error-unserved-rooms-cannot-be-placed-onhold","errorCode":null,"errorMessage":"error-unserved-rooms-cannot-be-placed-onhold","messagePattern":"error-unserved-rooms-cannot-be-placed-onhold","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/local-services/omnichannel.internalService.ts","lineNumber":57,"sourceCode":"\n\t\tif (!room || !isOmnichannelRoom(room)) {\n\t\t\tthrow new Error('error-invalid-room');\n\t\t}\n\t\tif (!room.open) {\n\t\t\tthrow new Error('error-room-already-closed');\n\t\t}\n\t\tif (room.onHold) {\n\t\t\tthrow new Error('error-room-is-already-on-hold');\n\t\t}\n\t\tconst restrictedOnHold = settings.get('Livechat_allow_manual_on_hold_upon_agent_engagement_only');\n\t\tconst canRoomBePlacedOnHold = !room.onHold;\n\t\tconst canAgentPlaceOnHold = !room.lastMessage?.token;\n\t\tconst canPlaceChatOnHold = canRoomBePlacedOnHold && (!restrictedOnHold || canAgentPlaceOnHold);\n\t\tif (!canPlaceChatOnHold) {\n\t\t\tthrow new Error('error-cannot-place-chat-on-hold');\n\t\t}\n\t\tif (!room.servedBy) {\n\t\t\tthrow new Error('error-unserved-rooms-cannot-be-placed-onhold');\n\t\t}\n\n\t\tconst [roomResult, subsResult] = await Promise.all([\n\t\t\tLivechatRooms.setOnHoldByRoomId(roomId),\n\t\t\tSubscriptions.setOnHoldByRoomId(roomId),\n\t\t\tMessage.saveSystemMessage<IOmnichannelSystemMessage>('omnichannel_placed_chat_on_hold', roomId, '', onHoldBy, { comment }),\n\t\t]);\n\n\t\tif (roomResult.modifiedCount) {\n\t\t\tvoid notifyOnRoomChangedById(roomId);\n\t\t}\n\n\t\tif (subsResult.modifiedCount) {\n\t\t\tvoid notifyOnSubscriptionChangedByRoomId(roomId);\n\t\t}\n\n\t\tawait callbacks.run('livechat:afterOnHold', room);\n\t}","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/local-services/omnichannel.internalService.ts#L39-L75","documentation":"Thrown by placeRoomOnHold when `room.servedBy` is falsy. A chat without a serving agent cannot be put on hold because there is no agent relationship to suspend. This is the last guard before the room/subscription update.","triggerScenarios":"Calling placeRoomOnHold on a room whose servedBy field is null/undefined: an unclaimed queued inquiry, a room whose agent was removed, or a chat returned to the queue.","commonSituations":"Trying to hold a chat that is still queued (no agent assigned); the servedBy relation was cleared by a transfer/abandon flow before the hold call.","solutions":["Only expose Hold for rooms with an active servedBy; gate the UI on room.servedBy being truthy.","Re-fetch the room to confirm it is still assigned before calling placeRoomOnHold.","If the chat is queued, route it through the assignment flow first, not the hold flow."],"exampleFix":"// before\nawait omnichannelService.placeRoomOnHold(room, comment, user);\n\n// after\nif (!room.servedBy) {\n  throw new Error('Room has no serving agent; cannot place on hold');\n}\nawait omnichannelService.placeRoomOnHold(room, comment, user);","handlingStrategy":"validation","validationCode":"if (!room.servedBy) {\n  throw new Error('Room has no serving agent; cannot place on hold');\n}\nawait omnichannelService.placeRoomOnHold(room, comment, user);","typeGuard":"function hasServingAgent(room: unknown): boolean {\n  return !!room && !!(room as any).servedBy;\n}","tryCatchPattern":"try {\n  await omnichannelService.placeRoomOnHold(room, comment, user);\n} catch (e) {\n  if (e instanceof Error && e.message === 'error-unserved-rooms-cannot-be-placed-onhold') {\n    notifyUser('This chat has no assigned agent.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Only show Hold for rooms with an active servedBy.","Re-fetch the room to confirm assignment before the call.","Route unassigned chats through assignment, not hold."],"tags":["omnichannel","livechat","room-state","agent-assignment"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}