openclaw - 💡(How to fix) Fix Unhandled promise rejection: Agent listener invoked outside active run [1 comments, 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#62341Fetched 2026-04-08 03:05:44
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
closed ×1commented ×1

OpenClaw intermittently throws an unhandled promise rejection from the embedded agent event pipeline:

Error: Agent listener invoked outside active run

The stack points into OpenClaw internals, specifically @mariozechner/pi-agent-core plus the OpenClaw exec/supervisor update bridge. This does not appear to be caused by a bad workspace prompt or invalid cron content.

Error Message

Unhandled promise rejection: Error: Agent listener invoked outside active run at Agent.processEvents (file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10) at file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21 at Object.onUpdate (file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7) at emitUpdate (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8) at handleStdout (or handleStderr) at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)

Root Cause

The stack points into OpenClaw internals, specifically @mariozechner/pi-agent-core plus the OpenClaw exec/supervisor update bridge. This does not appear to be caused by a bad workspace prompt or invalid cron content.

Code Example

Unhandled promise rejection: Error: Agent listener invoked outside active run
    at Agent.processEvents (file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10)
    at file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21
    at Object.onUpdate (file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7)
    at emitUpdate (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8)
    at handleStdout (or handleStderr)
    at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
RAW_BUFFERClick to expand / collapse

OpenClaw bug report draft

Title

Unhandled promise rejection: Agent listener invoked outside active run

Summary

OpenClaw intermittently throws an unhandled promise rejection from the embedded agent event pipeline:

Error: Agent listener invoked outside active run

The stack points into OpenClaw internals, specifically @mariozechner/pi-agent-core plus the OpenClaw exec/supervisor update bridge. This does not appear to be caused by a bad workspace prompt or invalid cron content.

Environment

  • OpenClaw app: 2026.4.5
  • Update available at time of report: 2026.4.20
  • OS: macOS 26.2 arm64
  • Node: 25.8.0
  • Gateway mode: local loopback
  • Gateway service: LaunchAgent, running

Error text

Unhandled promise rejection: Error: Agent listener invoked outside active run
    at Agent.processEvents (file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10)
    at file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21
    at Object.onUpdate (file:///opt/homebrew/lib/node_modules/openclaw/node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7)
    at emitUpdate (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1524:8)
    at handleStdout (or handleStderr)
    at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)

Observed occurrences

1) 2026-04-19 15:27:33 America/Los_Angeles

Source: /tmp/openclaw/openclaw-2026-04-19.log line 67

2) 2026-04-19 16:11:16 America/Los_Angeles

Source: /tmp/openclaw/openclaw-2026-04-19.log line 157

3) 2026-04-19 16:17:57 America/Los_Angeles

Source: /tmp/openclaw/openclaw-2026-04-19.log line 206

  • this variant came through handleStderr

4) 2026-04-20 11:19:29 America/Los_Angeles

Source: /tmp/openclaw/openclaw-2026-04-19.log line 1473

5) 2026-04-20 11:29:40 America/Los_Angeles

Source: /tmp/openclaw/openclaw-2026-04-20.log line 124

Trigger pattern / suspicion

This looks like a race in the embedded agent event stream when supervisor stdout/stderr updates arrive after the active run has already ended or transitioned.

Evidence:

  • stack always routes through pi-agent-core Agent.processEvents and agent-loop.ts:onUpdate
  • updates are coming from OpenClaw exec/supervisor bridge (emitUpdate, handleStdout or handleStderr, onSupervisorStdout)
  • at least one occurrence happened near cron queue/manual-run churn:
    • manual:2f3e1274-8ddd-473b-9310-221293426dbc:1776709039050:2 was queued waiting for an execution slot
  • another occurrence happened seconds after cron: job removed
  • this suggests late supervisor output is still being delivered to a listener after run teardown/removal

User-visible impact

  • noisy unhandled promise rejection in logs
  • makes foundation health look worse than it is
  • unclear whether some agent completion updates could be dropped or mishandled in edge cases
  • no clear evidence yet of user-facing data corruption, but it weakens trust in runtime stability

What was ruled out locally

These were fixed separately and do not explain this error:

  • missing Telegram targets in cron prompts
  • wrong STRATEGY.md path in marketing jobs
  • disallowed model overrides on some crons
  • missing memory/epiphanies.md
  • missing same-day daily memory file assumptions

After those fixes, this runtime error still stands out as an internal OpenClaw issue.

Likely reproduction directions

Potential reproduction path:

  1. Have multiple cron-driven isolated agent runs active or queued.
  2. Force one manual cron run while another is waiting for an execution slot.
  3. Remove or finish a related cron/run while supervisor stdout/stderr is still streaming.
  4. Observe whether late stdout/stderr update reaches Agent.processEvents after active-run teardown.

A second likely reproduction path:

  1. Start an embedded agent run that streams tool/process output.
  2. End, replace, or restart the run quickly.
  3. Let delayed stdout/stderr continue arriving from the supervisor socket.
  4. Observe the same exception.

Suggested fix area

Guard the embedded agent update listener so post-teardown supervisor output is ignored or detached cleanly instead of throwing.

Places implicated by stack:

  • @mariozechner/pi-agent-core/src/agent.ts
  • @mariozechner/pi-agent-core/src/agent-loop.ts
  • OpenClaw dist/exec-defaults-*.js supervisor output bridge

Attachments / evidence paths

  • /tmp/openclaw/openclaw-2026-04-19.log
  • /tmp/openclaw/openclaw-2026-04-20.log

Local operator note

This bug report was prepared after a cron and messaging reliability cleanup pass. Remaining runtime issue appears platform-side rather than workspace-side.

extent analysis

TL;DR

Investigate and address the synchronization of agent state during WebSocket reconnects to prevent the Agent listener invoked outside active run error.

Guidance

  • Review the pi-agent-core library to understand how agent listeners are managed and identify potential issues with the current implementation.
  • Implement guard checks before invoking agent listeners to ensure they are only called within an active run context.
  • Investigate the handleStdoutemitUpdateAgent.processEvents chain to identify potential race conditions and optimize the code to prevent them.
  • Consider adding proper cleanup of agent state when runs are interrupted to prevent inconsistent state.

Example

No specific code example can be provided without modifying the pi-agent-core library, but a potential solution could involve adding a check before invoking the agent listener:

if (agent.isActive()) {
  agent.processEvents();
} else {
  // Handle the case where the agent is not active
}

Notes

The provided analysis suggests that the issue is related to the agent lifecycle management during WebSocket reconnects and potential race conditions. However, without further investigation and modification of the pi-agent-core library, it is difficult to provide a definitive solution.

Recommendation

Apply a workaround by implementing guard checks and proper cleanup of agent state, as this is a more feasible solution than upgrading to a fixed version, which is not available. This approach can help mitigate the issue until a more permanent solution is found.

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