Skip to content

fix(gateway): keep channel turns working after an account-scheduled reconnect - #208736

Merged
obviyus merged 1 commit into
mainfrom
bugloop-208686
Nov 30, 2026
Merged

obviyus merged 1 commit into
mainfrom
bugloop-208686

Conversation

@obviyus

@obviyus obviyus commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

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.

…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

clawsweeper Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Pull request received.

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Nov 30, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 30, 2026
@clawsweeper

clawsweeper Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

Run 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.

  • Before: The reported Gateway reproduction failed all three alpha turns with closed-scope and abort errors while beta continued replying.
  • After: The PR reports three successful replies from both alpha and beta after reconnect.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with a distinct integration regression; reported Gateway results lack an inspectable transport trace.
Proof confidence 🦐 gold shrimp (3/6) The body reports a built Gateway with two agents, a mock model, and a reconnecting qa-channel stand-in, with alpha changing from three failed turns to three replies; no raw after-fix transport trace is attached, and contributor proof is exempt.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

The scores reflect the reviewer's assessment. Real behavior proof is not required for maintainer- or bot-authored pull requests.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A transport reconnected by an account-scheduled callback can reject every later message until the Gateway restarts.
Reason: The narrow reconnect failure has a concrete source mechanism and regression, and the maintainer-authored direction preserves the documented account lifecycle contract without claiming to resolve the unconfirmed linked reports.

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: d271f29702d9b5affb9c93c81428748df01352ee

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Account-scheduled callback work scope changes intended behavior with a stated reason (7f0410c: Account scheduling was introduced to prevent timers and admitted callbacks from escaping retirement; the PR explains why long-lived transports must nevertheless avoid inheriting each callback’s temporary work scope.)
  • Independent channel-account lifetime keeps the original intent (4c60fa0: Channel startup was detached from maintenance scope ownership so later inbound messages remained runnable after host-wake recovery.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • scotthuang: Raw commit 4c60fa0 adds src/gateway/server-channels.work-scope.test.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4c60fa0cc332; files: src/gateway/server-channels.work-scope.test.ts)
  • Vincent Koc: Raw commit b61ab6d adds src/gateway/server-channel-account-lifetime.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b61ab6deb40c; files: src/gateway/server-channel-account-lifetime.ts)

PR surface

Source +3, Tests +39. Total +42 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 11 8 +3
Tests 1 39 0 +39
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 50 8 +42

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 29, 2026, 9:54 PM ET / November 30, 2026, 02:54 UTC.

@obviyus
obviyus merged commit e9aa48a into main Nov 30, 2026
134 checks passed
@obviyus
obviyus deleted the bugloop-208686 branch November 30, 2026 03:02
@obviyus

obviyus commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

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 AsyncWorkScopeClosedError after the job finishes. #208686 stays open until we know which plugin and trigger you hit.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…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]>
tideclaw-bot pushed a commit that referenced this pull request Dec 1, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant