{"record":{"id":"5d95bb63a2866953","repo":"RocketChat/Rocket.Chat","slug":"invalid-app-user-cannot-transfer","errorCode":null,"errorMessage":"Invalid app user, cannot transfer","messagePattern":"Invalid app user, cannot transfer","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/app/apps/server/bridges/livechat.ts","lineNumber":269,"sourceCode":"\t\t\tshouldConsiderIdleAgent: settings.get<boolean>('Livechat_enabled_when_agent_idle'),\n\t\t\tshouldConsiderOfflineAgent: settings.get<boolean>('Livechat_accept_chats_with_no_agents'),\n\t\t});\n\n\t\treturn this.orch.getConverters()?.get('visitors').convertVisitor(livechatVisitor);\n\t}\n\n\tprotected async transferVisitor(visitor: IVisitor, transferData: ILivechatTransferData, appId: string): Promise<boolean> {\n\t\tthis.orch.debugLog(`The App ${appId} is transfering a livechat.`);\n\n\t\tif (!visitor) {\n\t\t\tthrow new Error('Invalid visitor, cannot transfer');\n\t\t}\n\n\t\tconst { targetAgent, targetDepartment: departmentId, currentRoom } = transferData;\n\n\t\tconst appUser = await Users.findOneByAppId(appId, {});\n\t\tif (!appUser) {\n\t\t\tthrow new Error('Invalid app user, cannot transfer');\n\t\t}\n\t\tconst { _id, username, name, type } = appUser;\n\t\tconst transferredBy = {\n\t\t\t_id,\n\t\t\tusername,\n\t\t\tname,\n\t\t\ttype,\n\t\t\tuserType: 'user',\n\t\t} as const;\n\n\t\tlet userId;\n\t\tlet transferredTo;\n\n\t\tif (targetAgent?.id) {\n\t\t\ttransferredTo = await Users.findOneAgentById(targetAgent.id, {\n\t\t\t\tprojection: { _id: 1, username: 1, name: 1 },\n\t\t\t});\n\t\t\tif (!transferredTo) {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/app/apps/server/bridges/livechat.ts#L251-L287","documentation":"Thrown by AppLivechatBridge.transferVisitor when Users.findOneByAppId(appId) returns null. Every installed App has a provisioned system user (the app user) used as the transferredBy actor; if it cannot be found the transfer cannot proceed. This points at an App installation/provisioning problem rather than a transfer-input problem.","triggerScenarios":"An App invokes the transfer accessor; the bridge looks up its own provisioned user via Users.findOneByAppId(appId) and gets null, e.g. the App's system user was deleted, the appId is stale, or provisioning did not complete.","commonSituations":"App's system user was removed manually or by a cleanup job; App was partially uninstalled/reinstalled and the user record is missing; appId mismatch after an App re-import; a DB restore that omitted the apps' user documents.","solutions":["Reinstall or re-enable the App so its system user is reprovisioned.","Confirm the App's system user exists in the Users collection (type 'app').","Check the App lifecycle hooks ran on install (enableApp provisioning).","Avoid manually deleting users whose type is 'app'."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const appUser = await Users.findOneByAppId(appId, {});\nif (!appUser) {\n  throw new Error(`App ${appId} is not provisioned (system user missing); reinstall the App`);\n}\nawait app.getLivechatModifier().transferVisitor(visitor, transferData);","typeGuard":"const isAppProvisioned = async (appId: string): Promise<boolean> =>\n  Boolean(await Users.findOneByAppId(appId, { projection: { _id: 1 } }));","tryCatchPattern":"try {\n  return await app.getLivechatModifier().transferVisitor(visitor, transferData);\n} catch (e) {\n  if ((e as Error).message === 'Invalid app user, cannot transfer') {\n    // prompt reinstall/re-enable of the App, then retry\n  }\n  throw e;\n}","preventionTips":["Do not manually delete users whose type is 'app'.","Reinstall/re-enable Apps to reprovision their system users.","After a DB restore, verify App system users are present."],"tags":["apps-engine","livechat","transfer","app-user","provisioning"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}