openclaw - 💡(How to fix) Fix [Bug]: Unhandled promise rejection "Agent listener invoked outside active run" with openai-codex/gpt-5.4 provider [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#62301Fetched 2026-04-08 03:06:24
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

When using openai-codex/gpt-5.4 as the primary model via Telegram channel, an unhandled promise rejection occurs intermittently during agent runs:

Error: Agent listener invoked outside active run

This causes:

  • Telegram messages to be garbled/broken mid-stream
  • Tool executions to abort halfway through
  • Orphaned user messages accumulating in the session

Error Message

[openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run
    at Agent.processEvents (file:///.../node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10)
    at file:///.../node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21
    at Object.onUpdate (file:///.../node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7)
    at emitUpdate (file:///.../dist/exec-defaults-uj0McX2k.js:1524:8)
    at handleStdout (file:///.../dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///.../dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///.../dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///.../dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:509:20)
    at addChunk (node:internal/streams/readable:564:12)

Root Cause

When using openai-codex/gpt-5.4 as the primary model via Telegram channel, an unhandled promise rejection occurs intermittently during agent runs:

Error: Agent listener invoked outside active run

This causes:

  • Telegram messages to be garbled/broken mid-stream
  • Tool executions to abort halfway through
  • Orphaned user messages accumulating in the session

Code Example

Error: Agent listener invoked outside active run

---

[openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run
    at Agent.processEvents (file:///.../node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10)
    at file:///.../node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21
    at Object.onUpdate (file:///.../node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7)
    at emitUpdate (file:///.../dist/exec-defaults-uj0McX2k.js:1524:8)
    at handleStdout (file:///.../dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///.../dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///.../dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///.../dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:509:20)
    at addChunk (node:internal/streams/readable:564:12)
RAW_BUFFERClick to expand / collapse

Description

When using openai-codex/gpt-5.4 as the primary model via Telegram channel, an unhandled promise rejection occurs intermittently during agent runs:

Error: Agent listener invoked outside active run

This causes:

  • Telegram messages to be garbled/broken mid-stream
  • Tool executions to abort halfway through
  • Orphaned user messages accumulating in the session

Stack trace

[openclaw] Unhandled promise rejection: Error: Agent listener invoked outside active run
    at Agent.processEvents (file:///.../node_modules/@mariozechner/pi-agent-core/src/agent.ts:533:10)
    at file:///.../node_modules/@mariozechner/pi-agent-core/src/agent.ts:380:21
    at Object.onUpdate (file:///.../node_modules/@mariozechner/pi-agent-core/src/agent-loop.ts:539:7)
    at emitUpdate (file:///.../dist/exec-defaults-uj0McX2k.js:1524:8)
    at handleStdout (file:///.../dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///.../dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///.../dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///.../dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:509:20)
    at addChunk (node:internal/streams/readable:564:12)

Steps to reproduce

  1. Configure openai-codex/gpt-5.4 as the primary model (ChatGPT Pro subscription, OAuth)
  2. Send messages via Telegram channel
  3. Request tool executions (e.g., running commands, file operations)
  4. Observe garbled responses and aborted tool executions

Environment

  • OpenClaw: 2026.4.5 (3e72c03)
  • Node: v25.9.0
  • OS: macOS (Darwin 25.4.0 arm64)
  • Channel: Telegram
  • Auth: openai-codex OAuth (ChatGPT Pro)

Notes

  • The error originates from @mariozechner/pi-agent-core, not OpenClaw itself
  • The issue does not occur with gemini/gemini-2.5-flash or ollama providers — only with openai-codex
  • Appears to be a race condition where stdout events arrive after the agent run has already ended

extent analysis

TL;DR

The most likely fix involves modifying the @mariozechner/pi-agent-core library to handle promise rejections and stdout events more robustly, potentially by implementing a mechanism to wait for all events to be processed before ending an agent run.

Guidance

  • Investigate the Agent.processEvents function in @mariozechner/pi-agent-core to understand how it handles events and promise rejections, and consider adding error handling or retries to mitigate the issue.
  • Review the agent-loop.ts file to see if there's a way to delay the end of an agent run until all pending events have been processed, which could help prevent the "Agent listener invoked outside active run" error.
  • Consider reaching out to the maintainers of @mariozechner/pi-agent-core to report the issue and ask for their assistance in resolving it, as the error originates from their library.
  • Test the system with other providers, like gemini/gemini-2.5-flash or ollama, to confirm that the issue is specific to openai-codex and to gather more information about the problem.

Example

No specific code example can be provided without modifying the @mariozechner/pi-agent-core library, but a potential solution might involve adding a check in the Agent.processEvents function to ensure that the agent run is still active before processing events.

Notes

The issue appears to be a race condition specific to the openai-codex provider, and resolving it may require changes to the @mariozechner/pi-agent-core library. The fact that the issue does not occur with other providers suggests that the problem is not with OpenClaw itself, but rather with the interaction between OpenClaw and the openai-codex provider.

Recommendation

Apply a workaround by implementing a retry mechanism or error handling in the Agent.processEvents function, as upgrading to a fixed version of @mariozechner/pi-agent-core is not currently an option. This workaround can help mitigate the issue until a permanent fix is available.

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