fix(whatsapp): harden bridge reconnection supervision - #75700
Open
Dannyzen wants to merge 1 commit into
Open
Conversation
teknium1
reviewed
Jul 31, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for hardening the bridge supervision. The timeout/cache and reconnect-scheduling work addresses behavior still present in current main (scripts/whatsapp-bridge/bridge.js:398,452).
Problems
- The Python poll-task handoff is already covered centrally: current
gateway/run.py:6853-6879detaches and shields fatal handling, and queues retryable adapters atgateway/run.py:6970-6986(introduced by2ab153218ba4). The WhatsApp-specific hunk and its regression test should be removed or re-scoped. - The new generation fence does not cover all events.
scripts/whatsapp-bridge/bridge.js:446still accepts stalecreds.update; QR handling at lines 451-459 runs before the generation checks; and the latermessages.update/messages.upsertlisteners remain unguarded. A stale socket can therefore still affect credentials, pairing output, or inbound handling after replacement.
Suggested changes
- Guard every socket callback at entry with the captured generation, bind listeners to
currentSock, and add a two-socket regression test covering stale credentials, QR, and inbound events. - Remove the adapter-specific handoff portion now supplied by the shared runner.
Automated hermes-sweeper review.
| }, 45_000); | ||
|
|
||
| sock.ev.on('creds.update', () => { saveCreds(); lidToPhone = buildLidMap(); }); | ||
| currentSock.ev.on('creds.update', () => { saveCreds(); lidToPhone = buildLidMap(); }); |
Contributor
There was a problem hiding this comment.
This listener still accepts events from a replaced socket. Add if (sock !== currentSock) return; before saving credentials (and apply the same captured-generation guard before QR and all message callbacks); otherwise the stated stale-event fence does not cover credential or inbound-event state.
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GatewayRunnerwithout the poll task cancelling itself during teardown.Problem
When the managed Node bridge exits inside the adapter poll task, the fatal-error handler tears the adapter down from a child task.
disconnect()then cancels the still-recorded poll task, aborting the parent beforeGatewayRunnercan queue background reconnection.The Node bridge also had unbounded version discovery and raw
setTimeout(startSocket, ...)calls. A stalled discovery or repeated/early close event could wedge startup, overlap sockets, or silently drop the next reconnect.Behavior
Verification
./scripts/run_tests.sh tests/gateway/test_whatsapp_connect.py -q(14 passed)node --test reconnect.test.js allowlist.test.mjs bridge.sendqueue.test.mjs outbound_ids.test.mjs owner_message_gate.test.mjs(28 passed)node bridge.native.test.mjsnode --check scripts/whatsapp-bridge/bridge.jsnode --check scripts/whatsapp-bridge/reconnect.jsgit diff --check14d789fcc3394ea53403e2b2f61c36cb881faf1c50073a27d19d9b4e27a661f2: no security or logic findingsRelated work
#73795 changes which WhatsApp Web version resolver is preferred. This PR is complementary: its cache/timeout wrapper can bound whichever resolver wins. If #73795 lands first, the overlap is limited to the version-discovery call site.
No package manifest or lockfile changes are included.