Skip to content

fix(channels): LINE, SMS, and Zalo messages fail with "Async work scope is closed" before the agent replies - #148548

Merged
obviyus merged 4 commits into
openclaw:mainfrom
edenfunf:fix/ingress-delivery-async-work-scope
Sep 15, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
edenfunf:fix/ingress-delivery-async-work-scope

Conversation

@edenfunf

@edenfunf edenfunf commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Related: #144801, #148025

What Problem This Solves

Fixes LINE messages failing with “Something went wrong while processing your request” before the agent replies. SMS and Zalo use the same webhook pump.

User Impact

Turns can answer, wait for an exec approval, and answer queued follow-ups after the first turn ends. No configuration or migration is required.

Why This Change Was Made

The ingress drain starts dispatches that outlive the pump. Dispatch now leaves the pump's async-work scope while retaining its existing Gateway root until the task settles. Claim settlement and cancellation are unchanged. Cleanup after dispatch no longer holds the incidental webhook root; independently owned plugin cleanup keeps its own lifetime.

Evidence

  • A self-signed POST to /line/webhook on an isolated Gateway reproduced Async work scope is closed on main a81fd6123fdc, with a failed transcript turn and no inference request.
  • The repaired dispatch completed the same flow with synthetic credentials and a local receiver: ordinary reply, approval prompt, denial, approval-turn answer, queued answer, and next answer. All six sends arrived. The dedicated openclaw approvals pending and openclaw approvals resolve <id> deny commands drove the real approval.
  • 251 tests across 23 owner/channel files passed on merge 5384b5a718a2 with main 62a4d0c547bc. Both new lifetime tests fail with the original production code. Type, lint, format, export, architecture and test-partition checks pass.
  • The original Bash CI timeout did not reproduce in six focused head/base/merge/parent controls. Hosted CI on the repaired head passed on attempt 2 (run 34918875223): the single native Bash close-deadline shard was rerun alone and went green.

This pass proves the Gateway and delivery boundary, not live LINE service delivery. The contributor also recorded real LINE push receipts at 138cd4fb4b1b.

Consumers

The shared monitor and plugin state API use the drain. LINE, SMS and Zalo supply detached webhook pumps; boot-started Discord is a scope-free sibling. Public plugin signatures stay unchanged.

Dispatch and cleanup ownership

The owner's intended boundary is: “the completed pump must not be held open for unrelated follow-ups.” Dispatch leaves the pump's async-work scope and retains an existing live Gateway root until dispatch settles. The incidental webhook root then releases. Required plugin cleanup keeps its separate owner and existing shutdown bounds.

The decision to leave the pump scope is made once, by runClaimed in src/channels/message/ingress-drain.ts. Production changes are +10/−2 lines, net +8, across the dispatch owner and its private storage helper. Claim settlement, cancellation, restart admission, and completed-message deduplication remain unchanged.

Evidence boundaries

The signed /line/webhook experiment used a real isolated Gateway, synthetic credentials, deterministic inference, and a local LINE request receiver. It captured an ordinary answer, approval prompt, denial notice, approval-turn answer, queued answer, and next answer. Recipient delivery through the real LINE service is not proved by this experiment.

The live green build was 6c7067918343; production bytes are identical at 2b94019ae275. The final commit changes only an optional test callback invocation. All 251 selected tests passed on merge 5384b5a718a2, with parents 2b94019ae275 and main 62a4d0c547bc. Restoring the original production code makes both new lifetime tests fail.

The live approval sequence includes #148228. The fresh merge also includes #148301; its reply-source receipt uses separate state that the dispatch scope exit preserves. The live sequence does not include #148301, and this validation does not claim a new streamed-tail recovery experiment.

The earlier Bash failure remains classified as a non-reproduced child startup/import timeout. Six focused head, base, merge, and relevant-parent controls passed. Different hosted runtime and shard conditions prevent treating those local passes as proof that the timeout cannot recur. Hosted CI remains a separate landing check.

@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 9:57 PM ET / September 15, 2026, 01:57 UTC (Revision 3).

ClawSweeper review

What this changes

The PR lets inbound channel deliveries and queued follow-ups outlive the webhook pump’s temporary work scope, with regression coverage for restart and plugin cleanup.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still inherits the completed pump’s work scope. No blocking defect was found, the recorded Gateway proof covers the changed boundary, and the previous draft-only blocker is resolved.

Priority: P1
Reviewed head: 2b94019ae275a12fd3367b795bc283d62ae9e69e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with relevant real Gateway observations and complementary lifetime regressions; no actionable patch defect remains.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded before/after observations exercise the real signed LINE webhook, shared ingress dispatch, agent turn, approval flow, and outbound client against a local receiver; all six after-fix sends arrived. Production bytes match the reviewed head. This proves the repaired Gateway boundary, without claiming current-head delivery through LINE’s live service.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded before/after observations exercise the real signed LINE webhook, shared ingress dispatch, agent turn, approval flow, and outbound client against a local receiver; all six after-fix sends arrived. Production bytes match the reviewed head. This proves the repaired Gateway boundary, without claiming current-head delivery through LINE’s live service.
Evidence reviewed 9 items Introduced production change: The merge-base-to-head diff changes only the dispatch scope boundary and adds its private async-local helper. Existing Gateway root retention, claim settlement, cancellation signals, and public plugin signatures remain intact.
Current main still needs the fix: Fetched main starts state.task directly in the inherited async context. The pump can return while dispatch remains active, and AsyncWorkScope rejects subsequently tracked work after closure.
Latest release comparison: The v2026.9.4 ingress drain also starts dispatch with an ordinary async invocation rather than exiting the pump scope. This establishes absence of this repair, without claiming that every release environment exhibits the failure.
Findings None None.
Security None None.

How this fits together

OpenClaw’s shared ingress monitor accepts durable channel events and dispatches them to agent turns. The pump can finish before those turns and their replies, so delivery lifetime must remain independently owned.

flowchart TD
  A[Channel webhook] --> B[Durable ingress queue]
  B --> C[Short-lived pump]
  C --> D[Dispatch outside pump scope]
  D --> E[Agent turn and queued replies]
  D --> F[Retained Gateway work]
  E --> G[Channel delivery]
  F --> H[Release after dispatch settles]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +251. Total +259 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 10 2 +8
Tests 2 251 0 +251
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 261 2 +259

Review metrics

None.

Technical review

Best possible solution:

Keep dispatch lifetime with the ingress owner while preserving explicit cancellation, Gateway admission, and independently owned plugin cleanup.

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

Yes: current source exposes the pump-closure race, and the captured evidence records a failing signed LINE webhook flow before repair. This review inspected source and supplied results without executing a current-main reproduction.

Is this the best way to solve the issue?

Yes: exiting the incidental pump scope at the existing dispatch owner is narrow and preserves the separate admission and cancellation contracts without introducing another lifetime manager.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The recorded LINE failure prevents agent replies, and SMS and Zalo use the same affected detached-pump path.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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): Recorded before/after observations exercise the real signed LINE webhook, shared ingress dispatch, agent turn, approval flow, and outbound client against a local receiver; all six after-fix sends arrived. Production bytes match the reviewed head. This proves the repaired Gateway boundary, without claiming current-head delivery through LINE’s live service.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded before/after observations exercise the real signed LINE webhook, shared ingress dispatch, agent turn, approval flow, and outbound client against a local receiver; all six after-fix sends arrived. Production bytes match the reviewed head. This proves the repaired Gateway boundary, without claiming current-head delivery through LINE’s live service.

Evidence

What I checked:

  • Introduced production change: The merge-base-to-head diff changes only the dispatch scope boundary and adds its private async-local helper. Existing Gateway root retention, claim settlement, cancellation signals, and public plugin signatures remain intact. (src/channels/message/ingress-drain.ts:456, 2b94019ae275)
  • Current main still needs the fix: Fetched main starts state.task directly in the inherited async context. The pump can return while dispatch remains active, and AsyncWorkScope rejects subsequently tracked work after closure. (src/channels/message/ingress-drain.ts:454, 1b017767133a)
  • Latest release comparison: The v2026.9.4 ingress drain also starts dispatch with an ordinary async invocation rather than exiting the pump scope. This establishes absence of this repair, without claiming that every release environment exhibits the failure. (src/channels/message/ingress-drain.ts:449, 3a9d69db306c)
  • Existing lifetime and shutdown owners: The complete monitor tracks active deliveries separately from completed claims and awaits them during stop. The drain retains its existing Gateway root through dispatch, while its explicit lifecycle signal still cancels unadopted work. The new helper exits only the work-scope storage; it does not clear authorization or plugin invocation contexts. (src/channels/message/ingress-monitor.ts:314, 2b94019ae275)
  • Boundary regression coverage: Both changed test modules were read completely. They exercise work after pump closure, follow-up work after delivery settlement, retained restart admission, independent plugin cleanup, cancellation recovery, and completed-event deduplication. The captured body reports both new cases fail with the original production code and 251 selected tests pass; this read-only review did not execute tests. (src/channels/message/ingress-monitor.restart-drain.test.ts:361, 2b94019ae275)
  • Recorded real Gateway proof and revision coverage: The captured PR body, sourceRevision dd2afceea64ab8b0e770926f5ff3e83130603b96d0bebd1569e3a77979df6126, records a signed /line/webhook request failing before inference on main and six successful sends after repair: ordinary answer, approval prompt, denial, approval-turn answer, queued answer, and next answer. It used an isolated Gateway, deterministic inference, synthetic credentials, and a local LINE receiver. GitHub confirms the final commit changes only the optional cancellation callback in a test, preserving the production bytes exercised at 6c70679. The prepared screenshots were inspected and belong to the separate LINE approval-card PR; they are not proof of this lifetime fix. (2b94019ae275)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (2 earlier review cycles)
  • reviewed 2026-09-14T21:46:58.058Z sha 138cd4f :: blocked before merge. :: none
  • reviewed 2026-09-15T01:45:06.379Z sha 2b94019 :: needs changes before merge. :: none

@obviyus
obviyus marked this pull request as draft September 15, 2026 01:37
@edenfunf
edenfunf marked this pull request as ready for review September 15, 2026 01:39
@edenfunf
edenfunf marked this pull request as draft September 15, 2026 01:40
@edenfunf

Copy link
Copy Markdown
Contributor Author

Sorry, I marked this ready by mistake. It's back in draft now.

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 15, 2026
@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-admin-merge
pr: 148548
head: 2b94019
scope: owner-review

@obviyus
obviyus marked this pull request as ready for review September 15, 2026 01:50
@obviyus
obviyus merged commit fb5aeed into openclaw:main Sep 15, 2026
538 of 572 checks passed
@obviyus

obviyus commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks @edenfunf!

Proof: Signed synthetic LINE webhooks through a real Gateway completed the approval-denial and queued-follow-up sequence, with all six sends recorded at a local receiver. Real LINE recipient delivery remains unproved.

  • Bug: Inbound messages failed before an answer with Async work scope is closed.
  • Fix: The ingress drain lets dispatch outlive the webhook pump while preserving existing cancellation and cleanup ownership.
Before After
The turn failed before reply. Ordinary, approval-waiting, queued, and later turns complete and send replies to the local receiver.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…pe is closed" before the agent replies (openclaw#148548)

Related: openclaw#144801, openclaw#148025

## What Problem This Solves

Fixes LINE messages failing with “Something went wrong while processing your request” before the agent replies. SMS and Zalo use the same webhook pump.

## User Impact

Turns can answer, wait for an exec approval, and answer queued follow-ups after the first turn ends. No configuration or migration is required.

## Why This Change Was Made

The ingress drain starts dispatches that outlive the pump. Dispatch now leaves the pump's async-work scope while retaining its existing Gateway root until the task settles. Claim settlement and cancellation are unchanged. Cleanup after dispatch no longer holds the incidental webhook root; independently owned plugin cleanup keeps its own lifetime.

## Evidence

- A self-signed POST to `/line/webhook` on an isolated Gateway reproduced `Async work scope is closed` on main `4e8dd8e1859f`, with a failed transcript turn and no inference request.
- The repaired dispatch completed the same flow with synthetic credentials and a local receiver: ordinary reply, approval prompt, denial, approval-turn answer, queued answer, and next answer. All six sends arrived. The dedicated `openclaw approvals pending` and `openclaw approvals resolve <id> deny` commands drove the real approval.
- 251 tests across 23 owner/channel files passed on merge `5384b5a718a2` with main `d229f4a2ba41`. Both new lifetime tests fail with the original production code. Type, lint, format, export, architecture and test-partition checks pass.
- The original Bash CI timeout did not reproduce in six focused head/base/merge/parent controls. Full CI remains pending on the repaired head.

This pass proves the Gateway and delivery boundary, not live LINE service delivery. The contributor also recorded real LINE push receipts at `138cd4fb4b1b`.

## Consumers

The shared monitor and plugin state API use the drain. LINE, SMS and Zalo supply detached webhook pumps; boot-started Discord is a scope-free sibling. Public plugin signatures stay unchanged.

## Dispatch and cleanup ownership

The owner's intended boundary is: “the completed pump must not be held open for unrelated follow-ups.” Dispatch leaves the pump's async-work scope and retains an existing live Gateway root until dispatch settles. The incidental webhook root then releases. Required plugin cleanup keeps its separate owner and existing shutdown bounds.

The decision to leave the pump scope is made once, by `runClaimed` in `src/channels/message/ingress-drain.ts`. Production changes are +10/−2 lines, net +8, across the dispatch owner and its private storage helper. Claim settlement, cancellation, restart admission, and completed-message deduplication remain unchanged.

## Evidence boundaries

The signed `/line/webhook` experiment used a real isolated Gateway, synthetic credentials, deterministic inference, and a local LINE request receiver. It captured an ordinary answer, approval prompt, denial notice, approval-turn answer, queued answer, and next answer. Recipient delivery through the real LINE service is not proved by this experiment.

The live green build was `6c7067918343`; production bytes are identical at `2b94019ae275`. The final commit changes only an optional test callback invocation. All 251 selected tests passed on merge `5384b5a718a2`, with parents `2b94019ae275` and main `d229f4a2ba41`. Restoring the original production code makes both new lifetime tests fail.

The live approval sequence includes openclaw#148228. The fresh merge also includes openclaw#148301; its reply-source receipt uses separate state that the dispatch scope exit preserves. The live sequence does not include openclaw#148301, and this validation does not claim a new streamed-tail recovery experiment.

The earlier Bash failure remains classified as a non-reproduced child startup/import timeout. Six focused head, base, merge, and relevant-parent controls passed. Different hosted runtime and shard conditions prevent treating those local passes as proof that the timeout cannot recur. Hosted CI remains a separate landing check.

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

Labels

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.

2 participants