{"record":{"id":"dcb96a203e68fa6d","repo":"RocketChat/Rocket.Chat","slug":"autocloseonholdscheduler-is-not-running","errorCode":null,"errorMessage":"AutoCloseOnHoldScheduler is not running","messagePattern":"AutoCloseOnHoldScheduler is not running","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/lib/omnichannel/AutoCloseOnHoldScheduler.ts","lineNumber":46,"sourceCode":"\t\tif (this.running) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.scheduler = new Agenda({\n\t\t\tmongo: (MongoInternals.defaultRemoteCollectionDriver().mongo as any).client.db(),\n\t\t\tdb: { collection: SCHEDULER_NAME },\n\t\t\tdefaultConcurrency: 1,\n\t\t\tprocessEvery: process.env.TEST_MODE === 'true' || process.env.TEST_MODE === 'api' ? '3 seconds' : '1 minute',\n\t\t});\n\n\t\tawait this.scheduler.start();\n\t\tthis.running = true;\n\t\tthis.logger.info('Service started');\n\t}\n\n\tpublic async scheduleRoom(roomId: string, timeout: number, comment: string): Promise<void> {\n\t\tif (!this.running) {\n\t\t\tthrow new Error('AutoCloseOnHoldScheduler is not running');\n\t\t}\n\n\t\tthis.logger.debug({ msg: 'Scheduling room to be closed', roomId, timeoutSeconds: timeout });\n\t\tawait this.unscheduleRoom(roomId);\n\n\t\tconst jobName = `${SCHEDULER_NAME}-${roomId}`;\n\t\tconst when = moment(new Date()).add(timeout, 's').toDate();\n\n\t\tthis.scheduler.define(jobName, this.executeJob.bind(this));\n\t\tawait this.scheduler.schedule(when, jobName, { roomId, comment });\n\t}\n\n\tpublic async unscheduleRoom(roomId: string): Promise<void> {\n\t\tif (!this.running) {\n\t\t\tthrow new Error('AutoCloseOnHoldScheduler is not running');\n\t\t}\n\t\tthis.logger.debug({ msg: 'Unscheduling room', roomId });\n\t\tconst jobName = `${SCHEDULER_NAME}-${roomId}`;","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/ee/server/lib/omnichannel/AutoCloseOnHoldScheduler.ts#L28-L64","documentation":"AutoCloseOnHoldScheduler.scheduleRoom throws if the service's running flag is false: the agenda-backed scheduler was never started (its start() had not completed) or was already stopped. scheduleRoom arms the auto-close timer when an omnichannel room is put on hold.","triggerScenarios":"Putting an omnichannel room on hold (which schedules auto-close) before AutoCloseOnHoldScheduler.start() completed during server startup, or after the service stopped; also in tests that use the scheduler without starting it.","commonSituations":"Livechat traffic arriving during startup; an earlier silent start() failure (Mongo/agenda connectivity); TEST_MODE misconfigured so startup ordering differs.","solutions":["Confirm the service actually started: look for the 'Service started' log from AutoCloseOnHoldScheduler","If start() failed, fix the underlying agenda/Mongo connection issue and restart the server","Guard early code paths with the scheduler's running flag and re-queue the operation once started"],"exampleFix":"// before\nawait scheduler.scheduleRoom(roomId, timeout, comment); // throws if not running\n\n// after\nif (!schedulerRunning()) {\n\tawait startScheduler();\n}\nawait scheduler.scheduleRoom(roomId, timeout, comment);","handlingStrategy":"validation","validationCode":"if (!scheduler.isRunning?.()) {\n\tawait scheduler.start();\n}\nawait scheduler.scheduleRoom(roomId, timeout, comment);","typeGuard":null,"tryCatchPattern":"try {\n\tawait scheduler.scheduleRoom(roomId, timeout, comment);\n} catch (err) {\n\tif (err instanceof Error && err.message === 'AutoCloseOnHoldScheduler is not running') {\n\t\t// engine not ready: re-queue after start completes; do not drop the room event\n\t} else {\n\t\tthrow err;\n\t}\n}","preventionTips":["Start the scheduler service before wiring livechat on-hold handlers","Verify the 'Service started' log during startup checks","In tests, always start the scheduler with short processEvery under TEST_MODE"],"tags":["omnichannel","scheduler","startup","on-hold"],"backgroundTag":"scheduler-not-started","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"}