fix(whatsapp): drain eligible pending deliveries on reconnect (#63916)

* fix(whatsapp): drain eligible pending deliveries on reconnect

* docs(changelog): note whatsapp reconnect pending drain
This commit is contained in:
Marcus Castro
2026-04-09 23:41:25 -03:00
committed by GitHub
parent ab9be8dba5
commit 95d467398e
7 changed files with 474 additions and 122 deletions

View File

@@ -1,5 +1,49 @@
import type { OpenClawConfig } from "../config/config.js";
import {
drainPendingDeliveries,
type DeliverFn,
type RecoveryLogger,
} from "../infra/outbound/delivery-queue.js";
// Public runtime/transport helpers for plugins that need shared infra behavior.
function normalizeWhatsAppReconnectAccountId(accountId?: string): string {
return (accountId ?? "").trim() || "default";
}
const WHATSAPP_NO_LISTENER_ERROR_RE = /No active WhatsApp Web listener/i;
/**
* @deprecated Prefer plugin-owned reconnect policy wired through
* `drainPendingDeliveries(...)`. This compatibility shim preserves the
* historical public SDK symbol for existing plugin callers.
*/
export async function drainReconnectQueue(opts: {
accountId: string;
cfg: OpenClawConfig;
log: RecoveryLogger;
stateDir?: string;
deliver?: DeliverFn;
}): Promise<void> {
const normalizedAccountId = normalizeWhatsAppReconnectAccountId(opts.accountId);
await drainPendingDeliveries({
drainKey: `whatsapp:${normalizedAccountId}`,
logLabel: "WhatsApp reconnect drain",
cfg: opts.cfg,
log: opts.log,
stateDir: opts.stateDir,
deliver: opts.deliver,
selectEntry: (entry) => ({
match:
entry.channel === "whatsapp" &&
normalizeWhatsAppReconnectAccountId(entry.accountId) === normalizedAccountId &&
typeof entry.lastError === "string" &&
WHATSAPP_NO_LISTENER_ERROR_RE.test(entry.lastError),
bypassBackoff: true,
}),
});
}
export * from "../infra/backoff.js";
export * from "../infra/channel-activity.js";
export * from "../infra/dedupe.js";
@@ -32,7 +76,7 @@ export * from "../infra/net/proxy-env.js";
export * from "../infra/net/proxy-fetch.js";
export * from "../infra/net/undici-global-dispatcher.js";
export * from "../infra/net/ssrf.js";
export { drainReconnectQueue } from "../infra/outbound/delivery-queue.js";
export { drainPendingDeliveries };
export * from "../infra/outbound/identity.js";
export * from "../infra/outbound/sanitize-text.js";
export * from "../infra/parse-finite-number.js";