Skip to content

2026.11.12: session permanently fails with AsyncWorkScopeClosedError after a scheduler job's work scope is drained #208686

Backlog

Description

@itsnimbus

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-claw context 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 with AsyncWorkScopeClosedError, from scope.track() once phase === "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 trackAsyncWork should 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.

Activity

  1. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    P1
    clawsweeper:needs-info
    clawsweeper:needs-maintainer-review
    clawsweeper:no-new-fix-pr
    impact:message-loss
    issue-rating: 🦐 gold shrimp
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-repro
    on Nov 30, 2026
  2. clawsweeper commented on Nov 30, 2026

    @clawsweeper
    Contributor

    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:

    • The retained callback or async resource connecting maintenance to later channel turns has not been identified.
    • The unnamed third-party channel and lossless-claw versions prevent separating core lifetime leakage from plugin-owned context retention.

    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:

    • Concrete official-release failure report: The reporter identifies OpenClaw 2026.11.12 on Linux and four failed turns over 75 minutes, with participant-recording rejection and aborted reply processing after scheduler scope drainage; restarting the Gateway restored service. The third-party channel and context engine remain relevant variables.
    • Scheduler owns a finite job lifetime: GatewayScheduler.run creates an AsyncWorkScope, executes the callback inside it, and drains it after asynchronous work settles. (src/infra/gateway-scheduler.ts:334, 413091a9667b)
    • Reported cancellation mechanism exists: Closed scopes reject track calls; beginClose aborts their signal; trackAsyncWork and getAsyncWorkSignal consume the ambient scope. This explains the reported errors if a later turn actually inherits that scope, but does not identify the inheriting resource. (src/shared/async-work-scope.ts:94, 413091a9667b)
    • Existing ingress isolation: Durable ingress explicitly runs dispatch outside its pump’s async work scope because dispatches and queued follow-ups outlive that scope; therefore scheduler drainage alone does not establish the missing upstream defect. (src/channels/message/ingress-drain.ts:488, 413091a9667b)
    • Existing lifetime regression contracts: The follow-up queue test checks that tracked work remains accepted after the triggering scope closes; the shared scope test separately requires late continuations to reject before invoking their producer. (src/auto-reply/reply/queue.drain-scope.test.ts:121, 413091a9667b)
    • Participant persistence catches failures: Participant recording catches trackAsyncWork rejection and reports it; silencing this warning would not repair the separately inherited aborted signal. (src/sessions/session-participant-recording.ts:56, 413091a9667b)
    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; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed November 29, 2026, 8:23 PM ET / November 30, 2026, 01:23 UTC.

  3. itsnimbus commented on Nov 30, 2026

    @itsnimbus
    Author

    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: trackAsyncWork rejects with AsyncWorkScopeClosedError in session-init, the subagent-registry handlers abort, and the stored abort reason is AsyncWorkScope.drain from GatewayScheduler.run. Another gateway restart cleared it again.

    What both affected sessions have in common:

    • Both agents run on the Codex app-server runtime (@openclaw/codex 2026.11.10, stdio transport). Agents on other runtimes were not affected.
    • In both cases the failure started within about one minute of the channel's upstream hub restarting. The channel plugin reconnected, and a turn was in flight or the session was busy at that moment. Several other hub restarts the same day broke nothing, so timing seems to matter.
    • In one case, the last successful turn before the failure spent about 147 s in the Codex app-server runtime-start stage.

    Reading the code:

    • The subagent-registry AbortError is a consequence, not the cause. runWithGatewayRootWorkContinuation finds no current root work and falls back to runWithGatewayIndependentRootWorkAdmission(..., getAsyncWorkSignal()), which passes in the signal of the already-closed scope.
    • So the failing turn's AsyncLocalStorage context already holds a drained scheduler-job scope. Our guess is that some long-lived per-session or per-agent object, such as a leased shared Codex app-server client or its event callbacks, is created inside a scheduler job (plugin service or maintenance) and keeps that job's context after the job drains.

    What did not reproduce it (11.12, embedded runtime, mock model):

    • a turn queued behind a busy session;
    • a channel-plugin reconnect in the middle of a turn, with a custody report on reconnect.

    We have not been able to test with the Codex runtime in isolation yet.

  4. daniel-lxs commented on Nov 30, 2026

    @daniel-lxs
    Member

    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?

  5. itsnimbus commented on Nov 30, 2026

    @itsnimbus
    Author

    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 (AsyncWorkScopeClosedError in session-init, subagent-registry AbortError with the reason AsyncWorkScope.drain from GatewayScheduler.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.

  6. daniel-lxs commented on Nov 30, 2026

    @daniel-lxs
    Member

    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?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clawsweeper:needs-infoclawsweeper:needs-maintainer-reviewclawsweeper:no-new-fix-primpact:message-lossissue-rating: 🦐 gold shrimp

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions