Skip to content

fix(whatsapp): drain debounced inbound before close - #81246

Merged
mcaxtr merged 2 commits into
mainfrom
fix/whatsapp-debounce-close-drain
May 13, 2026
Merged

mcaxtr merged 2 commits into
mainfrom
fix/whatsapp-debounce-close-drain

Conversation

@mcaxtr

@mcaxtr mcaxtr commented May 13, 2026 •

Copy link
Copy Markdown
Member

Summary

WhatsApp batches rapid inbound messages through a debounce window. When close() starts while a batch is still pending, OpenClaw already has those messages in memory, but the socket can be closed before the batch reaches the message handler. That means user code that replies from the debounced inbound message may run too late to use the still-open socket.

This PR keeps the fix scoped to the WhatsApp listener:

  • tracks in-flight messages.upsert handlers so close waits until already-received inbound work has reached the debouncer
  • tracks pending WhatsApp debounce keys and flushes them with the existing flushKey() API before closing the socket
  • waits for any active inbound flush to finish before calling the socket close routine
  • bounds close-time draining with a timeout so shutdown cannot hang forever

The regression coverage proves that debounced inbound reply() and sendMedia() calls run before sock.end(), and that close waits for an in-flight inbound handler before draining.

Verification

  • pnpm test extensions/whatsapp/src/monitor-inbox.behavior.test.ts
  • pnpm check:changed
  • git diff --check

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: M maintainer Maintainer-authored PR labels May 13, 2026
@clawsweeper

clawsweeper Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR updates WhatsApp Web inbound shutdown to wait for in-flight messages.upsert work, flush tracked debounced inbound keys before sock.end(), add regression coverage, and add a changelog entry.

Reproducibility: yes. source-reproducible: on current main, close() detaches listeners and closes the socket while debounced entries can still be pending, and the PR adds tests that assert reply/media sends happen before sock.end(). I did not execute tests in this read-only review.

Real behavior proof
Not applicable: This is a MEMBER-authored PR with the maintainer label, so the external contributor real-behavior proof gate does not apply.

Next step before merge
No repair lane: this is an active protected maintainer-labeled PR with no discrete actionable code finding for automation to fix.

Security
Cleared: The diff only changes in-process WhatsApp listener shutdown sequencing, tests, and changelog text; it does not touch dependencies, workflows, package resolution, secrets, or external code execution.

Review details

Best possible solution:

Land the scoped WhatsApp listener drain after normal maintainer review and CI; if it lands, use it to supersede the broader flushAll() proposal at #63038.

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

Yes, source-reproducible: on current main, close() detaches listeners and closes the socket while debounced entries can still be pending, and the PR adds tests that assert reply/media sends happen before sock.end(). I did not execute tests in this read-only review.

Is this the best way to solve the issue?

Yes. The listener-local drain uses the existing flushKey() contract and tracks pending handlers, pending keys, and active flushes, which is narrower than adding a shared flushAll() API for all debouncer consumers.

What I checked:

Likely related people:

  • steipete: Recent WhatsApp monitor and monitor test history includes hot-reloaded DM policy, socket teardown, and inbox assertion work adjacent to this shutdown path. (role: recent area contributor; confidence: high; commits: 7a6f73a8aae9, 69225003820a, b42227e4767b; files: extensions/whatsapp/src/inbound/monitor.ts, extensions/whatsapp/src/inbound/lifecycle.ts, extensions/whatsapp/src/monitor-inbox.streams-inbound-messages.test-support.ts)
  • mcaxtr: Prior merged WhatsApp monitor work on reply quoting and auth/runtime reconciliation is adjacent to preserving reply/send behavior during socket transitions; this is prior current-main history, not only authorship of this PR. (role: recent adjacent contributor; confidence: high; commits: f5f0235bb18a, aa76cf43f011; files: extensions/whatsapp/src/inbound/monitor.ts)
  • vincentkoc: Recent inbound debouncer cleanup/key-accounting work and WhatsApp group inbound recovery are relevant to draining queued inbound work safely. (role: debouncer and inbound recovery contributor; confidence: medium; commits: df27091f5f69, 9b7cfd0bea88, 3de42e946a2b; files: src/auto-reply/inbound-debounce.ts, extensions/whatsapp/src/inbound/monitor.ts, extensions/whatsapp/src/monitor-inbox.streams-inbound-messages.test-support.ts)
  • juanpablodlc: Path history shows the WhatsApp debounce configuration/batching feature was introduced through prior current-main work, making this person a lower-confidence routing candidate for original behavior context. (role: original WhatsApp debounce contributor; confidence: low; commits: 4a99b9b65118; files: src/auto-reply/inbound-debounce.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 4fdd71d1867a.

@mcaxtr
mcaxtr force-pushed the fix/whatsapp-debounce-close-drain branch from a85b13c to b774e28 Compare May 13, 2026 02:04
@mcaxtr
mcaxtr merged commit 81a3de1 into main May 13, 2026
105 checks passed
@mcaxtr
mcaxtr deleted the fix/whatsapp-debounce-close-drain branch May 13, 2026 02:13
pashpashpash pushed a commit that referenced this pull request May 13, 2026
* fix(whatsapp): drain debounced inbound before close

* docs(changelog): note WhatsApp debounce close drain

(cherry picked from commit 81a3de1)
l3ocifer pushed a commit to l3ocifer/frack-openclaw that referenced this pull request May 13, 2026
* fix(whatsapp): drain debounced inbound before close

* docs(changelog): note WhatsApp debounce close drain
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* fix(whatsapp): drain debounced inbound before close

* docs(changelog): note WhatsApp debounce close drain
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* fix(whatsapp): drain debounced inbound before close

* docs(changelog): note WhatsApp debounce close drain
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* fix(whatsapp): drain debounced inbound before close

* docs(changelog): note WhatsApp debounce close drain
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
* fix(whatsapp): drain debounced inbound before close

* docs(changelog): note WhatsApp debounce close drain

(cherry picked from commit 81a3de1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant