Skip to content

fix(whatsapp): patch Baileys QR auth handshake for sendUnifiedSession#74349

Closed
Sathvik-1007 wants to merge 1 commit into
openclaw:mainfrom
Sathvik-1007:fix/whatsapp-qr-pairing-unified-session
Closed

fix(whatsapp): patch Baileys QR auth handshake for sendUnifiedSession#74349
Sathvik-1007 wants to merge 1 commit into
openclaw:mainfrom
Sathvik-1007:fix/whatsapp-qr-pairing-unified-session

Conversation

@Sathvik-1007

Copy link
Copy Markdown
Contributor

Summary

  • Problem: WhatsApp QR pairing fails silently — phone shows "Logging in..." then "Couldn't link device" with no error in server logs after WhatsApp QR received.
  • Why it matters: WhatsApp channel completely unusable on current release (2026.3.8+), no workaround within OpenClaw
  • What changed: extended existing Baileys pnpm patch to port upstream PR #2294 fix — adds sendUnifiedSession telemetry that WA servers now require after pairing
  • What did NOT change (scope boundary): no Baileys version bump, no LID migration, no protobuf changes, existing media upload race fix preserved

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: WhatsApp servers began requiring sendUnifiedSession telemetry after QR pair success and presence announcement. Baileys 7.0.0-rc.9 (bundled in OpenClaw) lacks this — upstream fixed in PR #2294.
  • Missing detection / guardrail: no integration test for QR auth handshake completion (requires live WA session)
  • Contributing context (if known): WA server-side protocol change, silent failure with no error response

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: live QR pairing with physical device
  • Scenario the test should lock in: QR scan → connection.updateopen state within timeout
  • Why this is the smallest reliable guardrail: WA protocol is server-driven; unit/integration tests cannot simulate the real handshake
  • If no new test is added, why not: requires live WhatsApp session + physical device; existing 672 unit tests pass confirming no API surface regression

User-visible / Behavior Changes

WhatsApp QR pairing works again. No config changes needed.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No — same WA WebSocket, additional telemetry frame post-auth
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS ARM64 (Docker), Linux x86_64
  • Runtime/container: ghcr.io/openclaw/openclaw:latest (2026.3.13+)
  • Integration/channel: WhatsApp via Baileys 7.0.0-rc.9

Steps

  1. Enable WhatsApp plugin, restart gateway
  2. Open dashboard → Channels → WhatsApp → Show QR
  3. Scan with phone

Expected

  • Server logs connection.update → state transitions to open

Actual (before fix)

  • Server logs only WhatsApp QR received. then silence
  • Phone shows "Couldn't link device"

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets

672/672 WhatsApp extension tests pass. pnpm build clean. Reporter's side-by-side test (issue comment) confirms Baileys-specific failure vs working wwebjs with same phone/network.

Human Verification (required)

  • Verified scenarios: pnpm test:extension whatsapp (672 pass), pnpm build clean, pnpm openclaw --version runs
  • Edge cases checked: patch survives node_modules nuke + reinstall, existing media upload fix preserved, no export surface broken
  • What you did not verify: live QR pairing with physical device (no WA account available for CI)

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: WA protocol may change again requiring further patch updates
    • Mitigation: patch is surgical (4 files, additive only), easy to update or replace when Baileys releases stable version with fix included

WhatsApp servers now require sendUnifiedSession telemetry after pairing.
Without it, QR scan shows 'Logging in...' then silently fails with no
connection.update event. Patch ports the fix from upstream Baileys PR #2294:

- bump bundled WA version 1027934701 � 1035194821
- add serverTimeOffsetMs state + updateServerTimeOffset() on pair success
- emit sendUnifiedSession() after pair success and available presence
- preserve existing media upload race fix and dispatcher guard

Closes openclaw#46518
@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends the existing Baileys pnpm patch to add the sendUnifiedSession telemetry frame that WhatsApp servers now require after QR pairing, porting logic from upstream Baileys PR #2294. The implementation adds updateServerTimeOffset (to clock-sync session IDs against the WA server), getUnifiedSessionId (weekly-epoch modulo calculation), and sendUnifiedSession (fire-and-forget ib node), wiring them into the pair-success, CB:success, and presence-available handlers. The pre-existing media upload race fix and fetchAgent dispatcher guard are preserved unchanged.

Confidence Score: 4/5

Safe to merge with minor documentation clarification recommended — no correctness defects in the new logic.

Both findings are P2: an undocumented WA client version bump (scope creep vs. stated boundary) and the potentially over-eager sendUnifiedSession call on every presence-available event. Neither is a definite runtime defect, and the core sendUnifiedSession implementation and pnpm-lock.yaml hash update are correct.

patches/@[email protected] — the version bump on line 10 and the presence-available call site deserve a second look; pnpm-lock.yaml hashes are consistent and fine.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: patches/@[email protected]
Line: 9-10

Comment:
**Undocumented WA client version bump**

The WA protocol version is silently changed from `[2, 3000, 1027934701]` to `[2, 3000, 1035194821]`. The PR description states the scope boundary is "no Baileys version bump, no LID migration, no protobuf changes," yet this version number is what WA servers use to negotiate protocol capabilities and check for supported client builds. A version bump here could cause WA to enable or disable server-side features beyond the intended `sendUnifiedSession` handshake. If this bump is part of upstream PR #2294, it should be called out explicitly in the PR description and impact assessment.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: patches/@[email protected]
Line: 43-45

Comment:
**`sendUnifiedSession` fires on every presence-available transition**

`sendUnifiedSession` is already called in both the `pair-success` and `CB:success` handlers on every (re)connect. Calling it again here on every `available` presence event means it fires repeatedly throughout a session — on every reconnect cycle, network blip, or manual presence refresh. If WA's server-side requirement is only to send it once per connection establishment, this creates unnecessary `ib` frames. If periodic sends are intentional, a comment explaining the expected cadence would clarify the intent for future maintainers.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(whatsapp): patch Baileys QR auth han..." | Re-trigger Greptile

Comment on lines +9 to +10
-const version = [2, 3000, 1027934701];
+const version = [2, 3000, 1035194821];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Undocumented WA client version bump

The WA protocol version is silently changed from [2, 3000, 1027934701] to [2, 3000, 1035194821]. The PR description states the scope boundary is "no Baileys version bump, no LID migration, no protobuf changes," yet this version number is what WA servers use to negotiate protocol capabilities and check for supported client builds. A version bump here could cause WA to enable or disable server-side features beyond the intended sendUnifiedSession handshake. If this bump is part of upstream PR #2294, it should be called out explicitly in the PR description and impact assessment.

Prompt To Fix With AI
This is a comment left during a code review.
Path: patches/@[email protected]
Line: 9-10

Comment:
**Undocumented WA client version bump**

The WA protocol version is silently changed from `[2, 3000, 1027934701]` to `[2, 3000, 1035194821]`. The PR description states the scope boundary is "no Baileys version bump, no LID migration, no protobuf changes," yet this version number is what WA servers use to negotiate protocol capabilities and check for supported client builds. A version bump here could cause WA to enable or disable server-side features beyond the intended `sendUnifiedSession` handshake. If this bump is part of upstream PR #2294, it should be called out explicitly in the PR description and impact assessment.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WA client version constant (lines 9-10): This is the internal WA protocol version constant, not the Baileys npm package version. The bump from 1027934701 → 1035194821 is part of upstream Baileys PR #2294 and is required — WA servers reject the old constant after the protocol change that added sendUnifiedSession. "No Baileys version bump" in the description refers to the npm package remaining at 7.0.0-rc.9.

Comment on lines +43 to +45
+ if (type === 'available') {
+ void sendUnifiedSession();
+ }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 sendUnifiedSession fires on every presence-available transition

sendUnifiedSession is already called in both the pair-success and CB:success handlers on every (re)connect. Calling it again here on every available presence event means it fires repeatedly throughout a session — on every reconnect cycle, network blip, or manual presence refresh. If WA's server-side requirement is only to send it once per connection establishment, this creates unnecessary ib frames. If periodic sends are intentional, a comment explaining the expected cadence would clarify the intent for future maintainers.

Prompt To Fix With AI
This is a comment left during a code review.
Path: patches/@[email protected]
Line: 43-45

Comment:
**`sendUnifiedSession` fires on every presence-available transition**

`sendUnifiedSession` is already called in both the `pair-success` and `CB:success` handlers on every (re)connect. Calling it again here on every `available` presence event means it fires repeatedly throughout a session — on every reconnect cycle, network blip, or manual presence refresh. If WA's server-side requirement is only to send it once per connection establishment, this creates unnecessary `ib` frames. If periodic sends are intentional, a comment explaining the expected cadence would clarify the intent for future maintainers.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendUnifiedSession on presence-available (lines 43-45): Matches upstream exactly. WA expects periodic session telemetry, not one-shot on connect. The ib frame is tiny and fire-and-forget. Upstream wires it to presence-available because reconnect cycles re-announce presence — this keeps the session valid across network blips without requiring a full re-pair.

@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

Current main already implements the PR's central WhatsApp QR handshake fix by moving the WhatsApp plugin to baileys 7.0.0-rc11, which contains the upstream unified-session logic; the PR's rc9 patch target is now obsolete and conflicting.

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Keep the current-main baileys 7.0.0-rc11 dependency path and release it, rather than merging a stale patch against the removed rc9 package.

Do we have a high-confidence way to reproduce the issue?

Yes. The linked report gives concrete Docker/dashboard QR scan steps for the old Baileys rc9 path, and the source/dependency trail shows that path lacked upstream unified-session handling; I did not rerun live WhatsApp QR pairing.

Is this the best way to solve the issue?

Yes. Current main solves the same dependency-level gap by using baileys 7.0.0-rc11, which already contains the upstream unified-session implementation, so merging the old rc9 patch would add obsolete churn.

Security review:

Security review cleared: The PR changes only a dependency patch and lock hash; no new dependency source, lifecycle script, CI permission, secret handling, or command execution path was introduced.

What I checked:

  • Current main dependency: Current main pins the WhatsApp plugin to baileys 7.0.0-rc11, not the old @whiskeysockets/baileys 7.0.0-rc.9 package this PR patches. (extensions/whatsapp/package.json:11, 207fb9951d67)
  • Current lockfile: The lockfile uses [email protected] with the current local patch hash, so the PR's old rc9 patch hash update no longer applies. (pnpm-lock.yaml:39, 207fb9951d67)
  • Current patch scope: The remaining current-main Baileys patch is limited to media upload dispatcher guarding and logger typing; unified-session behavior now comes from the dependency itself. (patches/[email protected]:1, 207fb9951d67)
  • Dependency contract proof: The baileys 7.0.0-rc11 npm tarball contains serverTimeOffsetMs, updateServerTimeOffset, sendUnifiedSession, pair-success/login call sites, available-presence telemetry, and WhatsApp Web version 1035194821.
  • Upstream provenance: WhiskeySockets/Baileys PR 2294, feat: send unified session, was merged on 2026-01-24 and is the upstream source of the behavior this PR tried to backport. (d514764686dd)
  • OpenClaw fix provenance: Commit 85f9276 updates the WhatsApp dependency from baileys rc10 to rc11 and retargets the patch, which is the current-main implementation that supersedes this PR. (extensions/whatsapp/package.json:11, 85f9276624fc)

Likely related people:

  • steipete: Authored the current-main commit that moves the WhatsApp plugin to baileys 7.0.0-rc11, the implementation that supersedes this PR. (role: recent dependency refresh author; confidence: high; commits: 85f9276624fc, 049606326438; files: extensions/whatsapp/package.json, pnpm-lock.yaml, patches/[email protected])
  • frankekn: Merged history introduced and maintained the existing Baileys patch surface that this PR originally extended. (role: Baileys patch history contributor; confidence: medium; commits: d86527d8c6d5; files: patches/@[email protected], extensions/whatsapp/package.json, pnpm-lock.yaml)
  • mcaxtr: Recent merged work covers WhatsApp auth stabilization, QR login, session, and connection lifecycle paths adjacent to this handshake behavior. (role: WhatsApp auth and lifecycle area contributor; confidence: high; commits: aa76cf43f011; files: extensions/whatsapp/src/login-qr.ts, extensions/whatsapp/src/session.ts, extensions/whatsapp/src/connection-controller.ts)
  • BunsDev: Recent merged work kept WhatsApp QR login state synchronized across gateway/UI paths that exercise the Baileys login flow. (role: recent QR login area contributor; confidence: medium; commits: 245451b6a9c5; files: extensions/whatsapp/src/login-qr.ts, extensions/whatsapp/src/agent-tools-login.ts, extensions/whatsapp/src/connection-controller.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 207fb9951d67; fix evidence: commit 85f9276624fc, main fix timestamp 2026-05-13T10:21:17Z.

@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes:

This PR extends the local Baileys 7.0.0-rc.9 pnpm patch with unified-session/server-time telemetry hooks, updates the WhatsApp Web protocol version constant, preserves the media-upload hotfix, and refreshes the pnpm patch hash.

Maintainer follow-up before merge:

This is an active implementation PR touching patched dependency runtime/protocol behavior; the next action is maintainer review, upstream/version audit, changelog handling, and live QR proof, not an automated replacement branch.

Review details

Best possible solution:

Land a maintainer-approved WhatsApp QR pairing fix in the WhatsApp plugin path, either by auditing this surgical Baileys patch or choosing a dependency upgrade, while preserving the existing media-upload hotfixes and adding changelog credit plus live QR pairing proof.

Acceptance criteria:

  • pnpm test extensions/whatsapp
  • pnpm build
  • pnpm check:changed in Testbox for WhatsApp dependency/runtime changes
  • Live WhatsApp QR pairing with a physical device, including logs from QR receipt through connection.update open or a surfaced failure

What I checked:

  • Current main has no unified-session implementation: A current-main search for sendUnifiedSession, unified_session, serverTimeOffset, updateServerTimeOffset, TimeMs, and the proposed WhatsApp Web revision returned no matches under patches, extensions/whatsapp, or pnpm-lock.yaml; the existing local Baileys patch only contains the media upload/write-stream and dispatcher guards. (patches/@[email protected]:1, 8cf724a381a3)
  • Current dependency surface still matches the reported bug path: The WhatsApp plugin remains pinned to @whiskeysockets/baileys 7.0.0-rc.9, and the lockfile still references the older local patch hash 23ec8efe... on current main. (extensions/whatsapp/package.json:7, 8cf724a381a3)
  • QR login is still Baileys-backed: startWebLoginWithQr creates a Baileys socket via createWaSocket and logs WhatsApp QR received from the onQr callback; there is no OpenClaw-side fallback that would emit the proposed unified_session frame. (extensions/whatsapp/src/login-qr.ts:332, 8cf724a381a3)
  • PR diff is narrow and dependency-patch scoped: The PR changes only patches/@[email protected] and pnpm-lock.yaml, adding the Baileys socket/chats/defaults unified-session logic plus the new patch hash. (patches/@[email protected]:1, 6f7e5d04e191)
  • Upstream dependency comparison supports the main behavior: WhiskeySockets/Baileys PR 2294 is merged and adds server-time offset handling plus sendUnifiedSession calls on pair-success, login success, and available presence. The exact PR merge used WA version 1032141294, while current upstream master now carries 1035194821, matching this PR's version constant.
  • Security-sensitive review surface is contained but needs maintainer signoff: The diff does not add dependencies, lifecycle scripts, CI, permissions, or secret handling. It does patch compiled third-party runtime code and adds a telemetry frame over the existing WhatsApp WebSocket, so protocol/privacy behavior and live QR proof are the remaining review gates. (pnpm-lock.yaml:37, 6f7e5d04e191)

Likely related people:

  • frankekn: Recent merged history introduced and reviewed the existing Baileys 7.0.0-rc.9 pnpm patch that this PR extends. (role: Baileys patch maintainer/reviewer; confidence: medium; commits: d86527d8c6d5; files: patches/@[email protected], pnpm-lock.yaml)
  • mcaxtr: Recent merged history covers WhatsApp auth stabilization, local runtime reconciliation after login, and centralized account connection lifecycle work adjacent to this QR/session path. (role: WhatsApp auth and lifecycle maintainer; confidence: high; commits: aa76cf43f011, aa023e428306; files: extensions/whatsapp/src/session.ts, extensions/whatsapp/src/login-qr.ts, extensions/whatsapp/src/connection-controller.ts)
  • BunsDev: Recent merged work kept WhatsApp QR login state in sync across gateway, macOS, and UI wait flows, directly touching the login-qr surface involved here. (role: recent QR login maintainer; confidence: medium; commits: 245451b6a9c5; files: extensions/whatsapp/src/login-qr.ts)
  • asyncjason: Merged QR-pairing work handled Baileys 515 restart recovery in the QR login and socket recreation path, which remains adjacent to this handshake issue. (role: QR pairing restart history; confidence: medium; commits: 9d3e653ec9d2; files: extensions/whatsapp/src/login-qr.ts, extensions/whatsapp/src/session.ts)
  • vincentkoc: Recent merged history repaired WhatsApp reconnect and group inbound recovery around the same session/controller surfaces that will exercise this patched Baileys behavior after login. (role: recent WhatsApp reconnect maintainer; confidence: medium; commits: 21a92ea0f636, e672b61417af; files: extensions/whatsapp/src/session.ts, extensions/whatsapp/src/connection-controller.ts, extensions/whatsapp/src/inbound/monitor.ts)

Remaining risk / open question:

  • The PR body says live QR pairing with a physical WhatsApp account was not verified yet, which is the critical behavior for WhatsApp QR pairing fails silently on 2026.3.13 (macOS ARM64 Docker) #46518.
  • The WhatsApp Web version constant in this PR matches current upstream master but not the exact Baileys #2294 merge commit, so maintainers should confirm that combining it with the rc.9 backport is intentional.
  • The change patches compiled third-party runtime code and emits a new WhatsApp Web telemetry frame, so dependency drift and protocol/privacy behavior need explicit maintainer review.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 8cf724a381a3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WhatsApp QR pairing fails silently on 2026.3.13 (macOS ARM64 Docker)

1 participant