Skip to content

fix(baileys): ack incoming status stanzas - #2788

Open
daniloleonecarneiro wants to merge 1 commit into
mainfrom
hotfix/baileys-status-ack
Open

daniloleonecarneiro wants to merge 1 commit into
mainfrom
hotfix/baileys-status-ack

Conversation

@daniloleonecarneiro

@daniloleonecarneiro daniloleonecarneiro commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

📋 Description

WhatsApp now sends a <status> stanza to linked devices and expects it to be acked. Baileys 7.0.0-rc.9 (shipped in 2.3.7) never acks it. After roughly 50 minutes the server ends the stream (stream errored out, ack class=status, 3–9 times per hour). The instance then reconnects and shows open, but it stops receiving messages or gets them hours late. Restarting the instance does not help.

This hotfix patches Baileys with patch-package:

  • handleStatus acks the node (sendMessageAck(node)).
  • It is registered in the offline node processor (['status', handleStatus]) and as ws.on('CB:status', ...), next to CB:notification.

Build support for the patch:

  • patch-package added as a devDependency, plus a postinstall hook.
  • Dockerfile copies patches/ before npm ci, so the image ships the patched node_modules.

The lockfile diff only adds patch-package and its dependencies.

Neither the latest Baileys releases (rc13, rc14) nor develop handle CB:status yet. develop (Baileys rc13) already has the patch-package setup, so it needs the equivalent baileys+7.0.0-rc13.patch when this is merged back.

🔗 Related Issue

Reported by the community; no issue opened.

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

🧪 Testing

  • Clean npm ci applies baileys@7.0.0-rc.9 ✔.
  • Ack test: a local WebSocket server receives what the socket sends after a <status> node is emitted on CB:status. With the patch, both the online and the offline (offline attr) paths send <ack class='status' .../>. Without the patch, nothing is sent. The same test passes inside the built Docker image.
  • docker build succeeds. The API boots on Postgres, and a new Baileys instance completes the WhatsApp handshake and returns a QR code.
  • Not tested: a paired instance staying connected past the ~50 min window. No test number was available.

✅ Checklist

  • I have performed a self-review of my code
  • My changes generate no new warnings

Summary by Sourcery

Prevent Baileys connections from stalling by acknowledging incoming status stanzas and applying the fix consistently across local and Docker installations.

Bug Fixes:

  • Ensure incoming WhatsApp status stanzas are acknowledged so linked-device connections remain able to receive messages instead of silently stalling after the server timeout.

Enhancements:

  • Add tracked third-party patch management for the Baileys dependency, including automatic application during installation and Docker builds.

Build:

  • Include the Baileys patch in Docker builds and add patch-package with its lockfile dependencies.

Documentation:

  • Document the purpose and build requirements of the patches directory.

WhatsApp now sends <status> stanzas to linked devices and expects an ack.
Baileys 7.0.0-rc.9 drops them unacknowledged, so the server ends the stream
("stream errored out", ack class=status) and the instance reconnects in a
state where it stays "open" but stops receiving messages.

Patch Baileys via patch-package to ack <status> both online (CB:status) and
in the offline node queue. The Docker builder copies patches/ before npm ci
so the postinstall hook applies it in the image.
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Sorry @daniloleonecarneiro, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 hour and 42 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Patch Baileys to acknowledge incoming status stanzas in both the online event handler and offline node processor.

  • patches/baileys+7.0.0-rc.9.patch L1-34

Configuration

Apply the Baileys patch during installation and ensure the Docker builder has the patch directory before running npm ci.

  • Dockerfile L15
  • package.json L23, L154

Documentation

Document how patches are applied and why the patches directory must remain present for Docker builds.

  • patches/README.md L1-8

Lock files and vendored code

Record the patch-package dependency and its transitive dependencies in the lockfile.

  • package-lock.json L10525-10544, L12232-12248, L12651-12781 (+9 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant