{"record":{"id":"3559a300dced3e19","repo":"RocketChat/Rocket.Chat","slug":"failed-to-create-livechat-call","errorCode":null,"errorMessage":"failed-to-create-livechat-call","messagePattern":"failed-to-create-livechat-call","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/video-conference/service.ts","lineNumber":870,"sourceCode":"\t\t\tcallId,\n\t\t\trid,\n\t\t};\n\t}\n\n\tprivate async startLivechat(providerName: string, user: IUser, rid: IRoom['_id']): Promise<LivechatInstructions> {\n\t\tconst callId = await VideoConferenceModel.createLivechat({\n\t\t\trid,\n\t\t\tcreatedBy: {\n\t\t\t\t_id: user._id,\n\t\t\t\tname: user.name as string,\n\t\t\t\tusername: user.username as string,\n\t\t\t},\n\t\t\tproviderName,\n\t\t});\n\n\t\tconst call = (await this.getUnfiltered(callId)) as ILivechatVideoConference | null;\n\t\tif (!call) {\n\t\t\tthrow new Error('failed-to-create-livechat-call');\n\t\t}\n\n\t\tawait this.runNewVideoConferenceEvent(callId);\n\n\t\t// Livechat conferences do not use discussions\n\n\t\tconst joinUrl = await this.getUrl(call);\n\t\tconst messageId = await this.createLivechatMessage(call, user, joinUrl);\n\t\tcall.messages.started = messageId;\n\t\tawait VideoConferenceModel.setMessageById(callId, 'started', messageId);\n\n\t\treturn {\n\t\t\ttype: 'livechat',\n\t\t\tcallId,\n\t\t};\n\t}\n\n\tprivate async joinCall(","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/server/services/video-conference/service.ts#L852-L888","documentation":"Livechat variant: VideoConferenceModel.createLivechat returned an id, but the immediate getUnfiltered(callId) read - which happens before runNewVideoConferenceEvent in this branch - yields null. No app event has run yet, so the cause is narrower than the direct/group cases: the insert itself failed to persist, a model hook removed it, or the read could not see the just-written document.","triggerScenarios":"Starting a livechat video call when the video_conference insert silently fails or is rolled back; a collection hook deleting livechat call docs; a replica-set read routed away from the node that took the write.","commonSituations":"Disk/capacity problems causing failed writes on the calls collection; custom hooks registered on video_conference for livechat; deployments where reads hit lagging secondaries.","solutions":["Confirm createLivechat actually inserted (check the returned id in the video_conference collection and server logs for write errors)","Remove or fix collection hooks that delete livechat call documents","Ensure the read after create targets the primary (or waits for write visibility) in replica-set deployments","Retry the livechat call start after fixing the write path"],"exampleFix":"// before\nconst call = (await this.getUnfiltered(callId)) as ILivechatVideoConference | null;\nif (!call) throw new Error('failed-to-create-livechat-call');\n\n// after - keep the guard, but make the write verifiable\nconst callId = await VideoConferenceModel.createLivechat({ rid, createdBy, providerName });\nif (!callId) throw new Error('failed-to-create-livechat-call'); // write returned no id\nconst call = (await this.getUnfiltered(callId)) as ILivechatVideoConference | null;\nif (!call) throw new Error('failed-to-create-livechat-call'); // read lost the doc","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n\tawait videoConfService.startLivechatCall(user, rid);\n} catch (err) {\n\tif (err instanceof Error && err.message === 'failed-to-create-livechat-call') {\n\t\t// verify the insert persisted; check DB write errors and collection hooks\n\t}\n}","preventionTips":["Monitor MongoDB write errors on the video_conference collection","Avoid collection hooks that delete livechat call documents","In dev, run a single-node mongod (or primary reads) while testing livechat calls"],"tags":["video-conference","livechat","database-consistency","write-failure"],"backgroundTag":"created-record-not-found","analyzedSha":"e4b8178b205510181a96ceefee043d0abcd13e5a","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}