openclaw - 💡(How to fix) Fix [Bug]: pi-agent-core Unhandled Promise Rejection in async callback timing [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#63151Fetched 2026-04-09 07:57:47
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

pi-agent-core (built-in subagent runtime) throws unhandled promise rejections when agent listener is invoked after the corresponding run has already ended.

Error Message

ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run {"0":"Agent listener invoked outside of active run, discarding.","_meta":{"logLevelId":5,"logLevelName":"ERROR"}}

Root Cause

pi-agent-core (built-in subagent runtime) throws unhandled promise rejections when agent listener is invoked after the corresponding run has already ended.

Code Example

ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run
{"0":"Agent listener invoked outside of active run, discarding.","_meta":{"logLevelId":5,"logLevelName":"ERROR"}}

---

[2026-04-08T01:02:XX] ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run
[2026-04-08T02:26:XX] ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run
{"0":"Agent listener invoked outside of active run, discarding.","_meta":{"logLevelId":5,"logLevelName":"ERROR"}}
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

pi-agent-core (built-in subagent runtime) throws unhandled promise rejections when agent listener is invoked after the corresponding run has already ended.

Steps to reproduce

  1. Run agents with subagent tasks using pi-agent-core runtime
  2. Observe logs periodically for UnhandledPromiseRejection errors

Expected behavior

Async callbacks should correctly handle cases where run has ended, and should not throw uncaught promise rejections.

Actual behavior

ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run
{"0":"Agent listener invoked outside of active run, discarding.","_meta":{"logLevelId":5,"logLevelName":"ERROR"}}

OpenClaw version

2026.4.5

Operating system

macOS (Gateway Local mode)

Install method

NOT_ENOUGH_INFO

Model

NOT_ENOUGH_INFO

Provider / routing chain

NOT_ENOUGH_INFO

Additional provider/model setup details

Gateway Local mode with Feishu WebSocket channel × 5 accounts

Logs, screenshots, and evidence

[2026-04-08T01:02:XX] ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run
[2026-04-08T02:26:XX] ERROR: UnhandledPromiseRejection: Agent listener invoked outside of active run
{"0":"Agent listener invoked outside of active run, discarding.","_meta":{"logLevelId":5,"logLevelName":"ERROR"}}

Impact and severity

Affected: All users running subagent tasks via pi-agent-core Severity: Medium (does not affect functionality as event is discarded, but indicates race conditions) Frequency: Sporadic (observed 2 times in one day) Consequence: Potential for more serious issues in other scenarios where event discarding is not safe

Additional information

This is a typical async timing bug — listener callback triggered after the corresponding run has already ended. Should add proper check for run state before invoking listener callbacks.

extent analysis

TL;DR

Add a check for the run state before invoking agent listener callbacks to prevent unhandled promise rejections.

Guidance

  • Identify the specific code paths where the agent listener is invoked and add a check to ensure the corresponding run is still active.
  • Review the async callback handling in pi-agent-core to ensure proper error handling and prevention of unhandled promise rejections.
  • Consider adding logging or monitoring to detect and track instances of agent listeners being invoked outside of active runs.
  • Investigate the root cause of the race condition that leads to the agent listener being invoked after the run has ended.

Example

if (isRunActive()) {
  invokeAgentListenerCallback();
} else {
  logWarning("Agent listener invoked outside of active run, discarding.");
}

Notes

The provided information suggests a typical async timing bug, and addressing this issue will require careful review and modification of the pi-agent-core code. The exact implementation details may vary depending on the specific requirements and constraints of the system.

Recommendation

Apply a workaround by adding a check for the run state before invoking agent listener callbacks, as this will help prevent unhandled promise rejections and provide a more robust error handling mechanism.

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

Async callbacks should correctly handle cases where run has ended, and should not throw uncaught promise rejections.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING