Skip to content

fix(channels): keep started ingress deliveries admissible after their inherited root releases - #126590

Merged
Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
edenfunf:fix/ingress-dispatch-admission
Aug 20, 2026
Merged

Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
edenfunf:fix/ingress-dispatch-admission

Conversation

@edenfunf

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #126441.

On 2026.8.1-beta.2 and current main, every inbound LINE message is refused in 10-18 ms with GatewayDrainingError: Gateway is draining; new tasks are not accepted on a gateway that was never asked to stop or restart. The gateway reports itself healthy the whole time — ready, channels status --probe returns works — while the sender only sees the LINE loading indicator and never receives a reply. The durable queue retries each event on its backoff and every attempt fails identically, so events walk their budget toward dead-letter. The same message on 2026.7.1-2 is delivered normally.

The defect lives in the shared durable ingress drain, so every channel on it is exposed — the 16 extension channels using createChannelIngressMonitor (LINE, Discord, WhatsApp, Signal, iMessage, Feishu, Mattermost, MS Teams, IRC, Twitch, Nostr, Tlon, SMS, Nextcloud Talk, Zalo, Zalo Personal) plus the plugin registry runtime.

Why This Change Was Made

drainOnce starts each claimed dispatch without awaiting it (runClaimed(claimed, laneKey) in ingress-drain.ts), so the dispatch task outlives whatever admission context it inherits — the detached pump root (released when runPump returns, while deliveries are still in flight) or the transport request that enqueued the event (released once the webhook 200 is written). isGatewaySubordinateWorkAdmissionClosed() treats an inherited released root as closed (gateway-work-admission.ts branch return current.released), so beginSessionWorkAdmission refuses the turn as if the gateway were draining. No admission closed is ever logged because no admission fence was ever raised — the failing runs contain zero admission-closure lines across their whole lifetime, which is how the refusal was isolated to that branch by elimination.

The fix gives the dispatch task an admission context whose lifetime matches its own, at the single point where it detaches:

  • inherited root still live → retainGatewayRootWorkAdmissionContinuation() holds it until the task settles, so a real restart drain keeps waiting for in-flight deliveries;
  • inherited root already released (or absent) → the dispatch runs via runOutsideGatewayRootWorkAdmission, so the dead lease cannot poison it, while a real restart drain still refuses it at admission and the existing GatewayDrainingError disposition releases the claim without spending an attempt (preserving fix(channels): preserve ingress during gateway restarts #125919's semantics — the two changes compose).

This is the same released-root class fixed four times before, each by applying one of these helpers at the affected call site: #116040, #116094, #117505, #118105. The ingress drain was the remaining caller without that treatment. The exposure dates to the durable drain engine itself (fc6b9dad0b1 starts dispatches without awaiting them) and reached all channels with the shared monitor (c163daa4ed0, #111249, whose waitForDeliveryIdleBeforeRepump: false production default releases the pump root while deliveries run); 2026.7.1-2 predates both, and its @openclaw/[email protected] dist contains none of the shared-monitor entry points, which is why the control is immune.

Alternatives considered and rejected: wrapping the dispatch in runWithGatewayIndependentRootWorkContinuation adds microtask hops after dispatch resolution, which lets dispose() win the settlement race on stop and breaks the pre-adoption release contract (two existing tests catch this); making the pump wait for delivery idle before returning changes pump throughput semantics; and relaxing the released-root check in session admission would weaken the reset-retirement invariant globally.

One disclosed trade-off: a dispatch that starts on the outside path is not tracked in activeRootWork, so a restart drain does not wait for it. Today such a dispatch cannot run at all, and if a restart cuts it mid-flight the claim is recovered by the stale-lease path and redelivered — ordinary crash semantics for the durable queue.

User Impact

Inbound messages on durable-ingress channels reach the agent again. Before the fix, on an affected gateway every inbound message was silently lost from the sender's point of view while all health surfaces reported green; recovery required reading gateway logs. After the fix, messages are admitted, turns run, and a genuine restart drain still refuses or waits exactly as designed.

Evidence

Controlled three-version comparison, one variable (the OpenClaw version), same host, tunnel, port, LINE channel, config shape, webhook URL:

Version Result
2026.7.1-2 + @openclaw/[email protected] reply delivered ([model-fetch] response ... status=200 elapsedMs=2014); 0 draining errors
2026.8.1-beta.2 + @openclaw/[email protected] (version-matched) every message refused; 28 draining errors
main at 0f1670d8951 (source run) every message refused; 20 draining errors

Failing shape (identical on both bad versions, first attempt and every durable retry):

[diagnostic] message processed: channel=line ... outcome=error duration=16ms
  error="GatewayDrainingError: Gateway is draining; new tasks are not accepted"
[line] spooled update message:628040302011613237 failed; keeping for retry: Gateway is draining

Zero admission closed / admission reopened lines across both failing runs' lifetimes (checked in the file log), which excludes every fence-based closure and leaves only the inherited released root.

With this fix applied to the same source tree, the same live LINE channel delivers again: five inbound events (three sent from a real LINE client, two self-signed webhook posts) all passed admission — 0 draining errors — and the turn ran to a model response:

[provider-transport-fetch] [model-fetch] response provider=openrouter api=openai-completions
  model=anthropic/claude-haiku-4-5 status=200 elapsedMs=3095

One of the live events also demonstrated the durable path end to end: the gateway was stopped while the event was mid-retry, and the successor process recovered the claim and redelivered it. (During the fixed-run verification an unrelated failure surfaced after admission — the prepared model catalog worker rejects source runs because its reconstructed registry index diverges from the persisted one; that is a separate defect, reported separately, and was locally bypassed only to let the turn complete for this evidence. The admission counts above are unaffected by it.)

Red/green, both fix paths, deterministic:

  • keeps a started delivery admissible after its detached pump root releases — mirrors the production webhook-spool combination (runPumpTask + waitForDeliveryIdleBeforeRepump: false, admit inside a root that releases after the enqueue, delivery gated until the pump task settles). Without the fix: expected true to be false (admission observed closed during delivery). With it: passes.
  • dispatches outside an already-released inherited root instead of refusing — no runPumpTask, the pump chain inherits the admitting caller's released root via a gated pending scan. Without the fix: expected true to be false. With it: passes.

Both prior contract tests that constrain this area pass unchanged — defers a claimed event across restart drain without consuming retry budget (#125919) and releases a pre-adoption delivery for retry before disposing on stop — i.e. restart-drain refusal and stop-release ordering are preserved, not worked around.

Full runs: src/channels/message/ 171/171; tsgo:core and tsgo:test:src clean; oxlint clean; oxfmt --check clean.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 3:55 AM ET / 07:55 UTC.

ClawSweeper review

What this changes

The PR keeps detached durable channel deliveries admissible after their originating gateway root has been released.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. This is a source-supported repair for a real shared durable-ingress regression; the lifetime transfer is at the correct detachment owner and has no actionable correctness finding. It should wait for exact-head CI before merge.

Priority: P1
Reviewed head: 458ad41c3f88918749614151e25afea38ed9c655

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A narrow, source-supported repair with credible real-channel evidence and focused lifecycle regressions.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR provides controlled post-fix live LINE output showing delivered model responses and zero draining refusals; published logs should remain redacted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR provides controlled post-fix live LINE output showing delivered model responses and zero draining refusals; published logs should remain redacted.
Evidence reviewed 7 items Current-main failure path: The pump can return after starting a delivery when idle-waiting is disabled; a detached pump wrapper then releases its root while the delivery continues.
Admission invariant: A released inherited root is treated as closed, while the existing helpers either retain a live root or exit the released AsyncLocalStorage context.
Correct repair boundary: The patch retains the root before the unawaited claimed delivery starts, otherwise dispatches outside a released root, and releases the retained reference in the task finally block.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/channels/message/ingress-monitor.test.ts --testNamePattern "keeps a started delivery admissible|dispatches outside an already-released"

Result: PASS (completed)

node scripts/run-vitest.mjs src/channels/message/ingress-monitor.test.ts --testNamePattern "keeps a started delivery admissible|dispatches outside an already-re
leased"
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126590-9rk5UK/target$ node scripts/run-vitest.mjs src/channels/message/ingress-monitor.test.ts --testNamePatter
n "keeps a started delivery admissible|dispatches outside an already-released"
node scripts/run-vitest.mjs src/channels/message/ingress-monitor.test.ts --testNamePattern "keeps a started delivery admissible|dispatches outside an already-re
leased"
[test] starting test/vitest/vitest.channels.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126590-9rk5UK/target

 ✓  channels  src/channels/message/ingress-monitor.test.ts (28 tests | 26 skipped) 567ms
     ✓ keeps a started delivery admissible after its detached pump root releases  346ms

 Test Files  1 passed (1)
      Tests  2 passed | 26 skipped (28)
   Start at  07:56:35
   Duration  2.79s (transform 1.68s, setup 1.07s, import 803ms, tests 567ms, environment 0ms)

[test] passed 1 Vitest shard in 8.29s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126590-9rk5UK/target$ node scripts/run-vitest.mjs src/channels/message/ingress-monitor.test.ts --testNamePatter
n "keeps a started delivery admissible|dispatches outside an already-released"






























Assertions:

  • PASS expect_output: 2 passed

How this fits together

Durable channel ingress queues webhook events and later dispatches each claim into an agent turn. Gateway admission prevents new work during lifecycle drains, so detached deliveries must not inherit a released request or pump root.

flowchart LR
A[Channel webhook] --> B[Durable ingress queue]
B --> C[Ingress pump]
C --> D[Detached delivery]
D --> E[Gateway admission]
E --> F[Agent turn]
E --> G[Restart drain deferral]
Loading

Before merge

  • Resolve merge risk (P1) - This generic ingress change affects all monitors using detached or inherited roots, so an error could alter message delivery or restart-time claim recovery; exact-head ingress and required CI are still pending.
  • Resolve merge risk (P1) - Production code grows by 17 net lines; the growth is justified by the two necessary owner-boundary paths and their single finally release, with no net-neutral equivalent found.
  • Complete next step (P2) - The active PR already owns the bounded repair; the remaining work is normal exact-head validation and merge review.
Agent review details

Security

None.

PR surface

Source +17, Tests +108. Total +125 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 19 2 +17
Tests 1 108 0 +108
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 127 2 +125

Review metrics

Metric Value Why it matters
Production versus test delta production +17, tests +108 The production increase implements the retained-root and released-root branches at the generic owner boundary; added tests cover both paths.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126441
Summary: This PR is the candidate repair for the canonical durable-ingress admission regression.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Validate the shared delivery boundary (recommended)
    Merge after the exact PR head passes focused ingress lifecycle coverage and required CI, confirming delivery and restart-time claim recovery together.

Technical review

Best possible solution:

Merge after exact-head checks confirm both normal durable delivery and restart-drain claim deferral; retain the explicit generic root-retention/exit boundary rather than weakening admission globally.

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

Yes. Current-source tracing establishes the released-root path, and the PR supplies controlled live LINE before/after evidence; this review did not execute the contributor branch locally.

Is this the best way to solve the issue?

Yes. The fix uses existing admission primitives at the sole generic detached-delivery boundary, preserving real restart fences rather than relaxing them globally.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The reported regression can prevent inbound durable-channel messages from reaching an agent despite healthy channel probes.
  • add merge-risk: 🚨 message-delivery: The changed shared drain determines whether queued channel events enter delivery turns and how restart-time refusals preserve claims.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR provides controlled post-fix live LINE output showing delivered model responses and zero draining refusals; published logs should remain redacted.
  • 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 provides controlled post-fix live LINE output showing delivered model responses and zero draining refusals; published logs should remain redacted.

Label justifications:

  • P1: The reported regression can prevent inbound durable-channel messages from reaching an agent despite healthy channel probes.
  • merge-risk: 🚨 message-delivery: The changed shared drain determines whether queued channel events enter delivery turns and how restart-time refusals preserve claims.
  • 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 provides controlled post-fix live LINE output showing delivered model responses and zero draining refusals; published logs should remain redacted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides controlled post-fix live LINE output showing delivered model responses and zero draining refusals; published logs should remain redacted.

Evidence

What I checked:

Likely related people:

  • steipete: Introduced the shared monitor, restart-deferral behavior, and related admission design reflected in this repair. (role: shared ingress and admission-area contributor; confidence: high; commits: c163daa4ed02, 1958551ff924, 1bcc4c5e7063; files: src/channels/message/ingress-drain.ts, src/channels/message/ingress-monitor.ts, src/process/gateway-work-admission.ts)
  • Ayaan Zaidi: Authored the durable ingress engine where claimed deliveries are deliberately started without awaiting. (role: durable-ingress engine introducer; confidence: high; commits: fc6b9dad0b13; files: src/channels/message/ingress-drain.ts)
  • joshavant: Recent changes maintained recovery and cancellation behavior in the same ingress-drain owner. (role: recent durable-ingress contributor; confidence: medium; commits: 69983f80113a, 06600e2ca09f, 13750feff339; files: src/channels/message/ingress-drain.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for green required checks on the exact PR head.

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.

@Patrick-Erichsen Patrick-Erichsen self-assigned this Aug 20, 2026
@Patrick-Erichsen
Patrick-Erichsen merged commit c972fda into openclaw:main Aug 20, 2026
256 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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.

Beta blocker: line - every inbound message is refused with GatewayDrainingError on a gateway that never restarted

2 participants