Repository navigation
fix(whatsapp): replay approval reactions after transient Gateway failures - #130969
wangmiao0668000666 wants to merge 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 1:07 AM ET / 05:07 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherWhatsApp’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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +34, Tests +164. Total +198 across 4 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
…er in replay proof
|
@clawsweeper re-review Head 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: |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@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 |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@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 ( 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. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Closing as superseded: current main already implements both behavioral changes this PR carries. They landed in #140645 (
The branch is dirty against those same files, so a rebase has no residual behavior to preserve. The 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. |
What Problem This Solves
A transient Gateway 5xx/network/auth error during a WhatsApp approval reaction silently dropped the operator's approval click.
maybeResolveWhatsAppApprovalReactionswallowed the error withreturn 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
throwwould be worse here: the approval check runs in themessages.upsertloop 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:approval-reactions.ts— non-NotFound resolver errors nowthrow(NotFound stays terminal: binding cleared, reaction consumed).message-delivery.tsupsert fast path — catches the transient throw, logs it, and falls through to normal durable admission instead ofcontinue, keeping the batch loop alive.message-delivery.tsprocessDurableInboundMessage— 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: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 decidedallow-onceon 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:extensionsandpnpm tsgo:test:extensionsgreen;oxfmt --checkclean on all touched files.Changelog context
Behavior fix: WhatsApp approval reactions now survive transient Gateway failures instead of silently dropping the operator's click.