{"record":{"id":"eabada215cce0d95","repo":"RocketChat/Rocket.Chat","slug":"error-room-is-already-on-hold","errorCode":null,"errorMessage":"error-room-is-already-on-hold","messagePattern":"error-room-is-already-on-hold","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/local-services/omnichannel.internalService.ts","lineNumber":47,"sourceCode":"\t}\n\n\tasync placeRoomOnHold(\n\t\troom: Pick<IOmnichannelRoom, '_id' | 't' | 'open' | 'onHold'>,\n\t\tcomment: string,\n\t\tonHoldBy: Pick<IUser, '_id' | 'username' | 'name'>,\n\t) {\n\t\tthis.logger.debug({ msg: 'Attempting to place room on hold', roomId: room._id, userId: onHoldBy?._id });\n\n\t\tconst { _id: roomId } = room;\n\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","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/local-services/omnichannel.internalService.ts#L29-L65","documentation":"If room.onHold is already true, placeRoomOnHold throws Error('error-room-is-already-on-hold') rather than treating the repeat call as a no-op. The check runs third, after the room-type and open guards, so it fires on genuinely open livechat rooms that are already held.","triggerScenarios":"Double-invoking the on-hold action (double click, retried HTTP request without idempotency), or holding a room that another agent or automation already placed on hold.","commonSituations":"Duplicate submissions from flaky clients or retries; UI not reflecting the onHold flag set moments earlier by a different agent/session; bulk scripts processing a room list that overlaps with a concurrent hold job.","solutions":["Check room.onHold before calling and treat an already-held room as success.","Prevent duplicate submissions: disable the button after click, add idempotency keys for retried requests.","Re-fetch the room immediately before the call so the decision uses fresh state."],"exampleFix":"// before\nawait service.placeRoomOnHold(room, comment, user); // second click -> error-room-is-already-on-hold\n\n// after\nif (room.onHold) return { alreadyOnHold: true }; // idempotent: already in the desired state\nawait service.placeRoomOnHold(room, comment, user);","handlingStrategy":"validation","validationCode":"if (room.onHold) {\n\t// already held; treat as success and skip the call (idempotency at the caller)\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait service.placeRoomOnHold(room, comment, user);\n} catch (e: any) {\n\tif (e?.message === 'error-room-is-already-on-hold') return { alreadyOnHold: true }; // idempotent success\n\tthrow e;\n}","preventionTips":["Disable the hold button after first click to stop double submits.","Re-read the onHold flag from the server before each hold attempt.","Add idempotency keys when hold requests may be retried by the transport."],"tags":["omnichannel","on-hold","room-state","idempotency","enterprise"],"backgroundTag":"invalid-room-state","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}