Repository navigation
fix(gateway): keep channel turns working after an account-scheduled reconnect - #208736
Conversation
…econnect Account-scheduled plugin callbacks ran inside the scheduler job's async work scope. A transport reconnected from such a job kept that scope after the job settled and closed it, so every later inbound turn failed with AsyncWorkScopeClosedError and an aborted signal until restart. Run them outside the job's work scope, like the account task itself.
|
🦞👀 ClawSweeper review completeClawSweeper finished reviewing this revision. |
|
Codex review: passed. What this changesRun channel-account scheduled callbacks outside the scheduler job’s temporary work scope so reconnected transports can process later messages. Example: Account alpha reconnects its transport from ctx.scheduler, then receives three messages after the reconnect job finishes.
Review scores
The scores reflect the reviewer's assessment. Real behavior proof is not required for maintainer- or bot-authored pull requests. ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR repairs a current account-scheduler lifetime leak with a focused change and a distinct regression test; no actionable correctness or security defect was identified. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway channel manager supplies each account’s scheduler; scheduled callbacks create plugin transports, while account cancellation and teardown retain responsibility for stopping them. flowchart TD
A[Channel account manager] --> B[Account scheduler]
B --> C[Gateway scheduled job]
C --> D[Callback outside temporary work scope]
D --> E[Reconnected transport]
E --> F[Later inbound turns]
Technical reviewBest possible solution: Detach account-scheduled callback execution at the existing account-lifetime owner while preserving returned-work joins, cancellation, and plugin transport cleanup. Do we have a high-confidence way to reproduce the issue? Source inspection establishes the account-scheduler scope leak, and the body reports a failing-base/passing-head Gateway experiment and regression; this read-only review ran no target code. Is this the best way to solve the issue? The change repairs scope inheritance at its existing producer without weakening closed-scope rejection or changing service schedulers, making it a small, coherent fix for the demonstrated reconnect path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6442e281211b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +3, Tests +39. Total +42 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall readiness starts with the lower of the proof and patch scores. It is capped at 3/6 if the fix is partial, the change offers little benefit, a product decision is still open, or the PR reverses an earlier decision without saying why. ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 29, 2026, 9:54 PM ET / November 30, 2026, 02:54 UTC. |
|
Landed in e9aa48a. Thanks @itsnimbus for the detailed report. Work a channel plugin starts from a job on its account scheduler (for example rebuilding its transport after a drop) no longer keeps that job's work scope, so turns on the reconnected channel stop failing with |
…econnect (openclaw#208736) Root cause: src/gateway/server-channel-account-lifetime.ts:116 runs a channel account's scheduled callbacks (`ctx.scheduler`) inside the job's own async work scope (`GatewayScheduler.run`, src/infra/gateway-scheduler.ts:366, 359 on 2026.11.12), and the scheduler closes that scope when the callback settles. A transport the plugin reconnects from such a job keeps the closed scope, so every later inbound turn on it fails with `AsyncWorkScopeClosedError` and an aborted signal until the Gateway restarts. Candidate fix for openclaw#208686 (not closing it yet). Thanks @itsnimbus for the detailed report and logs. This PR fixes the reconnect path below, which reproduces the reported failure signature exactly. It does not yet confirm that this is the path the reporter hit. @itsnimbus: which channel plugin and version are you running, and do your logs show that plugin reconnecting its transport shortly before the first failure? openclaw#208447 (same reporter, same `AsyncWorkScopeClosedError` at session init on a channel turn) may be the same cause. Unconfirmed. ## What changes Account-scheduled callbacks now run outside the scheduler job's work scope. The account task itself already runs that way (`runChannelAccountStartup`, openclaw#163268), and the job still waits for the promise the callback returns. The plugin docs describe this pattern: plugins own their reconnection and sockets and use the account scheduler for timed work, and the bundled imap and mcp-relay plugins do the same. Plugin service schedulers are unchanged, because their tests require them to wait for tracked child work. Unverified: the report ties the failure to a maintenance tick and a `session.maintenance.plan.read`. I haven't reproduced that trigger. A scope-leak probe on a built Gateway with two agents across ordinary 30 s maintenance ticks found no turn running in a closed scheduler scope, but that run didn't include a session-maintenance plan pass. ## Evidence The setup is a built Gateway, a local mock model, and two agents. Each agent has its own account and transport on a third-party channel stand-in: the repo's qa-channel, changed only to reconnect from `ctx.scheduler` after its transport drops. The test drops alpha's transport and lets the plugin reconnect from its scheduled job. - main cd159a2: alpha failed 3/3 later turns ("The request took too long"). Each logged the reported set: `failed to record session participant AsyncWorkScopeClosedError`, `requester settlement handler failed AbortError`, `Embedded agent failed before reply: This operation was aborted`. Beta replied 3/3. - This PR: alpha and beta replied 3/3 after the reconnect, with no failure lines. Regression: `server-channels.work-scope.test.ts`, "keeps channel work from an account-scheduled reconnect alive after its job settles". It fails on main with `AsyncWorkScopeClosedError` and passes here. ## Follow-ups (not changed here) - The native approval-handler bootstrap retry (`src/infra/approval-handler-bootstrap.ts`) and the mcp-relay service connect job also create long-lived connections inside scheduler jobs. This is the same class of bug, on paths not reported yet. - The prompt-cache keep-warm pass, started by cron maintenance, keeps running after its maintenance job's scope closes, so it reads an aborted work signal. Co-authored-by: Ayaan Zaidi <[email protected]>
…econnect (#208736) Root cause: src/gateway/server-channel-account-lifetime.ts:116 runs a channel account's scheduled callbacks (`ctx.scheduler`) inside the job's own async work scope (`GatewayScheduler.run`, src/infra/gateway-scheduler.ts:366, 359 on 2026.11.12), and the scheduler closes that scope when the callback settles. A transport the plugin reconnects from such a job keeps the closed scope, so every later inbound turn on it fails with `AsyncWorkScopeClosedError` and an aborted signal until the Gateway restarts. Candidate fix for #208686 (not closing it yet). Thanks @itsnimbus for the detailed report and logs. This PR fixes the reconnect path below, which reproduces the reported failure signature exactly. It does not yet confirm that this is the path the reporter hit. @itsnimbus: which channel plugin and version are you running, and do your logs show that plugin reconnecting its transport shortly before the first failure? #208447 (same reporter, same `AsyncWorkScopeClosedError` at session init on a channel turn) may be the same cause. Unconfirmed. ## What changes Account-scheduled callbacks now run outside the scheduler job's work scope. The account task itself already runs that way (`runChannelAccountStartup`, #163268), and the job still waits for the promise the callback returns. The plugin docs describe this pattern: plugins own their reconnection and sockets and use the account scheduler for timed work, and the bundled imap and mcp-relay plugins do the same. Plugin service schedulers are unchanged, because their tests require them to wait for tracked child work. Unverified: the report ties the failure to a maintenance tick and a `session.maintenance.plan.read`. I haven't reproduced that trigger. A scope-leak probe on a built Gateway with two agents across ordinary 30 s maintenance ticks found no turn running in a closed scheduler scope, but that run didn't include a session-maintenance plan pass. ## Evidence The setup is a built Gateway, a local mock model, and two agents. Each agent has its own account and transport on a third-party channel stand-in: the repo's qa-channel, changed only to reconnect from `ctx.scheduler` after its transport drops. The test drops alpha's transport and lets the plugin reconnect from its scheduled job. - main 6c21817: alpha failed 3/3 later turns ("The request took too long"). Each logged the reported set: `failed to record session participant AsyncWorkScopeClosedError`, `requester settlement handler failed AbortError`, `Embedded agent failed before reply: This operation was aborted`. Beta replied 3/3. - This PR: alpha and beta replied 3/3 after the reconnect, with no failure lines. Regression: `server-channels.work-scope.test.ts`, "keeps channel work from an account-scheduled reconnect alive after its job settles". It fails on main with `AsyncWorkScopeClosedError` and passes here. ## Follow-ups (not changed here) - The native approval-handler bootstrap retry (`src/infra/approval-handler-bootstrap.ts`) and the mcp-relay service connect job also create long-lived connections inside scheduler jobs. This is the same class of bug, on paths not reported yet. - The prompt-cache keep-warm pass, started by cron maintenance, keeps running after its maintenance job's scope closes, so it reads an aborted work signal. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit e9aa48a) Co-authored-by: RomneyDa <[email protected]>
Root cause: src/gateway/server-channel-account-lifetime.ts:116 runs a channel account's scheduled callbacks (
ctx.scheduler) inside the job's own async work scope (GatewayScheduler.run, src/infra/gateway-scheduler.ts:366, 359 on 2026.11.12), and the scheduler closes that scope when the callback settles. A transport the plugin reconnects from such a job keeps the closed scope, so every later inbound turn on it fails withAsyncWorkScopeClosedErrorand an aborted signal until the Gateway restarts.Candidate fix for #208686 (not closing it yet). Thanks @itsnimbus for the detailed report and logs. This PR fixes the reconnect path below, which reproduces the reported failure signature exactly. It does not yet confirm that this is the path the reporter hit. @itsnimbus: which channel plugin and version are you running, and do your logs show that plugin reconnecting its transport shortly before the first failure?
#208447 (same reporter, same
AsyncWorkScopeClosedErrorat session init on a channel turn) may be the same cause. Unconfirmed.What changes
Account-scheduled callbacks now run outside the scheduler job's work scope. The account task itself already runs that way (
runChannelAccountStartup, #163268), and the job still waits for the promise the callback returns. The plugin docs describe this pattern: plugins own their reconnection and sockets and use the account scheduler for timed work, and the bundled imap and mcp-relay plugins do the same. Plugin service schedulers are unchanged, because their tests require them to wait for tracked child work.Unverified: the report ties the failure to a maintenance tick and a
session.maintenance.plan.read. I haven't reproduced that trigger. A scope-leak probe on a built Gateway with two agents across ordinary 30 s maintenance ticks found no turn running in a closed scheduler scope, but that run didn't include a session-maintenance plan pass.Evidence
The setup is a built Gateway, a local mock model, and two agents. Each agent has its own account and transport on a third-party channel stand-in: the repo's qa-channel, changed only to reconnect from
ctx.schedulerafter its transport drops. The test drops alpha's transport and lets the plugin reconnect from its scheduled job.failed to record session participant AsyncWorkScopeClosedError,requester settlement handler failed AbortError,Embedded agent failed before reply: This operation was aborted. Beta replied 3/3.Regression:
server-channels.work-scope.test.ts, "keeps channel work from an account-scheduled reconnect alive after its job settles". It fails on main withAsyncWorkScopeClosedErrorand passes here.Follow-ups (not changed here)
src/infra/approval-handler-bootstrap.ts) and the mcp-relay service connect job also create long-lived connections inside scheduler jobs. This is the same class of bug, on paths not reported yet.