hermes-agent/scripts/whatsapp-bridge
Anthony Tran 947fdeab3b fix(whatsapp): guard bridge reconnect against hangs and unhandled rejections
startSocket() awaits useMultiFileAuthState() and fetchLatestBaileysVersion()
before it creates a socket or registers event handlers, and the close handler
re-entered it via a bare setTimeout(startSocket, ...). That leaves two
unrecoverable failure modes on a reconnect:

- a rejection is an unhandled promise rejection (fatal on modern Node)
- a hang leaves the bridge permanently disconnected with nothing left to
  retry, while its HTTP server keeps answering 503 to the gateway

The second mode was observed in the field: fetchLatestBaileysVersion() is a
plain fetch to raw.githubusercontent.com with no AbortSignal, and after a
stream:error 503 disconnect the bridge logged 'Reconnecting in 3s...' once
and then sat silent and disconnected for 27+ hours until manually restarted.

Fix, as two pure helpers in bridge_helpers.js (keeping bridge.js side-effect
free to test):

- createReconnectScheduler(): every (re)connect entry point now catches a
  failed startSocket() and reschedules it instead of dying or going silent
- createVersionResolver(): bounds the version fetch with a 15s timeout and
  falls back to the last known-good version (or the Baileys default before
  first success) instead of pending forever
2026-08-03 10:03:57 +05:30
..
allowlist.js
allowlist.test.mjs
bridge.js
bridge.native.test.mjs
bridge.reconnect.test.mjs
bridge.sendqueue.test.mjs
bridge_helpers.js
outbound_ids.js
outbound_ids.test.mjs
owner_message_gate.js
owner_message_gate.test.mjs
package-lock.json
package.json