Skip to content

refactor(whatsapp): split inbound monitor orchestration - #115806

Merged
vincentkoc merged 7 commits into
mainfrom
refactor/whatsapp-monitor-orchestration
Jul 29, 2026
Merged

vincentkoc merged 7 commits into
mainfrom
refactor/whatsapp-monitor-orchestration

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

The WhatsApp inbound monitor concentrated socket lifecycle, metadata caching,
message admission and delivery, retry, dedupe, and shutdown behavior in one
high-context module. This made behavior-neutral maintenance risky even though
the monitor inbox already has substantial coverage.

Why This Change Was Made

This maintainer-requested refactor separates the attached socket session,
bounded group metadata cache, and message delivery coordinator, with
inbound/monitor.ts reduced to a composition root. Delivery-specific helpers
own debounce batching, identity/access normalization, and media enrichment so
each module stays below the repository line limit.

Retry, dedupe, reconnect handoff, cache invalidation, and shutdown drain
ordering remain explicit and WhatsApp-local. No transport policy moved into
core, and there is no compatibility or user-visible behavior change.

This PR is AI-assisted. I reviewed the complete branch and understand the
resulting ownership and shutdown flow.

User Impact

No user-visible behavior change. Maintainers can diagnose monitor failures from
smaller owner-specific modules and test names.

Evidence

  • node scripts/run-vitest.mjs extensions/whatsapp/src/monitor-inbox.behavior.test.ts extensions/whatsapp/src/inbound/durable-receive.test.ts extensions/whatsapp/src/inbound.media.test.ts
    • 3 files, 108 tests passed
  • Targeted oxfmt, oxlint, and git diff --check passed.
  • check-max-lines-ratchet passes after removing the obsolete
    inbound/monitor.ts baseline exception.
  • node scripts/check-deadcode-exports.mjs
    • production, full-tree, and script scans passed with zero entries
  • Fresh branch autoreview against origin/main: no accepted/actionable findings.
    One callback-variance claim was rejected because the composition root already
    narrows through normalizeAdmittedWebInboundMessage; the same code passed
    check-prod-types.
  • Ready-for-review Linux CI on 9e246deb6ef: 70 checks passed, 39
    intentionally skipped, zero failed.

@vincentkoc vincentkoc self-assigned this Jul 29, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review July 29, 2026 09:13
@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: XL maintainer Maintainer-authored PR labels Jul 29, 2026
@vincentkoc
vincentkoc marked this pull request as draft July 29, 2026 09:52
@vincentkoc
vincentkoc marked this pull request as ready for review July 29, 2026 10:01
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 9:04 AM ET / 13:04 UTC.

ClawSweeper review

What this changes

The branch splits the WhatsApp inbound monitor into dedicated socket-session, group-metadata-cache, message-normalization, enrichment, debounce, and delivery modules while retaining inbound/monitor.ts as the composition root.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for normal maintainer review. It is a maintainer-authored, maintainer-labeled WhatsApp refactor with a clean merge result and substantial targeted/CI validation, but it rewires the live inbound delivery and socket-shutdown path too broadly for automated cleanup or an evidence-free close.

Priority: P3
Reviewed head: 9e246deb6efbc9917d8fc686a98a4badea9cdd3c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch presents a coherent WhatsApp-local ownership split with focused regression coverage and successful CI, while its large lifecycle-sensitive scope still merits human area review.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR body supplies focused test and CI evidence for the refactor.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR body supplies focused test and CI evidence for the refactor.
Evidence reviewed 4 items Changed owner boundaries: The branch reduces extensions/whatsapp/src/inbound/monitor.ts to composition and moves cache, socket, normalization, enrichment, debounce, and delivery responsibilities into WhatsApp-local modules; this follows the repository preference for bounded owner-specific refactors.
Coverage and CI evidence: The PR body reports 108 focused tests across inbox, durable receive, and media paths, plus formatting, dead-code, max-lines, type checks, and a ready-for-review Linux CI run with no failures; the supplied check state also shows the relevant quality, boundary, lint, type, and compact test lanes succeeding.
Feature-history routing: The current-main history for the previous monitor path includes the centralization refactor 66743b8 by steipete and later WhatsApp delivery/identity fixes involving mcaxtr, so those are the strongest existing-history routing candidates for lifecycle-equivalence review.
Findings None None.
Security None None.

How this fits together

WhatsApp Web socket events enter the inbound monitor, which admits and normalizes messages, manages group metadata and short-lived caches, then delivers messages to the OpenClaw channel runtime. The refactor changes how those owners are composed while preserving message delivery, reconnect, retry, dedupe, and shutdown behavior.

flowchart LR
  A[WhatsApp Web socket events] --> B[Inbound monitor composition root]
  B --> C[Attached socket session]
  B --> D[Group metadata cache]
  B --> E[Delivery coordinator]
  E --> F[Admission and normalization]
  F --> G[Debounce and durable delivery]
  G --> H[OpenClaw channel runtime]
  C --> E
  D --> F
Loading

Before merge

  • Resolve merge risk (P1) - This behavior-preserving refactor moves reconnect handoff, dedupe, message admission, durable draining, and socket close ordering across several new owners; a regression could suppress or duplicate inbound WhatsApp delivery despite passing focused tests.
  • Resolve merge risk (P1) - The PR is behind its base branch, so maintainers should refresh the lifecycle review against the current merge result before landing; this is not itself a patch defect.
  • Complete next step (P2) - This protected maintainer-authored refactor needs an area-owner lifecycle review, not an automated repair or cleanup action.
Agent review details

Security

None.

PR surface

Source +297, Other -1. Total +296 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 13 2149 1852 +297
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 14 2149 1853 +296

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/whatsapp/src/auto-reply/monitor.ts, persistent cache schema: extensions/whatsapp/src/inbound/baileys-cache.ts, persistent cache schema: extensions/whatsapp/src/inbound/group-metadata-cache.ts, persistent cache schema: extensions/whatsapp/src/inbound/message-delivery.ts, persistent cache schema: extensions/whatsapp/src/inbound/message-normalization.ts, persistent cache schema: extensions/whatsapp/src/inbound/socket-session.ts, and 6 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept after lifecycle-equivalence review (recommended)
    A WhatsApp-area reviewer confirms the moved reconnect, dedupe, receipt, and close/drain paths preserve their existing ordering before merging the current merge result.
  2. Pause for a narrower runtime proof
    Hold the refactor until a focused WhatsApp monitor run demonstrates reconnect recovery and shutdown drain behavior in addition to the existing targeted suite.

Technical review

Best possible solution:

Land only after a WhatsApp-area maintainer confirms that reconnect, close/drain, dedupe, and read-receipt ownership remain equivalent at the current merge result; keep the monitor as the single composition root and the new modules WhatsApp-local.

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

Not applicable: this PR proposes a behavior-preserving internal refactor rather than correcting a reported user-facing failure. Its relevant proof is lifecycle-equivalence coverage of the existing monitor behavior.

Is this the best way to solve the issue?

Unclear: the proposed WhatsApp-local ownership split matches the repository’s bounded-refactor architecture, but the size and lifecycle sensitivity require maintainer confirmation that the new composition preserves current delivery and shutdown invariants.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 79e0b559fe46.

Labels

Label changes:

  • add P3: This is a behavior-neutral maintainability refactor rather than a reported user regression or feature request.
  • add merge-risk: 🚨 message-delivery: The diff relocates inbound admission, batching, durable delivery, retry, dedupe, and read-receipt coordination, so an ordering regression could affect WhatsApp messages.
  • add merge-risk: 🚨 availability: The refactor moves socket lifecycle and shutdown-drain ownership, where a regression could leave the channel stalled or fail to close cleanly.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR body supplies focused test and CI evidence for the refactor.

Label justifications:

  • P3: This is a behavior-neutral maintainability refactor rather than a reported user regression or feature request.
  • merge-risk: 🚨 message-delivery: The diff relocates inbound admission, batching, durable delivery, retry, dedupe, and read-receipt coordination, so an ordering regression could affect WhatsApp messages.
  • merge-risk: 🚨 availability: The refactor moves socket lifecycle and shutdown-drain ownership, where a regression could leave the channel stalled or fail to close cleanly.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor real-behavior-proof gate does not apply; the PR body supplies focused test and CI evidence for the refactor.

Evidence

What I checked:

  • Changed owner boundaries: The branch reduces extensions/whatsapp/src/inbound/monitor.ts to composition and moves cache, socket, normalization, enrichment, debounce, and delivery responsibilities into WhatsApp-local modules; this follows the repository preference for bounded owner-specific refactors. (extensions/whatsapp/src/inbound/monitor.ts:1, 9e246deb6efb)
  • Coverage and CI evidence: The PR body reports 108 focused tests across inbox, durable receive, and media paths, plus formatting, dead-code, max-lines, type checks, and a ready-for-review Linux CI run with no failures; the supplied check state also shows the relevant quality, boundary, lint, type, and compact test lanes succeeding. (extensions/whatsapp/src/monitor-inbox.streams-inbound-messages.test-support.ts:272, 9e246deb6efb)
  • Feature-history routing: The current-main history for the previous monitor path includes the centralization refactor 66743b8 by steipete and later WhatsApp delivery/identity fixes involving mcaxtr, so those are the strongest existing-history routing candidates for lifecycle-equivalence review. (extensions/whatsapp/src/inbound/monitor.ts:1, 66743b8)
  • Protected maintainer handling: The supplied GitHub context identifies the author as a MEMBER and the PR carries the maintainer label. Repository policy keeps maintainer-authored and protected-label PRs open for explicit maintainer handling.

Likely related people:

  • steipete: Current-main history attributes the monitor-state centralization refactor and subsequent plugin-boundary work on the monitor path to this contributor. (role: feature-history contributor; confidence: high; commits: 66743b8, e4b5027, 25a1875; files: extensions/whatsapp/src/inbound/monitor.ts)
  • mcaxtr: Current-main history shows recent WhatsApp fixes for self-chat notifications and outbound-echo handling on the monitor’s delivery/identity invariants. (role: recent behavior contributor; confidence: medium; commits: e1c9678, e45533d; files: extensions/whatsapp/src/inbound/monitor.ts, extensions/whatsapp/src/inbound/message-normalization.ts)
  • vincentkoc: The PR author also appears in prior merged WhatsApp CI work and authored the current seven-commit monitor refactor series. (role: recent area contributor; confidence: medium; commits: 1929599, 703826c, 3b1cbbe; files: extensions/whatsapp/src/inbound/monitor.ts, extensions/whatsapp/src/inbound/socket-session.ts, extensions/whatsapp/src/inbound/message-delivery.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the reconnect, shutdown-drain, dedupe, and receipt-order review against the current merge result before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant