Repository navigation
Description
Summary
On 2026.11.12, one agent's channel session got permanently stuck after a scheduled gateway job closed the async work scope it ran in. From then on, every inbound turn on that session failed in about 2 seconds with AsyncWorkScopeClosedError. No reply was sent, and the user saw "request took too long". Other agents on the same gateway kept working. Only a gateway restart cleared it.
Version
- OpenClaw 2026.11.12 (npm global), Node 24.22, Linux
- One gateway process, 40+ agents, a third-party channel plugin,
lossless-clawcontext engine
What happens
The session ran normal turns for about an hour after a gateway start. Then a session-maintenance tick (scheduler:maintenance:tick) ran, with a session.maintenance.plan.read transaction on that agent's database. About 90 s later, every turn on the session failed like this:
[session-init] failed to record session participant error={"name":"AsyncWorkScopeClosedError","message":"Async work scope is closed",
"stack":"AsyncWorkScopeClosedError: Async work scope is closed
at AsyncWorkScope.track (dist/async-work-scope-*.mjs)
at trackAsyncWork (dist/async-work-scope-*.mjs)
at recordSessionParticipantBestEffort (dist/session-participant-recording-*.mjs)
at recordAcceptedSessionParticipantInput (dist/session-participant-input-recording-*.mjs)
at initSessionStateAttemptLocked (dist/get-reply-*.mjs)"}
[agents/subagent-registry] requester settlement handler failed err={"name":"AbortError","message":"This operation was aborted",
"stack":"AbortError: This operation was aborted
at AbortController.abort
at AsyncWorkScope.beginClose (dist/async-work-scope-*.mjs)
at AsyncWorkScope.drain (dist/async-work-scope-*.mjs)
at dist/gateway-scheduler-*.mjs"}
[agents/subagent-registry] lifecycle event handler failed err={"name":"AbortError", ... same stack ...}
Embedded agent failed before reply: This operation was aborted
[diagnostic] message processed: channel=<channel> ... outcome=error duration=~2000ms
This repeated for every turn on that session (4 of 4 over 75 minutes). The stored abort reason is the same each time: the signal reason captured when the scope was closed, at GatewayScheduler.run → AsyncWorkScope.drain.
Likely mechanism
GatewayScheduler.run() runs each job inside a new AsyncWorkScope, then calls drain() on it once the job settles, which closes it for good.
If a job lazily creates per-session state, or starts a long-lived async chain for a session, that chain inherits the job's scope through AsyncLocalStorage. After the drain, later turns that resume through that chain see a closed scope:
trackAsyncWork()rejects withAsyncWorkScopeClosedError, fromscope.track()oncephase === "closed";getAsyncWorkSignal()returns the already-aborted signal, so subagent-registry handlers abort straight away.
recordSessionParticipantBestEffort is meant to be best effort, but the turn still dies, because the same closed scope's aborted signal reaches the reply path.
Expected
Work started by a scheduled job should not leave session state bound to the job's scope after the job finishes. Possible fixes:
- per-session or long-lived state created inside a scheduler job should be detached with
runOutsideAsyncWorkScope; - or
trackAsyncWorkshould fall back to running untracked when the current scope is closed and the caller is outside the job's lifetime; - or turns admitted from a channel should enter the gateway's retained work scope rather than inheriting whatever scope was active when the session's chain was created.
Workaround
A drained gateway restart, which keeps the session's transcript and context. A session reset was not tried, because it would wipe context, and it may not clear state keyed by session key.
Not related
The same gateway shows no other agent with this error. A separate Lost Codex binding lease error on another agent is unrelated.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Nov 30, 2026
Codex review: this still needs some work.
Summary
Keep this issue open: it reports repeated reply failures on an official release with stacks matching core cancellation code, but the callback retaining the scheduler scope is still unidentified.
Reproducibility: No reproduction was run. Current source supports the reported closed-scope failure mechanism, but does not establish which retained resource carries a scheduler scope into later turns.
Next step
Identify the resource retaining the scheduler scope using sanitized ingress traces and exact plugin versions, then establish a failing regression in which a later inbound turn survives maintenance completion.
Review details
Best possible solution:
Give the identified long-lived producer its proper independent lifetime while preserving closed-scope rejection and legitimate cancellation.
Do we have a high-confidence way to reproduce the issue?
No reproduction was run. Current source supports the reported closed-scope failure mechanism, but does not establish which retained resource carries a scheduler scope into later turns.
Is this the best way to solve the issue?
Repair the producer or admission boundary once the retained resource is identified; allowing all work in closed scopes to run untracked would undermine an intentional, tested lifecycle contract.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning medium; reviewed against 413091a9667b.
Label changes
Label changes:
No label changes.
Label justifications:
P1: The reported channel workflow repeatedly fails before replying and remains unavailable until a Gateway restart.impact:message-loss: Four reported inbound turns produced errors instead of channel replies.Evidence reviewed
What I checked:
src/infra/gateway-scheduler.ts:334, 413091a9667b)src/shared/async-work-scope.ts:94, 413091a9667b)src/channels/message/ingress-drain.ts:488, 413091a9667b)src/auto-reply/reply/queue.drain-scope.test.ts:121, 413091a9667b)src/sessions/session-participant-recording.ts:56, 413091a9667b)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.Reviewed November 29, 2026, 8:23 PM ET / November 30, 2026, 01:23 UTC.
itsnimbus commentedon Nov 30, 2026
Follow-up with more data from the same gateway, still on 2026.11.12.
It recurs. After a gateway restart fixed the first session, a second agent's channel session hit the same failure about 45 minutes later. The signature was identical:
trackAsyncWorkrejects withAsyncWorkScopeClosedErrorin session-init, the subagent-registry handlers abort, and the stored abort reason isAsyncWorkScope.drainfromGatewayScheduler.run. Another gateway restart cleared it again.What both affected sessions have in common:
@openclaw/codex2026.11.10, stdio transport). Agents on other runtimes were not affected.runtime-startstage.Reading the code:
runWithGatewayRootWorkContinuationfinds no current root work and falls back torunWithGatewayIndependentRootWorkAdmission(..., getAsyncWorkSignal()), which passes in the signal of the already-closed scope.What did not reproduce it (11.12, embedded runtime, mock model):
We have not been able to test with the Codex runtime in isolation yet.
fix(gateway): keep channel turns working after an account-scheduled r…
daniel-lxs commentedon Nov 30, 2026
Thanks for the report. I couldn't reproduce this on main: the same channel session kept replying through several maintenance sweeps. Could you share which channel plugin you're using, the exact versions of it and lossless-claw, and the Gateway log from around when the session stopped replying?
itsnimbus commentedon Nov 30, 2026
Third occurrence, again on a Codex-runtime agent, again cleared by a gateway restart.
New detail: the session was idle when it broke. It answered a turn normally a few minutes after the upstream hub's last restart, then got no traffic for about 2 hours. The next inbound turn failed with the same signature (
AsyncWorkScopeClosedErrorin session-init, subagent-registry AbortError with the reasonAsyncWorkScope.drainfromGatewayScheduler.run). So the capture happens while the session is idle, presumably during some scheduled background job, not on the reconnect itself.As an experiment we've turned off the Codex session catalog (
plugins.entries.codex.config.sessionCatalog.enabled: false), since it is the default-on background service that leases shared app-server clients. I'll report whether the failure still recurs with it off.fix(gateway): keep channel turns working after an account-scheduled r…
daniel-lxs commentedon Nov 30, 2026
Thanks for the extra details. I couldn't reproduce this on main with the Codex runtime after a 2 hour idle (the first reply came back in under 2 s, no AsyncWorkScopeClosedError). Could you share which channel plugin you're on, your lossless-claw config, and the full AsyncWorkScopeClosedError stack from the Gateway log?
fix(gateway): keep channel turns working after an account-scheduled r…