Skip to content

fix(zalouser): recover when listener handshakes stall - #109506

Merged
fuller-stack-dev merged 7 commits into
openclaw:mainfrom
lsr911:fix/zalouser-ws-handshake-timeout
Sep 17, 2026
Merged

fuller-stack-dev merged 7 commits into
openclaw:mainfrom
lsr911:fix/zalouser-ws-handshake-timeout

Conversation

@lsr911

@lsr911 lsr911 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: Zalo user-account monitoring can remain silently stuck when a WebSocket handshake never finishes.

User Impact

A stalled handshake now reports a timeout after 30 seconds and releases listener ownership so the channel can retry. Successful connections cancel the deadline; stop and abort clean up without a late unhandled socket error. No configuration or migration is required.

Why This Change Was Made

Listener ownership, handlers, and timers must exist before startup can emit an event or throw. Cleanup retires the stopped API so a retry cannot reuse a listener whose old socket is still closing.

This builds on @lsr911's original timeout fix and preserves the contributor branch ancestry. Unrelated Matrix changes were removed.

Also reuses the existing canonical native-wrapper/source-preparation input inventory fixes needed by CI. Current-main integration includes the landed bounded-read hook and Slack callback/import-cycle repairs; this PR has no remaining Slack or Matrix delta.

Evidence

  • Regression tests reproduced synchronous-connect timeout, startup exception, and stale-listener retry failures before repair.
  • Five startup lifecycle cases pass, covering connected, throw, abort, error, and rejected message handlers.
  • Real pinned [email protected] and ws transport proof passed with a real 30-second deadline: stalled loopback WebSocket upgrade → timeout → real monitor rejection and durable-ingress drain → same-profile monitor restart using a fresh listener → successful WebSocket connection → clean abort settlement.
  • Two existing monitor tests, eight quote-metadata tests, and the packaged-loader test pass.
  • Fresh independent P0–P2 review found no actionable defects.
  • Fresh combined review is clean through P2; native cold-provisioning smoke tests pass. The fixture passes syntax lint with zero warnings or errors.

The transport proof stubs only account restoration. It does not claim authenticated Zalo login or a full live-Gateway automatic retry run.

Real transport trace
transport:upgrade:1
Zalo listener error: Error: Zalo listener websocket handshake timed out
monitor:rejected
transport:upgrade:2
transport:connected
monitor:retry-started
monitor:abort-settled
node scripts/run-vitest.mjs extensions/zalouser/src/zalo-js.listener.test.ts

lsr911 and others added 2 commits July 17, 2026 09:18
The warnedEncryptedRooms and warnedCryptoMissingRooms Sets had no
capacity limit. Each distinct roomId that produced an encrypted event
would be added permanently, allowing unbounded growth over the gateway
lifetime.

- Cap warnedEncryptedRooms at 256 entries.
- Cap warnedCryptoMissingRooms at 256 entries.
- Skip add when the cap is reached so the dedupe Sets never grow
  without bound.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: 廖石荣 0668000909 <[email protected]>
The zca-js listener WebSocket had no connect deadline, so an
unreachable Zalo server would leave the listener silently stuck
without firing connected, error, or closed events.

- Add LISTENER_HANDSHAKE_TIMEOUT_MS (30s).
- Listen for the connected event to clear the handshake timer.
- Fail the listener with a descriptive error on timeout so the
  reconnect loop retries.
- Clean up the timer and connected listener on stop/abort.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: 廖石荣 0668000909 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added channel: matrix Channel integration: matrix channel: zalouser Channel integration: zalouser size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 17, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 10:16 PM ET / September 17, 2026, 02:16 UTC (Revision 5).

ClawSweeper review

What this changes

The PR adds a 30-second connection deadline and safe listener cleanup to Zalo Personal, with lifecycle regression coverage and supporting test and wrapper inventory corrections.

Merge readiness

✅ Ready for maintainer review

This remains a useful, bounded repair: current main and v2026.9.4 lack the handshake deadline. Earlier findings are resolved, the recorded real-transport recovery proof is sufficient, and no blocking defect was found.

Priority: P1
Reviewed head: 2c81fa85f7ac590c22ce2a38b52c328ea9dded37

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with convincing transport-boundary proof, resolved prior findings, and no remaining blocking correctness concern.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The captured terminal trace and inspected fixture exercise the production Zalo listener and monitor with real zca-js/ws transport: stalled upgrade, 30-second timeout, monitor rejection, fresh same-profile connection, and clean abort settlement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured terminal trace and inspected fixture exercise the production Zalo listener and monitor with real zca-js/ws transport: stalled upgrade, 30-second timeout, monitor rejection, fresh same-profile connection, and clean abort settlement.
Evidence reviewed 10 items Current main still lacks the repair: The pinned main implementation starts the listener without a connection deadline. Its watchdog detects event-loop scheduling gaps, so regular watchdog ticks do not detect a stalled WebSocket handshake.
Latest release comparison: Read the listener implementation from the supplied v2026.9.4 release commit through raw GitHub after the local release object was unavailable; it also lacks the handshake deadline.
Lifecycle ownership and failure propagation: Timers, event handlers, and profile ownership are established before listener.start. Cleanup cancels timers, detaches message handling, releases ownership, and retires the cached API while retaining guarded terminal handlers until closure. The existing monitor awaits ingress shutdown before rejecting.
Findings None None.
Security None None.

How this fits together

Zalo Personal receives account messages through the zca-js WebSocket client and passes them into OpenClaw’s channel monitor and durable ingress queue. Listener failures settle the monitor so the Gateway’s existing restart supervisor can retry.

flowchart TD
  A[Saved Zalo session] --> B[Zalo Personal listener]
  B --> C{WebSocket connects within deadline?}
  C -->|Yes| D[Receive messages into durable ingress]
  C -->|No| E[Stop socket and retire cached client]
  E --> F[Monitor reports failure]
  F --> G[Gateway restart supervisor]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -18, Tests +255, Other +3. Total +240 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 49 67 -18
Tests 3 255 0 +255
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 3 0 +3
Total 6 307 67 +240

Review metrics

None.

Technical review

Best possible solution:

Keep connection recovery in the Zalo listener owner and reuse the monitor’s existing settlement and Gateway restart paths.

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

Yes, from source: accepting TCP while withholding the WebSocket upgrade leaves main’s listener without a connection deadline. The submitted fixture exercises that trigger; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The patch repairs the existing listener lifecycle, matches the pinned dependency’s events, and avoids adding a competing retry mechanism or configuration surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ead7324bdb36.

Labels

Label justifications:

  • P1: An indefinitely stalled handshake can silently disable the Zalo Personal channel’s inbound workflow.
  • 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 captured terminal trace and inspected fixture exercise the production Zalo listener and monitor with real zca-js/ws transport: stalled upgrade, 30-second timeout, monitor rejection, fresh same-profile connection, and clean abort settlement.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured terminal trace and inspected fixture exercise the production Zalo listener and monitor with real zca-js/ws transport: stalled upgrade, 30-second timeout, monitor rejection, fresh same-profile connection, and clean abort settlement.

Evidence

What I checked:

  • Current main still lacks the repair: The pinned main implementation starts the listener without a connection deadline. Its watchdog detects event-loop scheduling gaps, so regular watchdog ticks do not detect a stalled WebSocket handshake. (extensions/zalouser/src/zalo-js.ts:1727, ead7324bdb36)
  • Latest release comparison: Read the listener implementation from the supplied v2026.9.4 release commit through raw GitHub after the local release object was unavailable; it also lacks the handshake deadline. (extensions/zalouser/src/zalo-js.ts, 3a9d69db306c)
  • Lifecycle ownership and failure propagation: Timers, event handlers, and profile ownership are established before listener.start. Cleanup cancels timers, detaches message handling, releases ownership, and retires the cached API while retaining guarded terminal handlers until closure. The existing monitor awaits ingress shutdown before rejecting. (extensions/zalouser/src/zalo-js.ts:1735, 2c81fa85f7ac)
  • Real transport proof matches the changed owner: The captured PR body, sourceRevision 4b42ebcac980a236ab16b1fcc622eb13332781c8babac9f0a53d87c2f81a0854, records stalled upgrade, timeout, monitor rejection, a second upgrade, successful connection, and abort settlement. The inspected fixture invokes the production monitor and listener with real zca-js, ws, and loopback TCP; only account restoration is stubbed. It does not claim authenticated Zalo login or a full Gateway automatic-retry run. (extensions/zalouser/src/zalo-js.listener.test.ts:137, 2c81fa85f7ac)
  • Affirmative dependency boundary: The private client adapter loads zca-js, the plugin pins version 2.1.2, and the transport fixture directly exercises its Listener. This makes zca-js’s event and stop contracts relevant; the change has no Codex dependency signal. (extensions/zalouser/src/zca-client.ts:13, 2c81fa85f7ac)
  • Pinned dependency contract verified: npm metadata identifies this repository and source commit for zca-js 2.1.2. Inspected both the published CommonJS listener and source: connected has no arguments; start creates a WebSocket without a handshake deadline; stop closes the socket and resets the listener before the asynchronous closed event. (src/apis/listen.ts:36, e6d6074feffb)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • fuller-stack-dev: 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-30T20:16:45.616Z sha 12e28b0 :: needs real behavior proof before merge. :: [P1] Define the Matrix cache caps in the events module | [P1] Match the listener event contract before subscribing | [P1] Initialize timeout state before starting the listener
  • reviewed 2026-09-17T01:22:16.147Z sha 7eb621b :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T01:43:47.092Z sha b5b4d24 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T01:57:33.991Z sha b6716f8 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 3, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 14, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
Integrate current main while preserving the contributor branch. Initialize listener ownership and deadlines before startup, retire stopped API instances, and drain late socket errors through closure. Remove unrelated Matrix changes and cover real zca-js timeout, monitor settlement, and same-profile retry.
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed channel: matrix Channel integration: matrix size: XS labels Sep 17, 2026
@fuller-stack-dev fuller-stack-dev changed the title fix(zalouser): bound Zalo listener WebSocket handshake with timeout fix(zalouser): recover when listener handshakes stall Sep 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 17, 2026
Use the existing deferred helper and exact fixture API surface, match the runtime logger contract, and bound loopback websocket frames. Preserve the verified real timeout and same-profile retry proof.
@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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 17, 2026
Preserve contributor ancestry while integrating the observed bounded-read regression repair. Reuse the canonical wrapper inventory, cold-checkout fixture and Slack receiver corrections from f91e0e0. Apply syntax-only lint corrections to the tested Zalo fixture without changing assertions or transport behavior.
Apply the reviewed type-only extraction from canonical PR150026 commit729eb63a68c71bee56544fb251dbe7d6ab42a56b to resolve the current-main import cycle exposed by PR109506 CI.
Resolve the equivalent type-only import paths in favor of the canonical ingress.types.ts owner landed by PR111148. Zalo production and real transport fixture are unchanged; the final six-file candidate passes fresh P0-P2 review and extension types/import-cycle checks.
@fuller-stack-dev
fuller-stack-dev merged commit 884f62c into openclaw:main Sep 17, 2026
181 of 182 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
* fix(matrix): bound warned room dedupe caches against unbounded growth

The warnedEncryptedRooms and warnedCryptoMissingRooms Sets had no
capacity limit. Each distinct roomId that produced an encrypted event
would be added permanently, allowing unbounded growth over the gateway
lifetime.

- Cap warnedEncryptedRooms at 256 entries.
- Cap warnedCryptoMissingRooms at 256 entries.
- Skip add when the cap is reached so the dedupe Sets never grow
  without bound.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: 廖石荣 0668000909 <[email protected]>

* fix(zalouser): bound Zalo listener WebSocket handshake with timeout

The zca-js listener WebSocket had no connect deadline, so an
unreachable Zalo server would leave the listener silently stuck
without firing connected, error, or closed events.

- Add LISTENER_HANDSHAKE_TIMEOUT_MS (30s).
- Listen for the connected event to clear the handshake timer.
- Fail the listener with a descriptive error on timeout so the
  reconnect loop retries.
- Clean up the timer and connected listener on stop/abort.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: 廖石荣 0668000909 <[email protected]>

* test(zalouser): type and bound the transport fixture

Use the existing deferred helper and exact fixture API surface, match the runtime logger contract, and bound loopback websocket frames. Preserve the verified real timeout and same-profile retry proof.

* fix(slack): reuse canonical ingress lifecycle leaf contract

Apply the reviewed type-only extraction from canonical PR150026 commit729eb63a68c71bee56544fb251dbe7d6ab42a56b to resolve the current-main import cycle exposed by PR109506 CI.

---------

Signed-off-by: 廖石荣 0668000909 <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Jason (Json) <[email protected]>
steipete added a commit that referenced this pull request Sep 17, 2026
Record the approved 362706-byte startup baseline under a 355 KiB cap, preserving the 512-byte growth and 64-byte variance allowances. Exact base and merge builds emitted byte-identical UI assets; hosted CI measured the same size.

Include the newly imported bundled plugin source utility in cold worktree fixtures, matching the repair already landed in #109506. Preserve all assertions and timeouts.
steipete added a commit that referenced this pull request Sep 17, 2026
* feat(gateway): measure synchronous session-list CPU

* fix(ci): repair native wrapper and skill-read checks

Restore three newly imported modules in the shared native PR wrapper inventory. Observe fs-safe Root.read through its current final-fence hook while preserving all aggregate byte, status, and inventory assertions.

Both defects reproduced before repair. All 24 plugin-skill bundle cases pass; nine focused native-wrapper cases pass on Blacksmith Testbox with unchanged limits. Independent review through P2 is clean.

* fix(ci): refresh measured UI budget and cold worktree fixture

Record the approved 362706-byte startup baseline under a 355 KiB cap, preserving the 512-byte growth and 64-byte variance allowances. Exact base and merge builds emitted byte-identical UI assets; hosted CI measured the same size.

Include the newly imported bundled plugin source utility in cold worktree fixtures, matching the repair already landed in #109506. Preserve all assertions and timeouts.

* test(slack): align Socket Mode fixtures with SDK acknowledgements

Give the shared receiver mock real EventEmitter listener ownership and an asynchronous acknowledgement sender, preserving the production envelope guard. Narrow WebSocket ArrayBuffer data before converting it so the loopback test typechecks without copying an existing Buffer.

The former ingress-cleanup failure reproduces before this repair; all 120 selected Slack tests and the extension test-type graph pass afterward.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
* feat(gateway): measure synchronous session-list CPU

* fix(ci): repair native wrapper and skill-read checks

Restore three newly imported modules in the shared native PR wrapper inventory. Observe fs-safe Root.read through its current final-fence hook while preserving all aggregate byte, status, and inventory assertions.

Both defects reproduced before repair. All 24 plugin-skill bundle cases pass; nine focused native-wrapper cases pass on Blacksmith Testbox with unchanged limits. Independent review through P2 is clean.

* fix(ci): refresh measured UI budget and cold worktree fixture

Record the approved 362706-byte startup baseline under a 355 KiB cap, preserving the 512-byte growth and 64-byte variance allowances. Exact base and merge builds emitted byte-identical UI assets; hosted CI measured the same size.

Include the newly imported bundled plugin source utility in cold worktree fixtures, matching the repair already landed in openclaw#109506. Preserve all assertions and timeouts.

* test(slack): align Socket Mode fixtures with SDK acknowledgements

Give the shared receiver mock real EventEmitter listener ownership and an asynchronous acknowledgement sender, preserving the production envelope guard. Narrow WebSocket ArrayBuffer data before converting it so the loopback test typechecks without copying an existing Buffer.

The former ingress-cleanup failure reproduces before this repair; all 120 selected Slack tests and the extension test-type graph pass afterward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: zalouser Channel integration: zalouser 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.

3 participants