{"record":{"id":"fe724c6564e4dd48","repo":"RocketChat/Rocket.Chat","slug":"error-not-found","errorCode":"error-not-found","errorMessage":"error-not-found","messagePattern":"error-not-found","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/omnichannel/takeInquiry.ts","lineNumber":18,"sourceCode":"import { Omnichannel } from '@rocket.chat/core-services';\nimport { LivechatInquiry, LivechatRooms, Users } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { RoutingManager } from './RoutingManager';\nimport { isAgentAvailableToTakeContactInquiry } from './contacts/isAgentAvailableToTakeContactInquiry';\nimport { migrateVisitorIfMissingContact } from './contacts/migrateVisitorIfMissingContact';\nimport { settings } from '../../settings';\n\nexport const takeInquiry = async (\n\tuserId: string,\n\tinquiryId: string,\n\toptions?: { clientAction: boolean; forwardingToDepartment?: { oldDepartmentId: string; transferData: any } },\n): Promise<void> => {\n\tconst inquiry = await LivechatInquiry.findOneById(inquiryId);\n\n\tif (!inquiry) {\n\t\tthrow new Meteor.Error('error-not-found', 'Inquiry not found', {\n\t\t\tmethod: 'livechat:takeInquiry',\n\t\t});\n\t}\n\n\tif (inquiry.status === 'taken') {\n\t\tthrow new Meteor.Error('error-inquiry-taken', 'Inquiry already taken', {\n\t\t\tmethod: 'livechat:takeInquiry',\n\t\t});\n\t}\n\n\tconst user = await Users.findOneOnlineAgentById(\n\t\tuserId,\n\t\tsettings.get<boolean>('Livechat_enabled_when_agent_idle'),\n\t\tsettings.get<boolean>('Livechat_accept_chats_with_no_agents'),\n\t\t{},\n\t);\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-agent-status-service-offline', 'Agent status is offline or Omnichannel service is not active', {","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/takeInquiry.ts#L1-L36","documentation":"takeInquiry loads the queued LivechatInquiry by id; if LivechatInquiry.findOneById returns null it throws Meteor.Error('error-not-found', 'Inquiry not found', { method: 'livechat:takeInquiry' }). Inquiries are ephemeral queue entries that are deleted once handled, so this usually means the entry was already consumed or never existed.","triggerScenarios":"Calling livechat:takeInquiry with an inquiryId from a stale queue listing — another agent took (and the inquiry was removed/retargeted) between rendering the queue and clicking, or the id is simply invalid.","commonSituations":"Race between multiple agents on a fast-moving queue, stale open tabs showing already-handled inquiries, client retries after a timeout, or UI not subscribing to inquiry change events.","solutions":["Refresh the inquiry list from the real-time subscription before retrying the take action","Handle this code as an expected outcome in the queue UI (silently drop the card / show 'already handled')","Verify the inquiryId being sent matches a doc: db.rocketchat_livechat_inquiry.findOne({_id: inquiryId})","Ensure clients subscribe to livechat inquiry stream events so lists stay current"],"exampleFix":"// before\nawait Meteor.callAsync('livechat:takeInquiry', inquiryId);\n\n// after\nconst inquiry = await LivechatInquiry.findOneById(inquiryId);\nif (!inquiry) {\n  // stale queue entry — refresh the list instead of erroring\n  return refreshQueue();\n}\nawait Meteor.callAsync('livechat:takeInquiry', inquiryId);","handlingStrategy":"validation","validationCode":"import { LivechatInquiry } from '@rocket.chat/models';\n\nconst inquiry = await LivechatInquiry.findOneById(inquiryId);\nif (!inquiry) {\n  return { stale: true }; // drop the card; do not call takeInquiry\n}\nawait Meteor.callAsync('livechat:takeInquiry', inquiryId);","typeGuard":"function isTakeableInquiry(v: { status?: string } | null | undefined): v is { _id: string; status: 'queued' } {\n  return !!v && v.status === 'queued';\n}","tryCatchPattern":"try {\n  await Meteor.callAsync('livechat:takeInquiry', inquiryId);\n} catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-not-found') {\n    // stale queue entry: refresh the list and remove the card, never retry the same id\n  } else {\n    throw err;\n  }\n}","preventionTips":["Subscribe to livechat inquiry stream events so queue lists stay current","Remove/disable take actions for entries older than a refresh interval","On API timeouts, re-fetch the inquiry before retrying take"],"tags":["omnichannel","inquiry","queue","race-condition","entity-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}