{"record":{"id":"87f6a993c2e1cf69","repo":"RocketChat/Rocket.Chat","slug":"error-user-not-found-87f6a9","errorCode":"error-user-not-found","errorMessage":"Inviter not found","messagePattern":"Inviter not found","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/slashcommands/invite/server.ts","lineNumber":95,"sourceCode":"\t\t\t\tprojection: { _id: 1, status: 1 },\n\t\t\t});\n\t\t\tif (subscription == null || isBannedSubscription(subscription)) {\n\t\t\t\tusersFiltered.push(user);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst usernameStr = user.username as string;\n\t\t\tvoid api.broadcast('notify.ephemeralMessage', userId, message.rid, {\n\t\t\t\tmsg: i18n.t('Username_is_already_in_here', {\n\t\t\t\t\tusername: usernameStr,\n\t\t\t\t\tlng: settings.get('Language') || 'en',\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\n\t\tconst inviter = await Users.findOneById(userId);\n\n\t\tif (!inviter) {\n\t\t\tthrow new Meteor.Error('error-user-not-found', 'Inviter not found', {\n\t\t\t\tmethod: 'slashcommand-invite',\n\t\t\t});\n\t\t}\n\n\t\tawait Promise.all(\n\t\t\tusersFiltered.map(async (user) => {\n\t\t\t\ttry {\n\t\t\t\t\t// TODO: Refactor this to return an error if some user fails to be added\n\t\t\t\t\treturn await addUsersToRoomMethod(\n\t\t\t\t\t\tuserId,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\trid: message.rid,\n\t\t\t\t\t\t\tusers: [user.username || ''],\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinviter,\n\t\t\t\t\t);\n\t\t\t\t} catch (e: unknown) {\n\t\t\t\t\tif (isMeteorError(e)) {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/slashcommands/invite/server.ts#L77-L113","documentation":"Inside /invite, the message's userId is resolved with Users.findOneById(userId) to build the inviter; if the record is gone the command throws 'error-user-not-found' with method 'slashcommand-invite'. This is an internal invariant - the user by definition just sent the command - so hitting it means the session's uid no longer matches a live user document: the account was deleted concurrently, or clustered deployment replication lag hides the user from this node.","triggerScenarios":"User account deleted (or merged) after the message was sent but before the server processes the slash command; multi-node setups reading from a node where the users collection lags; system-injected or replayed messages carrying a stale uid.","commonSituations":"Admin deletes a spam account while its flood of /invite commands is still queued; federation or imports producing orphaned uids; test harnesses replaying recorded messages.","solutions":["Verify the uid still exists before dispatching user-triggered commands (or let the error surface as proof of a stale session)","Terminate sessions and queued jobs of deleted users to stop stale commands","In clustered deployments, ensure user lookups are consistent (read from primary) before processing commands","Re-run the invite from a valid account; the invitee logic itself is unaffected"],"exampleFix":"// before\nconst inviter = await Users.findOneById(userId);\nif (!inviter) throw new Meteor.Error('error-user-not-found', 'Inviter not found');\n\n// after\nconst inviter = await Users.findOneById(userId);\nif (!inviter) {\n\tlogger.warn(`dropping /invite from vanished user ${userId}`);\n\treturn; // stale session - do not process\n}","handlingStrategy":"try-catch","validationCode":"const inviter = await Users.findOneById(userId);\nif (!inviter) {\n\tlogger.warn(`dropping command from vanished user ${userId}`);\n\treturn;\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait handleInviteCommand(message);\n} catch (err) {\n\tif (err instanceof Meteor.Error && err.error === 'error-user-not-found') return; // stale session; ignore\n\tthrow err;\n}","preventionTips":["Terminate sessions and queued jobs when deleting user accounts","Ensure user lookups are consistent (primary reads) in multi-node deployments","Treat inviter-not-found as a stale-session signal, not a bug in invite logic"],"tags":["slash-command","invite","user-record","stale-session","race-condition"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}