fix(whatsapp): stop retry loop on non-retryable 440 close

This commit is contained in:
Mark Musson
2026-02-24 19:28:47 +00:00
committed by Peter Steinberger
parent def993dbd8
commit e22a2d77ba
2 changed files with 72 additions and 0 deletions

View File

@@ -31,6 +31,12 @@ import { createWebOnMessageHandler } from "./monitor/on-message.js";
import type { WebChannelStatus, WebInboundMsg, WebMonitorTuning } from "./types.js";
import { isLikelyWhatsAppCryptoError } from "./util.js";
function isNonRetryableWebCloseStatus(statusCode: unknown): boolean {
// WhatsApp 440 = session conflict ("Unknown Stream Errored (conflict)").
// This is persistent until the operator resolves the conflicting session.
return statusCode === 440;
}
export async function monitorWebChannel(
verbose: boolean,
listenerFactory: typeof monitorWebInbox | undefined = monitorWebInbox,
@@ -402,6 +408,22 @@ export async function monitorWebChannel(
break;
}
if (isNonRetryableWebCloseStatus(statusCode)) {
reconnectLogger.warn(
{
connectionId,
status: statusCode,
error: errorStr,
},
"web reconnect: non-retryable close status; stopping monitor",
);
runtime.error(
`WhatsApp Web connection closed (status ${statusCode}: session conflict). Resolve conflicting WhatsApp Web sessions, then relink with \`${formatCliCommand("openclaw channels login --channel web")}\`. Stopping web monitoring.`,
);
await closeListener();
break;
}
reconnectAttempts += 1;
status.reconnectAttempts = reconnectAttempts;
emitStatus();