Skip to content

fix(whatsapp): resolve abortPromise when stop signal already fired - #109903

Merged
steipete merged 4 commits into
openclaw:mainfrom
ZengWen-DT:fix/whatsapp-abort-inflight-startup
Jul 18, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
ZengWen-DT:fix/whatsapp-abort-inflight-startup

Conversation

@ZengWen-DT

@ZengWen-DT ZengWen-DT commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where stopping a WhatsApp account during or immediately after connection startup would leave WhatsAppConnectionController.waitForClose() pending forever when the gateway stop AbortSignal was already aborted. Channel shutdown then waits on that race and never completes.

Why This Change Was Made

The controller built abortPromise with an abort listener but, when the signal was already aborted at construction time, only called stopDisconnectRetries() and never settled abortPromise. waitForClose() races on that promise, so a pre-aborted stop signal could hang indefinitely. The fix resolves abortPromise immediately when abortSignal.aborted is already true, matching the existing pre-aborted handling for disconnect retries. Risk note: proof uses the exported controller with a synthetic open connection; live WhatsApp/Baileys sessions were not used.

User Impact

WhatsApp channel stop/restart no longer hangs when shutdown is requested with an already-aborted stop signal (for example during fast gateway restarts or overlapping account lifecycle transitions).

Evidence

Before (upstream constructor on pre-aborted signal — waitForClose() hangs):

$ git stash push -m proof-before -- extensions/whatsapp/src/connection-controller.ts
$ WA_LABEL=before-fix node --import tsx /tmp/whatsapp-abort-proof.mjs
Worktree: /srv/projects/openclaw-wt-whatsapp-abort-startup
{
  "label": "before-fix",
  "elapsedMs": 501,
  "resolved": false,
  "value": "timeout"
}
$ echo $?
1

After (same harness with fix applied — resolves immediately):

$ WA_LABEL=after-fix node --import tsx /tmp/whatsapp-abort-proof.mjs
Worktree: /srv/projects/openclaw-wt-whatsapp-abort-startup
{
  "label": "after-fix",
  "elapsedMs": 0,
  "resolved": true,
  "value": "aborted"
}
$ echo $?
0

The harness drives the exported WhatsAppConnectionController with a pre-aborted AbortController, injects an open connection whose close promise never settles, and races waitForClose() against a 500ms timeout.

Focused tests:

$ node scripts/run-vitest.mjs run extensions/whatsapp/src/connection-controller.test.ts
 Test Files  1 passed (1)
      Tests  30 passed (30)

What was not tested: Live WhatsApp WebSocket/Baileys session with production credentials; local harness proves the pre-aborted abortPromise settlement bug and fix on the real exported class.

AI-assisted: Cursor Composer — proof runs executed manually on this machine.

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: XS labels Jul 17, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 8:59 PM ET / July 18, 2026, 00:59 UTC.

Summary
The PR unifies WhatsApp abort handling so an already-aborted gateway stop signal settles the controller close race, cancels in-flight setup, and adds a regression test.

PR surface: Source -5, Tests +49. Total +44 across 2 files.

Reproducibility: yes. at controller level: constructing the controller with an already-aborted signal leaves the old listener-only abort promise unsettled, and the added regression test directly exercises the repaired path. A live WhatsApp/Baileys reproduction has not been supplied.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Capture a redacted real WhatsApp/Baileys startup-stop or rapid-restart run on the current head showing shutdown completes.
  • Update the PR body with that evidence; if a fresh review does not trigger, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR provides terminal before/after output and focused tests using a synthetic connection, but no redacted real WhatsApp/Baileys startup-stop or restart evidence; add that behavior proof before merge and redact private endpoints, account identifiers, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging without a real WhatsApp/Baileys startup-stop or rapid-restart run leaves the user-facing shutdown behavior unverified outside the synthetic controller harness.

Maintainer options:

  1. Decide the mitigation before merge
    Add redacted after-fix evidence from a real WhatsApp/Baileys startup-stop or rapid-restart flow that shows the affected account reaches shutdown rather than hanging, then refresh review on the exact head.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] The remaining blocker is contributor-supplied real channel behavior evidence, not a mechanical repair that ClawSweeper can safely perform.

Security
Cleared: The two-file TypeScript change only adjusts existing abort and test control flow; no dependency, permission, secret, artifact, or supply-chain surface is introduced.

Review details

Best possible solution:

Add redacted after-fix evidence from a real WhatsApp/Baileys startup-stop or rapid-restart flow that shows the affected account reaches shutdown rather than hanging, then refresh review on the exact head.

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

Yes at controller level: constructing the controller with an already-aborted signal leaves the old listener-only abort promise unsettled, and the added regression test directly exercises the repaired path. A live WhatsApp/Baileys reproduction has not been supplied.

Is this the best way to solve the issue?

Yes, conditionally: using one abort callback for both signal states is the narrowest way to preserve identical cleanup and cancellation semantics. The remaining question is real channel behavior proof, not a different code design.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6f0f6af62e41.

Label changes

Label justifications:

  • P1: The reported race can leave a real WhatsApp account shutdown or restart waiting indefinitely during gateway lifecycle transitions.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides terminal before/after output and focused tests using a synthetic connection, but no redacted real WhatsApp/Baileys startup-stop or restart evidence; add that behavior proof before merge and redact private endpoints, account identifiers, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source -5, Tests +49. Total +44 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 19 -5
Tests 1 49 0 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 63 19 +44

What I checked:

  • Pre-aborted abort handling: The proposed constructor routes both already-aborted and future abort signals through one stop callback that resolves abortPromise, stops reconnect retries, and aborts owner/setup acquisition. (extensions/whatsapp/src/connection-controller.ts:514, 081ae6cd1829)
  • Regression coverage: The added test constructs the exported controller with a pre-aborted signal, verifies abortPromise settles, verifies openConnection rejects during shutdown, and verifies setup acquisition receives the aborted signal without creating a socket. (extensions/whatsapp/src/connection-controller.test.ts:1056, 081ae6cd1829)
  • Prior review blocker addressed: The latest branch commit is titled "fix(whatsapp): unify connection abort handling" and follows the earlier review cycle that required restoring pre-aborted setup cancellation; the new regression test covers that cancellation path. (extensions/whatsapp/src/connection-controller.ts:514, 081ae6cd1829)
  • Proof remains synthetic: The PR body explicitly says its before/after harness injects a synthetic connection and that no live WhatsApp WebSocket/Baileys session was exercised; focused unit tests are supplemental rather than real behavior proof. (081ae6cd1829)

Likely related people:

  • steipete: Authored the current PR-head integration commit that unified the controller abort path after the earlier cancellation concern. (role: recent area contributor; confidence: high; commits: 081ae6cd1829; files: extensions/whatsapp/src/connection-controller.ts, extensions/whatsapp/src/connection-controller.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (7 earlier review cycles)
  • reviewed 2026-07-17T10:04:42.157Z sha 2d0cdb77e96cdafe15dfaa33bd5c097d065064cb :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T12:30:29.292Z sha 1804c8bafa47a4ad9499037b65fdfc47f810d3d4 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T14:27:13.668Z sha bc20dbf4cf086f40f7bd22ffc2e57dba32e3b549 :: needs changes before merge. :: [P1] Restore pre-aborted setup cancellation
  • reviewed 2026-07-17T15:16:45.706Z sha afed980a0157ed38e8ab11a6d652ebde698286fc :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T15:57:55.635Z sha afed980a0157ed38e8ab11a6d652ebde698286fc :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T00:23:32.350Z sha 5c8159bc2ac30962ec04841aeaac5d8921e59ca1 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T00:50:02.854Z sha a6c281e0540b07fec2bc38a489419c019428fd68 :: needs real behavior proof before merge. :: none

@ZengWen-DT
ZengWen-DT force-pushed the fix/whatsapp-abort-inflight-startup branch from 2d0cdb7 to 1804c8b Compare July 17, 2026 12:24
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 17, 2026
@ZengWen-DT

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 17, 2026
@steipete
steipete force-pushed the fix/whatsapp-abort-inflight-startup branch 2 times, most recently from ee02e5a to 5c8159b Compare July 18, 2026 00:21
@clawsweeper clawsweeper Bot removed the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Jul 18, 2026
@clawsweeper clawsweeper Bot added the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Jul 18, 2026
@steipete
steipete force-pushed the fix/whatsapp-abort-inflight-startup branch from 5c8159b to a6c281e Compare July 18, 2026 00:47
ZengWen-DT and others added 4 commits July 18, 2026 01:56
waitForClose() races on abortPromise, but a pre-aborted gateway stop
signal never settled that promise because the abort listener was skipped.
Resolve abortPromise immediately when abortSignal.aborted is already true.

Co-authored-by: Cursor <[email protected]>
…tPromise fix

- Extract params.abortSignal to local const so tsgo can narrow the type
  through else-if control flow, fixing TS18048: possibly undefined
- Remove setupAbortController/ownerAcquireAbortController.abort() from
  the constructor's pre-aborted branch so openConnection() still works
  when the stop signal was already fired at construction time
- Use createSocketWithTransportEmitter() mock in the new test so
  shutdown() cleanup has sock.end() and ws.removeListener() available
@steipete
steipete force-pushed the fix/whatsapp-abort-inflight-startup branch from a6c281e to 081ae6c Compare July 18, 2026 00:57
@steipete
steipete merged commit bcc44ba into openclaw:main Jul 18, 2026
103 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…penclaw#109903)

* fix(whatsapp): resolve abortPromise when stop signal already fired

waitForClose() races on abortPromise, but a pre-aborted gateway stop
signal never settled that promise because the abort listener was skipped.
Resolve abortPromise immediately when abortSignal.aborted is already true.

Co-authored-by: Cursor <[email protected]>

* fix(whatsapp): resolve tsgo TS18048 and test mock in pre-aborted abortPromise fix

- Extract params.abortSignal to local const so tsgo can narrow the type
  through else-if control flow, fixing TS18048: possibly undefined
- Remove setupAbortController/ownerAcquireAbortController.abort() from
  the constructor's pre-aborted branch so openConnection() still works
  when the stop signal was already fired at construction time
- Use createSocketWithTransportEmitter() mock in the new test so
  shutdown() cleanup has sock.end() and ws.removeListener() available

* fix(whatsapp): preserve pre-aborted setup cancellation

* fix(whatsapp): unify connection abort handling

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
LZY3538 added a commit to LZY3538/openclaw that referenced this pull request Jul 18, 2026
When the gateway stop AbortSignal is already aborted at construction
time, the addEventListener('abort', onAbort) listener never fires per
the AbortSignal spec. This leaves waitForExit pending forever, hanging
channel shutdown. The fix resolves onAbort immediately when
abortSignal.aborted is already true, matching the pre-aborted handling
pattern in WhatsApp connection-controller (openclaw#109903) and QQBot
gateway-connection (openclaw#109896).

Co-Authored-By: Claude <[email protected]>
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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants