Fix duplicate WhatsApp outbound delivery.

Claim pending rows atomically and serialize the sidecar poller so overlapping polls cannot send the same reply twice; also stop inbound queue delivery from falling through to a second enqueue.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-07-22 11:41:52 +08:00
parent 10ae4abc1d
commit b6e023cd91
6 changed files with 193 additions and 14 deletions

View file

@ -973,10 +973,17 @@ async function pollOutboundQueue(sock: ReturnType<typeof makeWASocket>): Promise
function startOutboundPoller(getSock: () => ReturnType<typeof makeWASocket> | null): void {
const intervalMs = Number(process.env.OCLAW_WHATSAPP_OUTBOUND_POLL_MS || "1000") || 1000;
// Overlapping polls used to claim the same pending row twice (send → duplicate WhatsApp
// bubbles) once inbound replies also went through the outbound queue.
let pollInFlight = false;
setInterval(() => {
if (pollInFlight) return;
const s = getSock();
if (!s) return;
void pollOutboundQueue(s);
pollInFlight = true;
void pollOutboundQueue(s).finally(() => {
pollInFlight = false;
});
}, Math.max(1000, intervalMs));
}