Skip to content

fix(whatsapp): replay approval reactions after transient Gateway failures - #130969

Closed
wangmiao0668000666 wants to merge 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/whatsapp-approval-reaction-replay
Closed

wangmiao0668000666 wants to merge 2 commits into
openclaw:mainfrom
wangmiao0668000666:fix/whatsapp-approval-reaction-replay

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A transient Gateway 5xx/network/auth error during a WhatsApp approval reaction silently dropped the operator's approval click. maybeResolveWhatsAppApprovalReaction swallowed the error with return true (extensions/whatsapp/src/approval-reactions.ts:545), and the upsert consumer (extensions/whatsapp/src/inbound/message-delivery.ts) skipped the message before durable admission — so the reaction never reached the durable ingress queue, no retry owner ever saw it, and the click was lost with only a verbose log.

This is the WhatsApp instance of the invariant already fixed for matrix (#129879), signal (#130134), and iMessage (#130893); the signal repair intentionally left WhatsApp separate because its approval check runs pre-ingress.

Fixes #131004.

Why This Change Was Made

A naive one-line throw would be worse here: the approval check runs in the messages.upsert loop before durable admission, so an escaping throw would abort the loop and drop sibling messages in the same batch. The repair therefore routes the failure into the existing durable ingress as the retry owner:

  1. approval-reactions.ts — non-NotFound resolver errors now throw (NotFound stays terminal: binding cleared, reaction consumed).
  2. message-delivery.ts upsert fast path — catches the transient throw, logs it, and falls through to normal durable admission instead of continue, keeping the batch loop alive.
  3. message-delivery.ts processDurableInboundMessage — resolves approval reactions inside the durable dispatch (before normalization, since reaction payloads do not normalize into ordinary inbound messages). A transient failure there propagates to the real drain, which releases the claim and replays the reaction under the queue's retry policy.

User Impact

WhatsApp approval reactions now survive transient Gateway failures: the operator's 👍 is replayed once the Gateway recovers instead of vanishing. Sibling messages in the same upsert batch are unaffected.

Evidence

  • Qualified mock-gateway harness (verdict below): a REAL ephemeral gateway process (dist build of this branch, whatsapp plugin loaded, isolated state dir, real approval store / reviewer custody / record visibility) + the REAL message-delivery coordinator + REAL SQLite durable ingress queue; only the Baileys socket/session (the channel transport boundary) is mocked. A real pending exec approval is requested on the gateway with a whatsapp turn-source; the reaction's first resolution attempts target a dead local port (ECONNREFUSED, transient), then the config flips to the live port and the durable drain replays and resolves the approval on the gateway. Transcript:

    [proof] exec approval requested on real gateway: id=whatsapp-replay-proof-1787857153862
    [proof] reaction upsert emitted while the coordinator config points at a dead port
    whatsapp: approval reaction failed id=... sender=+15551230000: Error: connect ECONNREFUSED 127.0.0.1:1  (x3)
    [proof] durable rows after transient failure: pending=1 claims=0
    [proof] coordinator config flipped to the live gateway port; waiting for durable replay
    [proof] approval decision after replay: {"id":"...","decision":"allow-once","createdAtMs":...,"expiresAtMs":...}
    [proof] chat deliveries observed: []
    whatsapp: approval reaction applied id=... sender=+15551230000 status=allowed decision=allow-once
    VERDICT {"transientFailureInjected":true,"replayResolvedApproval":true,"reactionReachedChatLane":false}
    

    Verdict JSON: {"approvalId":"whatsapp-replay-proof-1787857153862","transientFailureInjected":true,"replayResolvedApproval":true,"decisionResult":{"decision":"allow-once"},"reactionReachedChatLane":false} — the transient failure never tombstones the reaction, the released claim is redelivered, the approval is decided allow-once on the real gateway, and nothing leaks into the chat lane.

  • New extensions/whatsapp/src/monitor-inbox.approval-reaction-replay.test.ts: real inbox monitor, real SQLite ingress queue, real drain, real approval-reaction resolution — only the socket and the Gateway approval-resolution call are mocked. Proves: the transient failure falls through to durable admission, the drain redelivers with an identical resolution request (approvalId/approvalKind/decision/channel), the replayed attempt resolves, the reaction never leaks into the chat pipeline, a sibling message in the same upsert batch is still delivered, and the completion tombstone blocks any third dispatch.

  • Regression proof: the replay test fails against pre-fix code (single swallowed call, no redelivery) and passes with the fix; the rewritten unit test (propagates transient Gateway errors for durable ingress replay) also fails pre-fix.

  • node scripts/run-vitest.mjs extensions/whatsapp/src/monitor-inbox extensions/whatsapp/src/approval-reactions.test.ts extensions/whatsapp/src/question-reactions.test.ts extensions/whatsapp/src/inbound.test.ts extensions/whatsapp/src/inbound — 359 passed.

  • pnpm tsgo:extensions and pnpm tsgo:test:extensions green; oxfmt --check clean on all touched files.

Changelog context

Behavior fix: WhatsApp approval reactions now survive transient Gateway failures instead of silently dropping the operator's click.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added the channel: whatsapp-web Channel integration: whatsapp-web label Aug 27, 2026
@wangmiao0668000666
wangmiao0668000666 marked this pull request as ready for review August 27, 2026 14:27
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 1:07 AM ET / 05:07 UTC.

ClawSweeper review

What this changes

The PR makes WhatsApp approval reactions retry through the existing durable inbound queue after Gateway failures, while preserving delivery of other messages in the batch.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix: current main and the latest release still lose approval reactions on Gateway failure. No blocking findings remain, and the supplied real-Gateway recovery trace satisfies the proof gate.

Priority: P1
Reviewed head: 88654d70c97160a67d1224526220badd90f790b7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with sufficient real-Gateway recovery evidence and no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The pinned-head transcript exercises the real WhatsApp coordinator, SQLite drain, and Gateway client against an ephemeral Gateway: connection failures release the claim, restored connectivity resolves allow-once, and no reaction enters chat. The mocked Baileys input is permitted by the repository’s harness policy.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The pinned-head transcript exercises the real WhatsApp coordinator, SQLite drain, and Gateway client against an ephemeral Gateway: connection failures release the claim, restored connectivity resolves allow-once, and no reaction enters chat. The mocked Baileys input is permitted by the repository’s harness policy.
Evidence reviewed 12 items Pinned scope: The verified merge-base-to-head delta changes only WhatsApp approval handling, its delivery coordinator, and two tests. Base-only Codex and other changes are excluded from this review.
Current main still loses the reaction: The resolver logs non-NotFound errors and returns true at line 545. The current-main upsert caller then continues before durable admission, leaving no retry owner.
Latest release remains affected: The v2026.9.1 resolver retains the same error-swallowing return; its blob matches current main. The requested repair is not present in that release.
Findings None None.
Security None None.

How this fits together

WhatsApp’s inbound coordinator receives chat messages and approval reactions. Approval reactions reach the Gateway’s approval service; the durable inbound queue owns retries and completion tracking.

flowchart TD
  A[WhatsApp incoming batch] --> B{Approval reaction}
  B -->|Yes| C[Check sender and resolve approval]
  C -->|Terminal result| D[Consume reaction]
  C -->|Gateway failure| E[Durable inbound queue]
  E --> F[Retry with current authorization]
  F --> C
  B -->|Ordinary message| G[Chat delivery]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +34, Tests +164. Total +198 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 39 5 +34
Tests 2 164 0 +164
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 203 5 +198

Review metrics

Metric Value Why it matters
Production versus test LOC Production +39/-5 (net +34); tests +164/-0 Production growth connects the existing immediate path to durable replay while preserving batch intake; a net-neutral move would remove immediate handling.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #131004
Summary: This PR is the implementation candidate for the open WhatsApp report; the merged sibling repairs affect different channel owners.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Preserve immediate approval handling and terminal cleanup while assigning failed attempts to the existing durable retry owner; a bare rethrow would abort batch intake.

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

Yes, from source: fail Gateway resolution for a registered approval reaction, and current main consumes it before durable admission. The contributor supplies before/after evidence; this review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. The repair belongs at WhatsApp’s admission boundary and reuses the existing resolver and retry machinery without changing approval policy or storage format.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 20d0daa063c0.

Labels

Label justifications:

  • P1: An approval reaction during a Gateway outage is silently lost in current main and the latest release, leaving the operator’s request unresolved.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The pinned-head transcript exercises the real WhatsApp coordinator, SQLite drain, and Gateway client against an ephemeral Gateway: connection failures release the claim, restored connectivity resolves allow-once, and no reaction enters chat. The mocked Baileys input is permitted by the repository’s harness policy.
  • proof: sufficient: Contributor real behavior proof is sufficient. The pinned-head transcript exercises the real WhatsApp coordinator, SQLite drain, and Gateway client against an ephemeral Gateway: connection failures release the claim, restored connectivity resolves allow-once, and no reaction enters chat. The mocked Baileys input is permitted by the repository’s harness policy.

Evidence

What I checked:

  • Pinned scope: The verified merge-base-to-head delta changes only WhatsApp approval handling, its delivery coordinator, and two tests. Base-only Codex and other changes are excluded from this review. (88654d70c971)
  • Current main still loses the reaction: The resolver logs non-NotFound errors and returns true at line 545. The current-main upsert caller then continues before durable admission, leaving no retry owner. (extensions/whatsapp/src/approval-reactions.ts:545, 20d0daa063c0)
  • Latest release remains affected: The v2026.9.1 resolver retains the same error-swallowing return; its blob matches current main. The requested repair is not present in that release. (extensions/whatsapp/src/approval-reactions.ts:545, ad6fe23aecb9)
  • Admission and replay owner: The socket monitor constructs this coordinator. Intake catches failed approval resolution and admits the event; durable dispatch resolves reactions before ordinary normalization, which otherwise discards reaction-only payloads. (extensions/whatsapp/src/inbound/message-delivery.ts:429, 88654d70c971)
  • Existing retry contract: WhatsApp delegates to the shared ingress monitor. Its drain releases failed claims through the existing backoff policy and writes completion tombstones after terminal delivery; this PR adds no queue schema or retry policy. (src/channels/message/ingress-drain.ts:358, 88654d70c971)
  • Authorization and terminal-state checks: Each replay reruns the existing WhatsApp approver check. Gateway resolution independently uses current configuration, validates reviewer custody against the live approval, and preserves terminal outcomes before applying a new decision. (src/gateway/server-methods/approval.ts:426, 88654d70c971)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-27T14:36:43.920Z sha 2deb376 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T16:34:02.766Z sha 88654d7 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T17:00:08.439Z sha 88654d7 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T19:06:53.632Z sha 88654d7 :: needs maintainer review before merge. :: none

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Head 88654d70c97 fixes the CI lint failure (no-promise-executor-return in the replay test) and shrinks the mock surface: the replay proof now uses the real isApprovalNotFoundError classifier instead of a mock — the injected gateway 503 Error genuinely is not a not-found, so the production classification itself drives the transient path. Verified: replay test passes, node scripts/run-oxlint.mjs on the touched file reports 0 errors.

On the proof shape: the remaining mocks are exactly the two external boundaries — the Baileys socket (the channel's transport input, analogous to the synthetic ingress rows in the accepted iMessage harness #130893) and the Gateway approval-resolution call (the fault-injection boundary, identical to signal #130134 / matrix #129879, which merged with this same harness shape). Everything in between is real production code: monitorWebInbox, upsert loop, durable admission, SQLite ingress queue, drain, and approval-reaction resolution. A real-WhatsApp run is not possible from this environment (the live QA lane needs the two dedicated WhatsApp Web accounts via Convex leases); if a maintainer can dispatch qa-live-transports-convex.yml with whatsapp_scenario=whatsapp-approval-exec-reaction-native against this head, that adds the live-path regression on top.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The review started at 16:29 UTC yesterday never completed (no update to the review comment). Requesting a fresh review of head 88654d70c97.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 27, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Real behavior proof added (transcript and verdict JSON now in the PR body): a real ephemeral gateway process (dist build of this head, whatsapp plugin loaded, isolated state dir — real approval store, reviewer custody, and record visibility) plus the real message-delivery coordinator and real SQLite durable ingress queue; only the Baileys socket/session is mocked, per the harness contract. A real pending exec approval is created on the gateway with a whatsapp turn-source; the reaction's first resolution attempts hit a dead local port (ECONNREFUSED), the durable drain releases the claim (pending=1 claims=0), and after the config flips to the live port the replay resolves the approval on the gateway (decision: "allow-once"). The reaction never reaches the chat lane.

This complements the committed SQLite replay regression (which ClawSweeper live-ran PASS earlier): that test covers fault/release/replay/completion/dedup inside the process; this run proves the same flow against a real gateway approval backend end to end.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 27, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Sep 5, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Closing as superseded: current main already implements both behavioral changes this PR carries.

They landed in #140645 (refactor(channels): share approval reaction settlement), merged 2026-09-07, which closed the canonical #131004 as completed and lists this PR as related. Verified against main 8fca3db5:

  • extensions/whatsapp/src/inbound/message-delivery.ts resolves approval reactions before normalization and, when resolution fails, logs whatsapp approval reaction resolution failed; admitting reaction for durable replay and admits the reaction for durable replay — the same admission fallback and the same warning string this PR adds.
  • extensions/whatsapp/src/approval-reactions.ts awaits settleApprovalReaction with no swallowing catch, so transient Gateway errors propagate to the durable drain instead of being absorbed — the throw error behavior this PR adds.
  • The regression coverage moved with the refactor: extensions/whatsapp/src/approval-reactions.test.ts:429 retains the target and propagates transient failures for durable replay. This PR's monitor-inbox.approval-reaction-replay.test.ts no longer exists on main.

The branch is dirty against those same files, so a rebase has no residual behavior to preserve. The status: 👀 ready for maintainer look verdict here was recorded at reviewed_at=2026-09-05, two days before #140645 merged, so it predates the supersession and does not contradict this.

If a WhatsApp-specific gap does remain after #140645 — for example a transport path the shared settlement does not own — it needs a fresh PR with a reproduction against current main rather than a rebase of this branch.

@wangmiao0668000666
wangmiao0668000666 deleted the fix/whatsapp-approval-reaction-replay branch October 28, 2026 07:42
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: WhatsApp approval reactions are silently dropped on transient Gateway failures

1 participant