openclaw - ✅(Solved) Fix [Bug]: Unhandled promise rejection: Error: Agent listener invoked outside active run [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#62256Fetched 2026-04-08 03:07:07
View on GitHub
Comments
2
Participants
2
Timeline
11
Reactions
1
Author
Timeline (top)
referenced ×5commented ×2cross-referenced ×2labeled ×2

10:37:21+08:00 [diagnostic] lane task done: lane=session:agent:personal:main durationMs=107330 active=0 queued=0 10:37:22+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run at Agent.processEvents (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10) at file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21 at Object.onUpdate (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7) at emitUpdate (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8) at handleStdout (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4) at Object.onSupervisorStdout [as onStdout] (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3) at file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21 at Socket.<anonymous> (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4) at Socket.emit (node:events:508:28) at addChunk (node:internal/streams/readable:563:12)

Error Message

10:37:22+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run

Root Cause

10:37:21+08:00 [diagnostic] lane task done: lane=session:agent:personal:main durationMs=107330 active=0 queued=0 10:37:22+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run at Agent.processEvents (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10) at file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21 at Object.onUpdate (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7) at emitUpdate (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8) at handleStdout (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4) at Object.onSupervisorStdout [as onStdout] (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3) at file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21 at Socket.<anonymous> (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4) at Socket.emit (node:events:508:28) at addChunk (node:internal/streams/readable:563:12)

Fix Action

Fixed

PR fix notes

PR #62265: fix(exec): catch onUpdate errors when agent run ends while exec still produces output

Description (problem / solution / changelog)

Fixes #62190 Fixes #62256

Problem

When an exec process outlives its parent agent run (e.g. due to tool-call abort, turn timeout, or late stdout delivery after the lane task completes), the onUpdate callback throws "Agent listener invoked outside active run" from pi-agent-core. This becomes an unhandled promise rejection that crashes the gateway.

Multiple users report this on both macOS and Windows with 2026.4.5. The stack trace is always:

Agent.processEvents (pi-agent-core/src/agent.ts:533)
  ← Object.onUpdate (pi-agent-core/src/agent-loop.ts:539)
  ← emitUpdate (bash-tools.exec-runtime)
  ← handleStdout
  ← Object.onSupervisorStdout
  ← Socket.<anonymous>

Root Cause

emitUpdate() guards on session.backgrounded || session.exited, which covers the common cases. However, there is a race where:

  1. The agent run completes (lane task done)
  2. The exec process is still running or its stdout pipe still has buffered data
  3. Late stdout arrives → handleStdoutemitUpdateopts.onUpdate()
  4. pi-agent-core throws because the agent run is no longer active

The session is not yet marked as exited (process still running) and not backgrounded (foreground mode), so the guard passes.

Fix

  1. try-catch on onUpdate: Wrap opts.onUpdate() in a try-catch so late-arriving stdout from a finished agent run does not become an unhandled rejection
  2. updateSuppressed flag: On first error, set a flag so subsequent stdout/stderr chunks skip onUpdate entirely instead of repeatedly throwing
  3. Debug logging: Log a [exec] onUpdate suppressed for session <id> debug message on the first suppression, including the original error message — visible in openclaw logs for troubleshooting without being noisy at info/warn level

The exec process itself continues to run and its output is still captured in the session buffer. Only the streaming updates to the (now-dead) agent run are suppressed.

Limitations and future work

  • The catch is broad (catches all errors, not just the expected "Agent listener invoked outside active run"). This is intentional as a defensive measure — any onUpdate failure should not crash the gateway. If more granular handling is needed, error type discrimination can be added later.
  • The root cause is a lifecycle mismatch between agent runs and exec processes. A cleaner long-term fix would be for pi-agent-core to expose a cancellation signal or detach hook so exec can proactively stop calling onUpdate when the run ends, rather than discovering it via a thrown error.

Test Plan

  • Added test: "does not crash when onUpdate throws (agent run ended while exec still producing output)"
  • Verifies exec completes normally, onUpdate was called at least twice, and the thrown error was silently caught
  • All existing bash-tools tests pass
  • Boundary invariant test updated for upstream setup-registry.runtime.ts allowlist drift

Changed files

  • src/agents/bash-tools.exec-runtime.ts (modified, +24/-13)
  • src/agents/bash-tools.test.ts (modified, +33/-0)
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

10:37:21+08:00 [diagnostic] lane task done: lane=session:agent:personal:main durationMs=107330 active=0 queued=0 10:37:22+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run at Agent.processEvents (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10) at file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21 at Object.onUpdate (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7) at emitUpdate (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8) at handleStdout (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4) at Object.onSupervisorStdout [as onStdout] (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3) at file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21 at Socket.<anonymous> (file:///C:/Users/stone/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4) at Socket.emit (node:events:508:28) at addChunk (node:internal/streams/readable:563:12)

Steps to reproduce

代理监听器在非活跃运行状态下被调用 —— 这是 openclaw 内部代码的逻辑错误,属于工具自身 bug。

Expected behavior

V20260405版本bug

Actual behavior

非常严重,经常出现,openclaw无法使用了

OpenClaw version

20264.5

Operating system

windows11

Install method

No response

Model

deepseekv3.2

Provider / routing chain

no

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The issue is likely caused by an internal logic error in OpenClaw, and a potential fix or workaround is to check the active run state before invoking the agent listener.

Guidance

  • Review the OpenClaw code, specifically the Agent.processEvents function in agent.ts, to understand the logic behind the error message "Agent listener invoked outside active run".
  • Verify that the active flag is properly set and checked before invoking the agent listener.
  • Check the OpenClaw version and consider upgrading to a newer version if available, as the issue is reported in version 20264.5.
  • Investigate the onUpdate function in agent-loop.ts to see if it's correctly handling the update event and if it's related to the error.

Example

No code snippet is provided as the issue is related to internal OpenClaw code and not a user-provided code.

Notes

The issue seems to be a regression bug that was introduced in a recent version of OpenClaw, and the exact cause is not clear without more information about the code changes. The error message suggests that the agent listener is being invoked outside of an active run, which could be due to a logic error in the OpenClaw code.

Recommendation

Apply workaround: Check the active run state before invoking the agent listener, as this is likely to be a temporary fix until the underlying issue is resolved in a future version of OpenClaw.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

V20260405版本bug

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING