openclaw - 💡(How to fix) Fix openclaw cron run triggers gateway crash: "Agent listener invoked outside active run" unhandled promise rejection [1 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#62876Fetched 2026-04-09 08:01:22
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Error Message

  1. gateway 日志出现:Unhandled promise rejection: Error: Agent listener invoked outside active run if (!signal) throw new Error("Agent listener invoked outside active run")

Code Example

const signal = this.activeRun?.abortController.signal
  if (!signal) throw new Error("Agent listener invoked outside active run")
RAW_BUFFERClick to expand / collapse

问题描述

手动运行 openclaw cron run <job-id> 后,gateway 会抛出未处理的 promise rejection,导致主进程崩溃退出,systemd 随后 SIGKILL 掉残留的 openclaw-cron 进程。每次触发均复现,不是偶发。

复现步骤

  1. 运行 openclaw cron run <any-job-id>
  2. 命令挂住不返回
  3. gateway 日志出现:Unhandled promise rejection: Error: Agent listener invoked outside active run
  4. gateway 主进程退出
  5. systemd 在停机超时后将残留 openclaw-cron 进程 SIGKILL

已知复现时间点

  • 今天 09:35:28
  • 今天 09:57:57
  • 今天 10:57:04

每次均与 openclaw cron run 执行强相关。

根因分析

根据 gateway crash 堆栈:

  • Agent.processEvents() 抛出 Agent listener invoked outside active run
  • 调用链经过 exec-defaults-*.jshandleStderr -> emitUpdate -> onUpdate
  • pi-agent-core/dist/agent.js 中存在检查:
    const signal = this.activeRun?.abortController.signal
    if (!signal) throw new Error("Agent listener invoked outside active run")
  • 问题在于:cron run 触发后,异步 stderr/update 在 agent run 结束后仍继续被回调到 processEvents(),此时 activeRun 已被清空,直接命中 throw 导致 gateway 崩溃。

影响

  • 任何手动 cron run 调试均会导致 gateway 重启
  • 依赖 cron 调度的生产任务存在稳定性风险
  • 建议在修复前避免使用 cron run 调试

环境

  • OpenClaw 2026.4.5 (3e72c03)
  • Node.js v22.22.2
  • OS: Linux 6.8.0

extent analysis

TL;DR

To fix the issue, ensure that asynchronous stderr/update callbacks are properly cleaned up after the agent run ends, preventing processEvents() from being invoked outside an active run.

Guidance

  • Review the exec-defaults-*.js file to ensure that handleStderr and emitUpdate are properly handling the case when the agent run has ended.
  • Verify that the onUpdate callback is removed or properly cleaned up after the agent run completes to prevent further invocations of processEvents().
  • Investigate the pi-agent-core/dist/agent.js file to determine if the activeRun check can be modified to handle the case where asynchronous callbacks are still pending after the agent run has ended.
  • Consider implementing a timeout or cleanup mechanism to ensure that any pending callbacks are properly handled or removed after a certain period.

Example

// Example of how to remove the onUpdate callback after the agent run completes
const onUpdate = () => {
  // Handle update logic
};

// ...

// Remove the onUpdate callback after the agent run completes
agent.on('run:end', () => {
  agent.removeListener('update', onUpdate);
});

Notes

The provided code snippet is a hypothetical example and may not directly apply to the actual implementation. The root cause analysis suggests that the issue is related to asynchronous callbacks being invoked after the agent run has ended, but the exact solution will depend on the specific implementation details.

Recommendation

Apply a workaround to ensure that asynchronous callbacks are properly cleaned up after the agent run ends, such as implementing a timeout or cleanup mechanism, until a permanent fix can be implemented.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING