#9515: fix(web): retry WhatsApp 515 restart up to 3 times with delay
channel: whatsapp-web
stale
Cluster:
WhatsApp Connection Stability Fixes
## Problem
The WhatsApp login flow only allowed a single restart attempt after a 515 error ("own on stream" / restart required after pairing). If the retry also failed with 515, the login state was cleaned up and subsequent polls returned "No active WhatsApp login in progress" indefinitely — the polling modal stayed open but never recovered.
## Changes
- Replace boolean `restartAttempted` with `restartCount` (max 3 retries)
- Add 1.5s delay between disconnect and reconnect (server cooldown)
- Reset login TTL on each retry so retries have enough time
## Testing
Existing test passes (adjusted for the new retry counter and delay).
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR updates the WhatsApp web QR login retry logic for disconnect status `515` by replacing the one-shot `restartAttempted` flag with a `restartCount` capped at 3, adding a 1.5s reconnect delay, and resetting the login TTL (`startedAt`) on each retry so subsequent polling has enough time to complete.
The change is contained to `src/web/login-qr.ts`, specifically the `restartLoginSocket(...)` helper invoked from `waitForWebLogin(...)` when `login.errorStatus === 515`.
<h3>Confidence Score: 4/5</h3>
- This PR is close to safe to merge but has a race that can resurrect a stale login/socket during the added retry delay.
- Logic is localized and the retry counter/delay are straightforward, but `restartLoginSocket` now introduces an awaited delay without any cancellation/active-login check, and it mutates the `login` object after the delay. That creates a concrete stale-reference hazard if the login is reset/replaced while waiting.
- src/web/login-qr.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#3071: fix: WhatsApp 515 error retry not triggering
by rabsef-bicrym · 2026-01-28
85.5%
#9727: fix(whatsapp): retry reconnect loop on initial connection failure
by luizlf · 2026-02-05
83.8%
#17487: fix: WhatsApp connection stability - continue reconnection after ma...
by MisterGuy420 · 2026-02-15
79.7%
#16923: fix(web): resolve stale socket race condition in WhatsApp auto-reply
by dorukardahan · 2026-02-15
75.9%
#19303: Fix WhatsApp internal error leakage + cron.run timeout defaults
by koala73 · 2026-02-17
75.9%
#13764: feat(whatsapp): add --qr-png option to save QR code as PNG file
by aorfevre · 2026-02-11
74.6%
#16628: feat(web): implement three-tier graduated retry strategy
by KrE80r · 2026-02-14
74.3%
#11249: fix(whatsapp): prevent pairing-mode auto-replies to unknown DMs
by liuxiaopai-ai · 2026-02-07
72.8%
#4181: fix(whatsapp): resolve Brazilian mobile JID variants (8/9 digit)
by lucasmpramos · 2026-01-29
72.6%
#6302: fix: Add timeouts to prevent indefinite hangs (issues #4954, #4956,...
by batumilove · 2026-02-01
72.5%