Fix duplicate responses caused by reconnect-stacking loops
WhatsApp reconnections called startMessageLoop/startSchedulerLoop/ startIpcWatcher and setInterval again without stopping the previous instances, creating parallel loops that processed the same messages. Add guard flags so each loop starts only once per process lifetime. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -141,7 +141,14 @@ async function runTask(
|
||||
updateTaskAfterRun(task.id, nextRun, resultSummary);
|
||||
}
|
||||
|
||||
let schedulerRunning = false;
|
||||
|
||||
export function startSchedulerLoop(deps: SchedulerDependencies): void {
|
||||
if (schedulerRunning) {
|
||||
logger.debug('Scheduler loop already running, skipping duplicate start');
|
||||
return;
|
||||
}
|
||||
schedulerRunning = true;
|
||||
logger.info('Scheduler loop started');
|
||||
|
||||
const loop = async () => {
|
||||
|
||||
Reference in New Issue
Block a user