Skip to content

fix(zalouser): settle waitForExit when abort signal already fired - #109988

Closed
LZY3538 wants to merge 10 commits into
openclaw:mainfrom
LZY3538:fix/zalouser-abort-signal-race
Closed

LZY3538 wants to merge 10 commits into
openclaw:mainfrom
LZY3538:fix/zalouser-abort-signal-race

Conversation

@LZY3538

@LZY3538 LZY3538 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where stopping a ZaloUser gateway account during or immediately after connection startup could leave channel shutdown waiting forever. The race occurs when the gateway stop signal is already aborted before the monitor registers its listener, or becomes aborted while startup allowlist/group resolution is in progress.

Why This Change Was Made

AbortSignal does not replay an abort event to listeners registered after the signal has fired. The monitor now checks for shutdown before asynchronous startup work and rechecks after that work before creating the Zalo listener. The existing listener lifecycle remains local to listener startup; no extra lifecycle state is introduced.

The fix stays inside the ZaloUser plugin and adds no config, protocol, SDK, dependency, or compatibility surface.

User Impact

ZaloUser stop and restart operations now settle promptly instead of hanging during fast gateway restarts or overlapping account lifecycle transitions. An aborted startup also cannot restore a Zalo listener session.

Evidence

The dedicated lifecycle suite follows the production gateway boundary (zalouserPlugin.gateway.startAccount -> monitorZalouserProvider) and mocks only the outer Zalo SDK/network boundary. It proves:

  • normal startup remains pending until abort, then invokes the listener's stop exactly once and settles;
  • shutdown during the pending friends-resolution Promise completes without restoring startZaloListener;
  • an already-aborted signal skips monitor preflight and listener startup;
  • failure-path cleanup always aborts and settles test tasks, preventing leaked Promises or cross-test pollution.

Same-test A/B result:

Revision Result Observable behavior
origin/main@347ee45895 1 passed, 2 failed Calls startZaloListener after mid-preflight abort; calls listZaloFriends after pre-abort
refreshed PR head e49cbc2f2c 3 passed, 0 failed Both invalid startup paths are skipped; normal abort/stop lifecycle still passes

Focused validation on PR head:

Test Files  3 passed (3)
Tests       26 passed (26)
node scripts/run-vitest.mjs extensions/zalouser/src/channel.lifecycle.test.ts extensions/zalouser/src/monitor.group-gating.test.ts extensions/zalouser/src/monitor.account-scope.test.ts

pnpm format and git diff --check pass. The local changed-check could not acquire Blacksmith because the blacksmith executable is unavailable; the pushed head's standard GitHub lint/type/build gates are the authoritative replacement.

Live configured-account proof

Run on the code-equivalent pre-refresh head 6b1c1d291e with a real Zalo personal account and an isolated pr109988-proof profile. The harness used the production gateway, monitor, listener, credential-state migration, and zca-js network path; it did not mock the Zalo SDK or network. Direct and group inbound policies were disabled, and no messages were sent.

MIGRATION changes=2 warnings=0
CREDENTIAL_STATE entries=1
PROOF_START sha=6b1c1d291e2269fc30cbc52dad27d15ae30ea151 pid=<redacted>
GATEWAY_INFO [pr109988-proof] starting zalouser provider (<display-name-redacted>)
PREABORT_RETURNED elapsed_ms=2235
GATEWAY_INFO [pr109988-proof] starting zalouser provider (<display-name-redacted>)
LIVE_1_ACTIVE pid=<redacted> settled=false
LIVE_1_STOPPED settled=true
GATEWAY_INFO [pr109988-proof] starting zalouser provider (<display-name-redacted>)
LIVE_2_ACTIVE pid=<redacted> settled=false
LIVE_2_STOPPED settled=true
PROOF_COMPLETE

During LIVE_1_ACTIVE, the operating system reported two Established TCP connections owned by the proof process to Zalo endpoints on remote port 443. After the already-aborted invocation returned, the first live start succeeded immediately; if that invocation had retained a listener for the profile, production startZaloListener would have rejected it as already running. Both real listener cycles stayed pending while active, settled after abort, and the second start proves the first stop released the listener for restart.

This live result closes the previously stated configured-account boundary gap. The branch was subsequently replayed without conflicts onto origin/main@347ee45895 as head e49cbc2f2c; the resulting PR diff remains the same three files (+142/-1). The committed same-test A/B was rerun against that current main (1/3) and refreshed head (3/3). The configured-account run proves the unchanged fix over the real credential and Zalo network boundary.

@openclaw-barnacle openclaw-barnacle Bot added channel: zalouser Channel integration: zalouser size: XS labels Jul 17, 2026
@clawsweeper clawsweeper Bot added 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. 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 maintainer review before merge. Reviewed July 18, 2026, 7:41 AM ET / 11:41 UTC.

Summary
The PR adds pre- and post-preflight abort guards to monitorZalouserProvider and lifecycle regression coverage so already-aborted or mid-preflight shutdown cannot start or restore a Zalo listener.

PR surface: Source +12, Tests +129. Total +141 across 3 files.

Reproducibility: yes. at source level: invoke the ZaloUser gateway start with an already-aborted signal or abort during async allowlist/group preflight; supplied A/B tests and configured-account output report the former behavior and the fix. I could not independently run or inspect that path because the review sandbox rejected read-only command execution.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • [P2] Refresh the branch against current main and retain green required checks on that exact head.

Risk before merge

  • [P1] The branch is behind current main; refresh it and re-run required checks on the exact mergeable head before landing.

Maintainer options:

  1. Refresh current-base proof (recommended)
    Rebase or use the merge queue, then require the exact refreshed head to pass its existing lifecycle and required checks before merge.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Refresh against current main and gate merge on the resulting exact head's required checks.

Next step before merge

  • [P2] No mechanical repair is identified; a maintainer should review the refreshed exact head because the branch is behind current main.

Security
Cleared: The supplied three-file diff changes only ZaloUser abort ordering and tests; it adds no dependency, secret, permission, workflow, or external execution surface.

Review details

Best possible solution:

Rebase or merge-queue-refresh this focused plugin-local fix onto current main, preserve the two abort guards and lifecycle coverage, and land it once the refreshed required checks stay green.

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

Yes, at source level: invoke the ZaloUser gateway start with an already-aborted signal or abort during async allowlist/group preflight; supplied A/B tests and configured-account output report the former behavior and the fix. I could not independently run or inspect that path because the review sandbox rejected read-only command execution.

Is this the best way to solve the issue?

Yes, based on the supplied diff and proof: guards before cancellable startup work and before listener creation are the narrowest way to ensure shutdown wins without adding lifecycle state or public surface.

AGENTS.md: unclear because the file could not be read completely.

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

Label changes

Label changes:

  • add merge-risk: 🚨 availability: The patch changes shutdown/startup ordering for a channel listener, so the refreshed merge result must retain prompt stop and restart behavior.

Label justifications:

  • P1: A ZaloUser gateway stop can hang while an account is starting or restarting.
  • merge-risk: 🚨 availability: The patch changes shutdown/startup ordering for a channel listener, so the refreshed merge result must retain prompt stop and restart behavior.
  • 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 (logs): The PR body provides redacted after-fix configured-account output showing pre-abort return, two real listener stop cycles, and a successful restart through the production gateway and Zalo network path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides redacted after-fix configured-account output showing pre-abort return, two real listener stop cycles, and a successful restart through the production gateway and Zalo network path.
Evidence reviewed

PR surface:

Source +12, Tests +129. Total +141 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 0 +12
Tests 2 130 1 +129
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 142 1 +141

What I checked:

  • PR source change: The supplied diff adds an abortSignal.aborted return before asynchronous resolution and another immediately before listener startup, matching the described pre-abort and mid-preflight race boundary. (extensions/zalouser/src/monitor.ts:764, e49cbc2f2c14)
  • Behavior proof: The PR body reports a redacted configured-account run through the production gateway, monitor, listener, credential state, and real zca-js network path: pre-abort returned, two active listener cycles settled after abort, and the second restart succeeded. (6b1c1d291e22)
  • CI and focused validation: Provided GitHub context reports the refreshed head’s CI gate, build, lint, type, architecture, security, and real-behavior-proof checks as successful, plus 26 focused lifecycle tests passed. (extensions/zalouser/src/channel.lifecycle.test.ts:1, e49cbc2f2c14)
  • Current-base limitation: The PR is marked mergeable but behind its base; the supplied current main SHA is later than the PR base, so the exact merge result and current-main equivalence require a rebase or merge-queue refresh before landing. (f98bcb7fa73c)

Likely related people:

  • LZY3538: The supplied PR history shows the author developed the ZaloUser abort guards and the focused lifecycle coverage; independent current-main ownership could not be traced because read-only shell inspection failed. (role: proposed fix author and recent lifecycle-test contributor; confidence: low; commits: 88969c9ab73e, e49cbc2f2c14; files: extensions/zalouser/src/monitor.ts, extensions/zalouser/src/channel.lifecycle.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 (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-18T03:44:22.486Z sha ffe5ebcfe2f4939fc2b60bbe76922a48d5d0413c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T04:56:10.606Z sha a4be8e9450312ef984340c3cfcda3e2fcad8110c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T05:02:25.022Z sha a4be8e9450312ef984340c3cfcda3e2fcad8110c :: needs real behavior proof before merge. :: [P1] Return waitForExit from the pre-abort path
  • reviewed 2026-07-18T05:17:53.418Z sha 86bb679c6f0236e9ec9581e9dc31a275c3ed7be6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T06:46:51.090Z sha 6b1c1d291e2269fc30cbc52dad27d15ae30ea151 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T06:54:44.455Z sha 6b1c1d291e2269fc30cbc52dad27d15ae30ea151 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T10:47:40.819Z sha 6b1c1d291e2269fc30cbc52dad27d15ae30ea151 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T10:59:39.795Z sha e49cbc2 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 17, 2026
@LZY3538
LZY3538 force-pushed the fix/zalouser-abort-signal-race branch from cd5467c to ffe5ebc Compare July 18, 2026 02:30
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 18, 2026
@LZY3538

LZY3538 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Head a4be8e9450 adds a committed regression test for abort arriving while startup resolution is still pending. Focused ZaloUser lifecycle coverage is 25/25 passing, openclaw/ci-gate is green, and the Real behavior proof check is green. The PR body now states the evidence boundary explicitly; no configured ZaloUser account is available here, so please reassess the committed production-function boundary proof or leave the maintainer acceptance request as the only remaining action.

@clawsweeper

clawsweeper Bot commented Jul 18, 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:

@LZY3538

LZY3538 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@steipete all CI and the Real behavior proof check are green on a4be8e9450, and ClawSweeper reports no remaining code repair. This environment has no configured ZaloUser account, so the only remaining gate is either a live account run or explicit maintainer acceptance of the production-monitor boundary proof. If that evidence bar is acceptable for this narrowly scoped lifecycle fix, please record acceptance and merge when convenient.

@LZY3538 LZY3538 closed this Jul 18, 2026
@LZY3538 LZY3538 reopened this Jul 18, 2026
@LZY3538 LZY3538 closed this Jul 18, 2026
@LZY3538 LZY3538 reopened this Jul 18, 2026
@LZY3538

LZY3538 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Final head: 6b1c1d291e.

New evidence since the prior review:

  • Dedicated production lifecycle path: zalouserPlugin.gateway.startAccount -> real monitorZalouserProvider; only the outer Zalo SDK/network boundary is mocked.
  • Same-test A/B: origin/main@4e0cc187a2 = 1/3 passed, with direct failures showing listener restoration after mid-preflight abort and friends lookup after pre-abort; final head = 3/3 passed.
  • Normal-path contract also proves the exact account/profile/AbortSignal reaches startZaloListener, remains pending before abort, calls stop once, and settles after abort.
  • Focused related suite: 3 files, 26/26 tests passed.
  • Final-head GitHub gates: Real behavior proof passed; CI passed including build, lint, prod types, test types, changed tests, channel contracts, architecture boundaries, security, and openclaw/ci-gate.

The PR body contains the full commands, result matrix, and the explicit remaining live-account limitation. Please assess the final source and this gateway-boundary A/B evidence rather than the earlier monitor-only proof.

@clawsweeper

clawsweeper Bot commented Jul 18, 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:

@LZY3538

LZY3538 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

A real Zalo personal account was configured on final head 6b1c1d291e. The PR body now includes redacted production gateway/monitor/zca-js output: the already-aborted invocation returned, two consecutive real listener cycles remained pending while active and settled after abort, restart succeeded, and the proof process owned established TLS connections to Zalo endpoints on port 443. No SDK or network mock was used and no messages were sent. Please reassess the configured-account 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: 🦪 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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels 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]>
LZY3538 and others added 9 commits July 18, 2026 18:56
…ady fired

When the gateway stop AbortSignal is already aborted at construction
time, return immediately after settling waitForExit instead of falling
through to startZaloListener which restores the Zalo API session and
resolves the user. An already-aborted shutdown should not perform
asynchronous session startup or allocate listener resources.

Also add a focused regression test that asserts startZaloListener is
not called for a pre-aborted signal and the monitor resolves promptly
with a stop handle.

Co-Authored-By: Claude <[email protected]>
Move the abort-signal lifecycle guard before the account-resolution
preflight (allowlist name resolution, Zalo friends/groups API calls)
so an already-aborted shutdown does not perform Zalo API calls or
session restoration in startZaloListener.

Previously the abort check sat after the preflight block, which could
make blocking Zalo API calls (listZaloFriends, listZaloGroups) during
a shutdown that was already requested.

Co-Authored-By: Claude <[email protected]>
If the abort signal fires during async preflight work (listZaloFriends,
listZaloGroups), the abort handler settles waitForExit but execution
resumes after the preflight and can still reach startZaloListener during
an already-requested shutdown. Add a post-preflight recheck of stopped
and abortSignal.aborted to prevent listener startup after abort.

Co-Authored-By: Claude <[email protected]>
…guard

The helper pre-aborted the signal to skip listener startup while still
running the friends/groups resolution in the try block. With the new
pre-try-block abort guard the function returns before the try block,
so no resolution occurs.

Fix: defer the abort into startZaloListenerMock so resolution runs
first and the signal is aborted inside the listener, which triggers
the post-startZaloListener abortSignal.aborted check (line 961) to
settle waitForExit cleanly.

Co-Authored-By: Claude <[email protected]>
@LZY3538
LZY3538 force-pushed the fix/zalouser-abort-signal-race branch from 6b1c1d2 to e49cbc2 Compare July 18, 2026 10:57
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 18, 2026
@LZY3538 LZY3538 closed this Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: zalouser Channel integration: zalouser merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: S 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.

1 participant