Skip to content

improve(whatsapp): reuse inbound message projection - #127958

Merged
steipete merged 1 commit into
mainfrom
codex/perf-whatsapp-inbound-projection
Aug 22, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-whatsapp-inbound-projection

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

After WhatsApp inbound authorization, ordinary message enrichment repeatedly rebuilt the same immutable Baileys normalized/future-proof wrapper chain for location, contacts, ad context, media kind, text, reply context, direct-media probing, and mentions.

Why This Change Was Made

Build one WhatsApp-owner-local readonly projection after authorization and reuse it across enrichment. Standalone extractor and media callers retain their existing normalization fallbacks. The projection type remains private, and only the narrow derived mentionedJids fact leaves enrichment; provider message references do not reach callbacks, persistence, core, protocol, config, or the public SDK.

The direct-media handoff uses projection entry zero, which is exactly the Baileys normalizeMessageContent(msg.message) result that the media owner previously computed itself. Later entries are extraction-only future-proof payloads.

User Impact

Accepted WhatsApp inbound messages perform less repeated wrapper normalization and projection, with no user-visible behavior, routing, policy, media, mention, persistence, or configuration change.

Evidence

  • Exact current parent 71b5de40611144b2406c0d28c9cc459b64b693bb; exact PR head fcc5e6ced962e086c4a7fd07d5205a1104f10e75.
  • Deterministic owner probe: the unchanged base owner performed 8 normalizeMessageContent calls for an ordinary text message and failed the <= 2 invariant; the candidate performs exactly 2 and preserves body hello. The implementation-coupled probe was removed after red/green proof per test-audit.
  • Exact base/candidate differential covered ordinary text, ephemeral wrappers, future-proof payloads, quoted messages/media, mentions, image/ad/media, contacts, location, native flows, protocol-only messages, malformed quote context, and provider-envelope failures with byte-identical canonical output SHA-256 e3af3bbd0289ca164a2ac26b2a86fe10ae11bcc980842fcec2808ab2565a8d07.
  • Owner microstage benchmark including production mention projection: 20,000 representative messages, 3 warmups and 9 alternating samples, median 34.4696 ms → 26.1878 ms (24.03% reduction); checksums were identical at 5,040,000. This is not an end-to-end throughput claim.
  • Identical base/candidate owner+sibling set: 10 files, 179 tests passed each.
  • Full bundled WhatsApp extension: 96 files, 1,315 tests passed.
  • Exact final owner/media recheck: 3 files, 93 tests passed.
  • node scripts/check-changed.mjs -- <five changed paths> passed all extension production/test typechecks, format, Oxlint, dead-export, boundary, ratchet, storage/media, and import-cycle gates. The final current-parent assertion ratchet also passed after an unrelated same-file baseline update on main.
  • GIT_BRANCH=main pnpm build passed all TS/plugin/postbuild/UI phases; Control UI startup gzip remained within its committed tolerance.
  • Production diff is +83/−51 across four WhatsApp owner files; the assertion-safety baseline is +2/−2. No test-only seam or timing test is retained.
  • TruffleHog and exact-final-commit Codex Sol/high autoreview passed with no accepted/actionable P0/P1 finding.
  • No live WhatsApp service was invoked. The repair is an owner-local immutable projection reuse covered by deterministic red/green proof, exact semantic differential, media/wrapper tests, and the full extension suite.

@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: S maintainer Maintainer-authored PR labels Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for exact head fcc5e6ced962e086c4a7fd07d5205a1104f10e75 on base 71b5de40611144b2406c0d28c9cc459b64b693bb:

  • Exact-head CI run 32579329995: 112 jobs, 96 succeeded / 16 skipped / 0 failed; openclaw/ci-gate succeeded.
  • Local behavior proof: temporary base/candidate probe showed ordinary-text normalization calls 8 → 2 while preserving hello; exact semantic differential remained byte-identical (e3af3bbd0289ca164a2ac26b2a86fe10ae11bcc980842fcec2808ab2565a8d07). The implementation-coupled probe was removed after red/green proof.
  • Performance: 20,000-message owner benchmark median 34.4696 → 26.1878 ms (24.03% reduction), identical checksum 5,040,000.
  • Verification: base and candidate owner/sibling sets 179/179; full WhatsApp extension 1,315/1,315; final focused owner/media 93/93; changed-file gate and full build passed.
  • Native review: 0 findings, READY FOR /prepare-pr; production +83/-51 across four WhatsApp owner files, test code unchanged, assertion baseline +2/-2.
  • ClawSweeper exact-review run 32579334194: patch correct (0.82 confidence), no findings, security cleared, no maintainer decision, and no rank-up moves. Its terminal command passed all 84 tests; the proof was marked partial only because Vitest output did not contain the harness's expected literal extractMentionedJids, not because a test failed. The public placeholder has not yet published the completed artifact, so this cites the downloaded immutable artifact rather than claiming the placeholder is final.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 127958 passed at 2026-08-22T14:49:23Z in hosted_exact_or_recent_parent mode, reusing exact-head CI run 32579329995; no separate Testbox lease/run was needed. Remote PR head/tree matched the prepared head/tree.
  • No live WhatsApp account was available. For this behavior-neutral owner-local projection refactor, dependency-source inspection, adversarial wrapper/media/error differential coverage, focused tests, the full extension suite, and exact-head CI provide deterministic coverage of the changed boundary.

All available landing gates are green; no review action remains.

@steipete
steipete merged commit 963fafb into main Aug 22, 2026
161 checks passed
@steipete
steipete deleted the codex/perf-whatsapp-inbound-projection branch August 22, 2026 14:51

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 10:43 AM ET / 14:43 UTC.

ClawSweeper review

What this changes

This PR builds one normalized WhatsApp inbound-message projection during enrichment and reuses it for text, media, reply, location, contact, and mention extraction.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness finding. The PR centralizes repeated inbound-message normalization inside the WhatsApp owner and preserves the raw-message fallback for standalone media callers; it remains open because it is maintainer-authored and carries the protected maintainer label.

Priority: P3
Reviewed head: fcc5e6ced962e086c4a7fd07d5205a1104f10e75

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a coherent owner-local refactor with no concrete regression found in the reviewed path.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor real-behavior-proof gate; its PR body provides focused deterministic validation claims.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor real-behavior-proof gate; its PR body provides focused deterministic validation claims.
Evidence reviewed 6 items Projection owner and delivery consumer: Enrichment creates one projection, passes it to all extraction paths, reuses entry zero for direct-media classification, and returns mentions; delivery consumes that returned fact rather than normalizing again.
Standalone media fallback remains: The optional normalized message changes only the enrichment caller; all other media callers still normalize their raw message locally.
Existing behavior coverage: Current tests cover direct and quoted-message mention boundaries plus media download and quoted-media authorship; the patch does not add implementation-coupled call-count tests.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/whatsapp/src/inbound/extract.test.ts extensions/whatsapp/src/inbound/media.node.test.ts

Result: FAIL (partial) — step 2 expect_output extractMentionedJids: expected terminal output was not visible within 30 seconds: "extractMentionedJids"

node scripts/run-vitest.mjs extensions/whatsapp/src/inbound/extract.test.ts extensions/whatsapp/src/inbound/media.node.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127958-PJXPga/target$ node scripts/run-vitest.mjs extensions/whatsapp/src/inbound/extract.test.ts extensions/wh
atsapp/src/inbound/media.node.test.ts
node scripts/run-vitest.mjs extensions/whatsapp/src/inbound/extract.test.ts extensions/whatsapp/src/inbound/media.node.test.ts
[test] starting test/vitest/vitest.extension-whatsapp.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127958-PJXPga/target

 ✓  extension-whatsapp  extensions/whatsapp/src/inbound/media.node.test.ts (15 tests) 18876ms
 ✓  extension-whatsapp  extensions/whatsapp/src/inbound/extract.test.ts (69 tests) 24ms

 Test Files  2 passed (2)
      Tests  84 passed (84)
   Start at  14:44:33
   Duration  19.96s (transform 32.43s, setup 1.55s, import 18.92s, tests 18.90s, environment 0ms)

[test] passed 1 Vitest shard in 23.78s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127958-PJXPga/target$ node scripts/run-vitest.mjs extensions/whatsapp/src/inbound/extract.test.ts extensions/wh
atsapp/src/inbound/media.node.test.ts
[test] starting test/vitest/vitest.extension-whatsapp.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127958-PJXPga/target





























Assertions:

  • FAIL expect_output: extractMentionedJids

How this fits together

The WhatsApp plugin receives a Baileys message, authorizes it, enriches it into delivery facts, and then queues it for OpenClaw’s channel flow. This change shares one local normalized projection between enrichment and the delivery metadata it produces.

flowchart LR
  A[Inbound WhatsApp message] --> B[Admission and authorization]
  B --> C[Normalized message projection]
  C --> D[Enrichment]
  D --> E[Media reply and mention facts]
  E --> F[Queued channel delivery]
Loading

Before merge

  • Resolve merge risk (P1) - This read-only checkout has no installed Baileys source and GitHub/network access was unavailable, so the normalization contract was not independently executed here; exact-head validation should complete before landing.
  • Complete next step (P2) - No repair work is queued: no concrete patch defect was found, and this maintainer-labelled PR should complete ordinary exact-head review.
Agent review details

Security

None.

PR surface

Source +32, Other 0. Total +32 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 83 51 +32
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 2 0
Total 5 85 53 +32

Review metrics

Metric Value Why it matters
Production versus test LOC production +83/-51 (net +32); tests 0; assertion baseline +2/-2 The added owner-local projection replaces repeated normalization work; no public config, API, or persisted-data surface changes.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the projection private to the WhatsApp plugin, retain the standalone raw-message fallback, and land only after exact-head validation confirms wrapper, media, and mention equivalence.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the projection private to the WhatsApp plugin, retain the standalone raw-message fallback, and land only after exact-head validation confirms wrapper, media, and mention equivalence.

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

Not applicable: this PR optimizes an existing owner-local path rather than reporting a user-facing defect; source comparison confirms the repeated projection work on current main.

Is this the best way to solve the issue?

Yes. A private projection at the WhatsApp enrichment owner removes duplicate work while preserving the existing raw-message fallback; moving it into core or the public SDK would add unjustified surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 71b5de406111.

Labels

Label changes:

  • add P3: This is a scoped internal performance refactor with no claimed user-visible behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P3: This is a scoped internal performance refactor with no claimed user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the recent extraction consolidation and related interactive-mention/media repairs that define this owner boundary. (role: recent WhatsApp extraction contributor; confidence: high; commits: e7f1202bbb39, e922b53675d0; files: extensions/whatsapp/src/inbound/extract.ts, extensions/whatsapp/src/inbound/message-enrichment.ts, extensions/whatsapp/src/inbound/message-delivery.ts)
  • lurebat: Earlier history attributes the quoted-message mention boundary to this contributor, which remains relevant to the moved mention computation. (role: mention-semantics contributor; confidence: medium; commits: 5d91b68af355; files: extensions/whatsapp/src/inbound/extract.ts)

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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants