Skip to content

[Bug]: WhatsApp QR pairing fails 100% on Baileys v7 — getStatusCode() never unwraps lastDisconnect wrapper, 515 restart path is dead code #33961

@asyncjason

Description

@asyncjason

Bug type

Behavior bug (incorrect output/state without crash)

Summary

WhatsApp QR pairing fails 100% of the time on Baileys v7 — 515 restart signal is never detected

Channel: whatsapp-web
Severity: Critical (complete feature breakage)

Description

WhatsApp QR pairing always fails with "WhatsApp login failed: status=515 Unknown Stream Errored (restart required)". The 515 "restart required" signal that Baileys sends during the key exchange is never detected, so the reconnect-with-saved-creds path (restartLoginSocket) is dead code.

Root Cause

getStatusCode() in src/web/session.ts receives a wrapper object { error: BoomError, date } from lastDisconnect, but only checks err.output?.statusCode and err.status — it never unwraps the .error property. This means login.errorStatus is always undefined when a 515 is received, the === 515 check never matches, and restartLoginSocket is never called.

Additionally, restartLoginSocket creates a new socket immediately after closing the old one without waiting for pending credential writes to flush. Even if the 515 were detected, useMultiFileAuthState would read stale/empty creds.

Steps to Reproduce

  1. Configure a WhatsApp channel in OpenClaw
  2. Start QR login via web.login.start
  3. Scan the QR code with WhatsApp on phone

Expected

After 515, socket restarts with saved creds, connection completes, "Linked!" message returned.

Actual

getStatusCode({ error: BoomError(515), date })undefined → 515 check never matches → restartLoginSocket never called → pairing fails → creds directory is empty on disk.

Environment

  • Baileys: @whiskeysockets/baileys v7.0.0-rc.9
  • Runtime: Node v22
  • OS: Debian Bookworm (Docker)

Proposed Fix

  1. Add err.error?.output?.statusCode fallback to getStatusCode() so it unwraps the lastDisconnect wrapper
  2. Export waitForCredsSaveQueue() from session.ts
  3. restartLoginSocket awaits creds flush before creating the new socket

Files affected: src/web/session.ts, src/web/login-qr.ts, src/web/login-qr.test.ts

Steps to reproduce

  1. Configure a WhatsApp channel in OpenClaw
  2. Start QR login via web.login.start
  3. Scan the QR code with WhatsApp on phone
  4. Observe pairing fails with status=515 Unknown Stream Errored (restart required)

Expected behavior

After Baileys sends the 515 "restart required" signal, the socket restarts with saved credentials and the connection completes successfully.

Actual behavior

getStatusCode() fails to unwrap the lastDisconnect wrapper object { error: BoomError, date }, returning undefined instead of 515. The restart path never triggers, credentials are never saved, and pairing fails every time.

OpenClaw version

2026.3.2

Operating system

Debian 13

Install method

Docker

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbug:behaviorIncorrect behavior without a crash

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions