{"record":{"id":"cff578c9e08c1c73","repo":"RocketChat/Rocket.Chat","slug":"room-id-not-found","errorCode":null,"errorMessage":"Room id not found","messagePattern":"Room id not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/meteor/app/apps/server/bridges/rooms.ts","lineNumber":239,"sourceCode":"\n\tprotected async getDirectByUsernames(usernames: Array<string>, appId: string): Promise<IRoom | undefined> {\n\t\tthis.orch.debugLog(`The App ${appId} is getting direct room by usernames: \"${usernames}\"`);\n\t\tconst room = await Rooms.findDirectRoomContainingAllUsernames(usernames, {});\n\t\tif (!room) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.orch.getConverters()?.get('rooms').convertRoom(room);\n\t}\n\n\tprotected async update(room: IRoom, members: Array<string> = [], appId: string): Promise<void> {\n\t\tthis.orch.debugLog(`The App ${appId} is updating a room.`);\n\n\t\tconst rm = await this.orch.getConverters()?.get('rooms').convertAppRoom(room, true);\n\n\t\tconst updateResult = await Rooms.updateOne({ _id: room.id }, { $set: rm });\n\n\t\tif (!updateResult.matchedCount) {\n\t\t\tthrow new Error('Room id not found');\n\t\t}\n\n\t\tfor (const username of members) {\n\t\t\tconst member = await Users.findOneByUsername(username, {});\n\n\t\t\tif (!member) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tawait addUserToRoom(room.id, member);\n\t\t}\n\t}\n\n\tprotected async delete(roomId: string, appId: string): Promise<void> {\n\t\tthis.orch.debugLog(`The App ${appId} is deleting a room.`);\n\t\tawait deleteRoom(roomId);\n\t}\n","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/app/apps/server/bridges/rooms.ts#L221-L257","documentation":"AppRoomBridge.update performs Rooms.updateOne({ _id: room.id }, { $set: rm }) and throws 'Room id not found' when matchedCount is 0 — i.e. no room document exists with that id (deleted, never existed, or from a different database). The apps-engine room object's id is stale at update time.","triggerScenarios":"The room was deleted between when the app fetched it and when it called update; room.id came from persisted/cached state after a DB restore or migration; a hand-typed or user-supplied id with a typo.","commonSituations":"Long-running apps caching room ids; rooms removed by retention/cleanup policies; workspaces re-imported without old room ids; race between moderators deleting rooms and app background jobs.","solutions":["Verify existence first with the room reader (read.getRoomById) before updating","On failure, re-fetch fresh state and retry once; if still missing, discard the cached id","Avoid persisting room ids beyond their usefulness; resolve ids at execution time","Validate user-supplied room ids against the reader before attempting updates"],"exampleFix":"// before\nawait app.getRocketChat().getChat().updateRoom(cachedRoom, members); // room deleted -> throws\n// after\nconst fresh = await this.read.getRoomById(cachedRoom.id);\nif (!fresh) { app.getLogger().warn('room no longer exists, dropping state'); return; }\nawait app.getRocketChat().getChat().updateRoom(fresh, members);","handlingStrategy":"validation","validationCode":"const fresh = await this.read.getRoomById(room.id);\nif (!fresh) {\n  app.getLogger().warn(`room ${room.id} no longer exists; dropping cached state`);\n  return;\n}\nawait app.getRocketChat().getChat().updateRoom(fresh, members);","typeGuard":null,"tryCatchPattern":"try {\n  await app.getRocketChat().getChat().updateRoom(room, members);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Room id not found') {\n    const fresh = await this.read.getRoomById(room.id);\n    if (!fresh) return; // room deleted — drop state\n    return app.getRocketChat().getChat().updateRoom(fresh, members); // retry once with fresh data\n  }\n  throw err;\n}","preventionTips":["Check room existence via the reader before every update","Resolve room ids at execution time instead of caching them long-term","Handle deletion races gracefully — rooms disappear via retention and moderation","Validate any user-supplied room id against the reader before writing"],"tags":["apps-engine","rooms","update","not-found","stale-id"],"backgroundTag":"record-not-found","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"}