openclaw - 💡(How to fix) Fix [Bug]: Agent listener invoked outside active run causes Gateway crash [2 comments, 3 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#62342Fetched 2026-04-08 03:05:43
View on GitHub
Comments
2
Participants
3
Timeline
8
Reactions
0
Author
Timeline (top)
subscribed ×3commented ×2mentioned ×2labeled ×1

Gateway crashes with "Agent listener invoked outside active run" unhandled promise rejection from pi-agent-core

Error Message

Error Stack Trace:

14:18:37+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run at Agent.processEvents (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent.js:388:19) at file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent.js:259:120 at Object.onUpdate (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent-loop.js:336:47) at emitUpdate (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8) at handleStdout (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4) at Object.onSupervisorStdout [as onStdout] (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3) at file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21 at Socket.<anonymous> (file:///C:/Users/Grow%20up/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:559:12)

Config: gateway.mode=local, channels: openclaw-weixin/telegram/dingtalk, 1 daily cron job at 3 AM

Root Cause

Root cause: Race condition in pi-agent-core when session/task is ending and new event triggers concurrently (heartbeat, message, or internal callback). Agent listener invoked in "inactive run state" causes uncaught Promise rejection that crashes the entire Gateway.

Code Example

Error Stack Trace:


14:18:37+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run
 at Agent.processEvents (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent.js:388:19)
 at file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent.js:259:120
 at Object.onUpdate (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent-loop.js:336:47)
 at emitUpdate (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8)
 at handleStdout (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4)
 at Object.onSupervisorStdout [as onStdout] (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
 at file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21
 at Socket.<anonymous> (file:///C:/Users/Grow%20up/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:559:12)


Config: gateway.mode=local, channels: openclaw-weixin/telegram/dingtalk, 1 daily cron job at 3 AM
RAW_BUFFERClick to expand / collapse

Bug type

Crash (process/app exits or hangs)

Beta release blocker

No

Summary

Gateway crashes with "Agent listener invoked outside active run" unhandled promise rejection from pi-agent-core

Steps to reproduce

  1. Run OpenClaw 2026.4.5 on Windows 10 with gateway.mode=local
  2. Gateway runs normally with channels (openclaw-weixin, telegram, dingtalk)
  3. Wait for concurrent events (session ending + heartbeat/message trigger)
  4. Gateway crashes with unhandled promise rejection

Expected behavior

Gateway should handle events gracefully even outside active run, catch unhandled promise rejections, and continue running without crashing

Actual behavior

Gateway process terminates with unhandled promise rejection. Error: "Agent listener invoked outside active run" from @mariozechner/pi-agent-core/dist/agent.js:388. Requires manual restart.

OpenClaw version

2026.4.5

Operating system

Windows 10 (10.0.19045)

Install method

npm global install

Model

bailian/qwen3.5-plus

Provider / routing chain

bailian (Alibaba Cloud)

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Error Stack Trace:


14:18:37+08:00 [openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run
 at Agent.processEvents (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent.js:388:19)
 at file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent.js:259:120
 at Object.onUpdate (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/dist/agent-loop.js:336:47)
 at emitUpdate (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8)
 at handleStdout (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4)
 at Object.onSupervisorStdout [as onStdout] (file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
 at file:///C:/Users/Grow%20up/AppData/Roaming/npm/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21
 at Socket.<anonymous> (file:///C:/Users/Grow%20up/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:559:12)


Config: gateway.mode=local, channels: openclaw-weixin/telegram/dingtalk, 1 daily cron job at 3 AM

Impact and severity

Affected: All users on Windows 10/11 with version 2026.4.5 Severity: Critical (Gateway process terminates completely) Frequency: Multiple times per day (intermittent, appears random) Consequence: Requires manual restart, disrupts all active sessions and channels, 5+ minute wait for Gateway to become usable again

Additional information

Root cause: Race condition in pi-agent-core when session/task is ending and new event triggers concurrently (heartbeat, message, or internal callback). Agent listener invoked in "inactive run state" causes uncaught Promise rejection that crashes the entire Gateway.

Related component: @mariozechner/pi-agent-core/dist/agent.js:388

CC: @vincentkoc @mariozechner

extent analysis

TL;DR

The Gateway crash due to an unhandled promise rejection from pi-agent-core can be mitigated by addressing the race condition that occurs when a session/task is ending and a new event is triggered concurrently.

Guidance

  1. Review the pi-agent-core code: Examine the agent.js file, specifically line 388, to understand how the Agent listener invoked outside active run error is being thrown and consider implementing a try-catch block to handle this scenario.
  2. Implement concurrency control: Introduce mechanisms to manage concurrent events, such as using locks or semaphores, to prevent the race condition that leads to the crash.
  3. Enhance error handling: Improve the error handling in the Gateway to catch and handle unhandled promise rejections, preventing the process from terminating unexpectedly.
  4. Test with simulated concurrent events: Develop test cases that simulate the concurrent events (session ending + heartbeat/message trigger) to ensure the fixes are effective in preventing the crash.

Example

// Example of a try-catch block to handle the error
try {
  // Code that might throw "Agent listener invoked outside active run"
  Agent.processEvents();
} catch (error) {
  // Handle the error to prevent the process from crashing
  console.error('Error processing events:', error);
}

Notes

The provided information suggests a race condition in pi-agent-core as the root cause. However, without direct access to the codebase or more detailed logs, the suggestions are based on the information given and might need further refinement.

Recommendation

Apply a workaround by implementing a try-catch block to handle the Agent listener invoked outside active run error and enhancing the concurrency control and error handling mechanisms within the Gateway. This approach is chosen because it directly addresses the identified root cause and can be implemented without waiting for a potential fix in pi-agent-core.

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

Gateway should handle events gracefully even outside active run, catch unhandled promise rejections, and continue running without crashing

Still need to ship something?

×6

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

Back to top recommendations

TRENDING