Repository navigation
fix(channels): keep started ingress deliveries admissible after their inherited root releases - #126590
Conversation
… inherited root releases
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 3:55 AM ET / 07:55 UTC. ClawSweeper reviewWhat this changesThe PR keeps detached durable channel deliveries admissible after their originating gateway root has been released. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep 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 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherDurable 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +17, Tests +108. Total +125 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
… inherited root releases (openclaw#126590)
What Problem This Solves
Fixes #126441.
On
2026.8.1-beta.2and currentmain, every inbound LINE message is refused in 10-18 ms withGatewayDrainingError: Gateway is draining; new tasks are not acceptedon a gateway that was never asked to stop or restart. The gateway reports itself healthy the whole time —ready,channels status --probereturnsworks— 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 on2026.7.1-2is 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
drainOncestarts each claimed dispatch without awaiting it (runClaimed(claimed, laneKey)iningress-drain.ts), so the dispatch task outlives whatever admission context it inherits — the detached pump root (released whenrunPumpreturns, 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.tsbranchreturn current.released), sobeginSessionWorkAdmissionrefuses the turn as if the gateway were draining. Noadmission closedis 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:
retainGatewayRootWorkAdmissionContinuation()holds it until the task settles, so a real restart drain keeps waiting for in-flight deliveries;runOutsideGatewayRootWorkAdmission, so the dead lease cannot poison it, while a real restart drain still refuses it at admission and the existingGatewayDrainingErrordisposition 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 (
fc6b9dad0b1starts dispatches without awaiting them) and reached all channels with the shared monitor (c163daa4ed0, #111249, whosewaitForDeliveryIdleBeforeRepump: falseproduction default releases the pump root while deliveries run);2026.7.1-2predates 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
runWithGatewayIndependentRootWorkContinuationadds microtask hops after dispatch resolution, which letsdispose()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:
2026.7.1-2+@openclaw/[email protected][model-fetch] response ... status=200 elapsedMs=2014); 0drainingerrors2026.8.1-beta.2+@openclaw/[email protected](version-matched)drainingerrorsmainat0f1670d8951(source run)drainingerrorsFailing shape (identical on both bad versions, first attempt and every durable retry):
Zero
admission closed/admission reopenedlines 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
drainingerrors — and the turn ran to a model response: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— norunPumpTask, 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) andreleases 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:coreandtsgo:test:srcclean;oxlintclean;oxfmt --checkclean.