Skip to content

fix(zalo): trigger cleanup when abort signal already fired - #109990

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

LZY3538 wants to merge 6 commits into
openclaw:mainfrom
LZY3538:fix/zalo-abort-signal-race

Conversation

@LZY3538

@LZY3538 LZY3538 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a shutdown race in the Zalo channel provider. When the gateway stop AbortSignal was already aborted before monitorZaloProvider registered its listener, the abort event was not replayed and startup continued into polling or webhook resource acquisition.

Why This Change Was Made

The monitor now checks abortSignal.aborted immediately before listener registration and before acquiring hosted-media routes, registering a webhook, or starting polling. The normal later-abort path remains unchanged.

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

User Impact

Fast gateway stops and overlapping account lifecycle transitions no longer allow Zalo polling, webhook mutation, or local HTTP-route startup after shutdown has already won the race.

Evidence

Real behavior proof

The committed integration test exercises the complete production boundary:

configured OpenClaw Zalo account -> zaloPlugin.gateway.startAccount -> startZaloGatewayAccount -> real account probe -> monitorZaloProvider

It does not mock the Zalo API module, monitor, gateway runtime, config resolver, fetch, AbortSignal, or plugin HTTP-route registry. The production Zalo HTTP client connects over a real loopback TCP socket using its supported ZALO_API_URL override. The loopback endpoint returns normal Zalo-shaped responses and records every API method observed without exposing the configured token.

The same test was run against the PR base and the reviewed head:

Revision Result API methods observed after configured gateway startup Local routes after return
Base db3213264a 0 passed, 2 failed polling: getMe, getWebhookInfo; webhook: getMe, setWebhook, deleteWebhook 0
Head 14a96a5713 2 passed, 0 failed polling: getMe; webhook: getMe 0

getMe is the production gateway's account probe. On the fixed head, the already-aborted monitor performs no polling inspection, update polling, webhook registration/deletion, or local route registration after that probe.

Base failure excerpts:

polling: expected [ 'getMe', 'getWebhookInfo' ] to deeply equal [ 'getMe' ]
webhook: expected [ 'getMe', 'setWebhook', 'deleteWebhook' ] to deeply equal [ 'getMe' ]
Test Files  1 failed (1)
Tests       2 failed (2)

Head result:

Test Files  1 passed (1)
Tests       2 passed (2)

Focused related validation on the final head:

node scripts/run-vitest.mjs \
  extensions/zalo/src/channel.pre-aborted.integration.test.ts \
  extensions/zalo/src/monitor.lifecycle.test.ts \
  extensions/zalo/src/channel.startup.test.ts

Test Files  3 passed (3)
Tests       10 passed (10)

Targeted oxfmt, oxlint, and git diff --check pass. The standard pushed-head CI remains authoritative for full build, lint, and test-type gates.

Proof boundary: this is a real-process, real-socket integration against a deterministic loopback Zalo API endpoint, not a claim of testing the public Zalo service. That substitution is appropriate for this race because the asserted behavior is the absence and ordering of API/resource acquisition after a pre-aborted lifecycle; the test fails on the base by observing the exact unwanted production HTTP methods and passes on the fixed head with only the required account probe.

When the gateway stop AbortSignal is already aborted at construction
time, the addEventListener('abort', stopOnAbort) listener never fires
per the AbortSignal spec. In non-webhook mode this skips stop() and
leaves the Zalo provider running. The fix calls stopOnAbort immediately
when abortSignal.aborted is already true, matching the pre-aborted
handling pattern in WhatsApp (openclaw#109903), QQBot (openclaw#109896), and ZaloUser
(openclaw#109988).

Co-Authored-By: Claude <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added channel: zalo Channel integration: zalo size: XS 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. P1 High-priority user-facing bug, regression, or broken workflow. 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 July 18, 2026, 6:37 AM ET / 10:37 UTC.

Summary
The branch makes monitorZaloProvider stop and return before polling, webhook, or route acquisition when its abort signal was already fired, and adds lifecycle plus loopback-HTTP regression coverage.

PR surface: Source +9, Tests +162. Total +171 across 3 files.

Reproducibility: yes. in source-backed integration evidence: the supplied A/B loopback gateway scenario observes the unwanted Zalo API/resource-acquisition path on the base and its absence on the proposed head. The supplied evidence is against the PR base rather than a newly executed current-main run.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/zalo/src/channel.pre-aborted.integration.test.ts. Confirm migration or upgrade compatibility proof before merge.

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] Rebase or refresh the merge result against current main and let required checks validate that exact head.

Risk before merge

  • [P1] The branch is behind current main; refresh the merge result and required checks for the exact rebased head before landing.

Maintainer options:

  1. Decide the mitigation before merge
    Land the guarded early-return path after a routine rebase/check refresh, preserving the existing normal later-abort cleanup path.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No narrow automated repair remains; the next action is normal maintainer merge review after refreshing the behind branch.

Security
Cleared: The diff changes only Zalo monitor lifecycle control flow and local regression tests; it adds no dependency, permission, credential, workflow, or supply-chain surface.

Review details

Best possible solution:

Land the guarded early-return path after a routine rebase/check refresh, preserving the existing normal later-abort cleanup path.

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

Yes in source-backed integration evidence: the supplied A/B loopback gateway scenario observes the unwanted Zalo API/resource-acquisition path on the base and its absence on the proposed head. The supplied evidence is against the PR base rather than a newly executed current-main run.

Is this the best way to solve the issue?

Yes. Checking the already-fired signal at the monitor boundary, invoking existing cleanup, and returning before resource acquisition is the narrowest fix; it avoids adding lifecycle state, configuration, or a parallel cleanup path.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix production-path loopback HTTP A/B run showing the base performs unwanted Zalo polling/webhook calls after pre-abort while the head performs only the account probe; no secret-bearing evidence is included.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies an after-fix production-path loopback HTTP A/B run showing the base performs unwanted Zalo polling/webhook calls after pre-abort while the head performs only the account probe; no secret-bearing evidence is included.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes a bounded channel lifecycle race that can leave polling, webhook, or route work active during rapid shutdown, without evidence of a broad active outage.
  • 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 (live_output): The PR body supplies an after-fix production-path loopback HTTP A/B run showing the base performs unwanted Zalo polling/webhook calls after pre-abort while the head performs only the account probe; no secret-bearing evidence is included.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix production-path loopback HTTP A/B run showing the base performs unwanted Zalo polling/webhook calls after pre-abort while the head performs only the account probe; no secret-bearing evidence is included.
Evidence reviewed

PR surface:

Source +9, Tests +162. Total +171 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 0 +9
Tests 2 162 0 +162
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 171 0 +171

What I checked:

  • Pre-aborted guard: The proposed guard calls the existing abort cleanup path and returns before registering a late abort listener or acquiring hosted-media, webhook, or polling resources. (extensions/zalo/src/monitor.ts:856, 14a96a5713d8)
  • Production-boundary regression proof: The added integration coverage starts the configured Zalo gateway path with a real AbortSignal and production HTTP client against loopback, asserting that pre-abort prevents polling/webhook calls and route registration after the required account probe. (extensions/zalo/src/channel.pre-aborted.integration.test.ts:1, 14a96a5713d8)
  • Prior review continuity: The latest completed ClawSweeper cycle reviewed the same head and reported no remaining findings after the contributor added the production-path loopback proof; the earlier cleanup-registration finding was addressed by the explicit return. (extensions/zalo/src/monitor.ts:856, 14a96a5713d8)

Likely related people:

  • vincentkoc: The PR timeline records a direct notification and subscription during the initial lifecycle review, making this person the only concrete non-author routing signal available in the supplied history. (role: recent review participant; confidence: low; files: extensions/zalo/src/monitor.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 (6 earlier review cycles)
  • reviewed 2026-07-17T12:47:51.069Z sha 812103b :: needs real behavior proof before merge. :: [P1] Avoid stopping before cleanup handlers are registered
  • reviewed 2026-07-17T13:15:20.984Z sha 522274f :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T14:18:43.170Z sha 7bb50ef :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T02:16:39.417Z sha 2eab8ad :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T02:59:27.133Z sha 2eab8ad :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-18T09:55:49.418Z sha 14a96a5 :: needs maintainer review before merge. :: none

LZY3538 and others added 2 commits July 17, 2026 21:09
…dy fired

When the gateway stop AbortSignal is already aborted, return immediately
after calling stopOnAbort() instead of falling through to hosted-media
route registration, webhook setup, or polling. Previously, calling
stop() before resource acquisition set stopped=true with an empty
stopHandlers list; startup then continued and registered cleanup
handlers (e.g. plugin HTTP route unregister callbacks) that were
skipped by the finally block because stopped was already true. This
leaked plugin HTTP routes across restart cycles.

The fix exits before the try block so no resources are ever acquired
when the monitor is already destined for shutdown.

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

Verify that monitorZaloProvider returns immediately without entering
the polling loop or registering webhook routes when the abort signal
is already aborted at construction time.

Co-Authored-By: Claude <[email protected]>
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 17, 2026
ClawSweeper review feedback: the polling regression test should also
assert getWebhookInfo is not called, since on main the polling path
inspects the webhook before starting the loop. Without the early-return
guard a pre-aborted signal would trigger the webhook inspection and
then hang at waitForAbortSignal.

Co-Authored-By: Claude <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 18, 2026
@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
@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@LZY3538

LZY3538 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Head 14a96a5 adds a committed no-module-mock integration proof through the configured Zalo account resolver, production gateway startAccount path, production HTTP client over loopback TCP, real AbortSignal, and real plugin route registry. The same test fails 2/2 on base db32132 by observing getWebhookInfo or setWebhook/deleteWebhook after pre-abort, and passes 2/2 on head with only the required getMe account probe and zero routes. The PR body contains the exact A/B matrix and proof boundary; Real behavior proof is green.

@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:

@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. labels Jul 18, 2026
steipete added a commit that referenced this pull request Jul 29, 2026
Reconstruct the verified Zalo lifecycle fix from #109990 on current main and preserve its exact production and regression-test blobs.

Source: #109990

Co-authored-by: LZY3538 <[email protected]>
steipete added a commit that referenced this pull request Jul 29, 2026
Reconstruct the verified Zalo lifecycle fix from #109990 on current main and preserve its exact production and regression-test blobs.

Source: #109990

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: LZY3538 <[email protected]>

Copy link
Copy Markdown
Contributor

Thank you, @LZY3538 — your Zalo lifecycle fix and both regression-test files are now landed on current main, with your original production and test blobs preserved and your Co-authored-by credit included.

Canonical PR: #115763
Landed commit: 4a19f39

We reconstructed your change on current repaired main because the original fork could not accept a signed main-merge through the repository-native publishing guard. Before landing, we independently reproduced the original failure in both configured polling and webhook modes, passed the original 123-test Zalo plugin suite, verified real gateway-to-loopback HTTP regressions on the exact signed replacement, and confirmed that all seven hosted workflows passed.

Closing this original only now that the canonical commit has actually merged. Thank you for identifying and fixing the startup/shutdown race.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
)

Reconstruct the verified Zalo lifecycle fix from openclaw#109990 on current main and preserve its exact production and regression-test blobs.

Source: openclaw#109990

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: LZY3538 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: zalo Channel integration: zalo P2 Normal backlog priority with limited blast radius. 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.

3 participants