openclaw - ✅(Solved) Fix [Bug]: Gateway restarts due to Unhandled promise rejection [1 pull requests, 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#62190Fetched 2026-04-08 03:07:51
View on GitHub
Comments
0
Participants
1
Timeline
8
Reactions
0
Author
Participants
Timeline (top)
referenced ×5labeled ×2cross-referenced ×1

I'm on 2026.4.5. I commonly tail the openclaw logs via openclaw logs --follow and noticed my logs were dropping out due to the gateway disconnecting. I'm seeing this stack trace in the logs what the gateway recycles. That's it. No AI slop in the description, thought I just raise to y'all's attention.

23:22:42+00:00 debug cron {"module":"cron","storePath":"/Users/mitchellcomardo/.openclaw/cron/jobs.json"} {"nextAt":1775518051092,"delayMs":60000,"clamped":true} cron: timer armed
23:22:56+00:00 error [openclaw] 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 (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:508:20)
    at addChunk (node:internal/streams/readable:564:12)

Error Message

23:22:42+00:00 debug cron {"module":"cron","storePath":"/Users/mitchellcomardo/.openclaw/cron/jobs.json"} {"nextAt":1775518051092,"delayMs":60000,"clamped":true} cron: timer armed 23:22:56+00:00 error [openclaw] 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 (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4) at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3) at file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21 at Socket.<anonymous> (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4) at Socket.emit (node:events:508:20) at addChunk (node:internal/streams/readable:564:12)

Root Cause

I'm on 2026.4.5. I commonly tail the openclaw logs via openclaw logs --follow and noticed my logs were dropping out due to the gateway disconnecting. I'm seeing this stack trace in the logs what the gateway recycles. That's it. No AI slop in the description, thought I just raise to y'all's attention.

23:22:42+00:00 debug cron {"module":"cron","storePath":"/Users/mitchellcomardo/.openclaw/cron/jobs.json"} {"nextAt":1775518051092,"delayMs":60000,"clamped":true} cron: timer armed
23:22:56+00:00 error [openclaw] 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 (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:508:20)
    at addChunk (node:internal/streams/readable:564:12)

Fix Action

Fixed

PR fix notes

PR #62265: fix(exec): catch onUpdate errors when agent run ends while exec still produces output

Description (problem / solution / changelog)

Fixes #62190 Fixes #62256

Problem

When an exec process outlives its parent agent run (e.g. due to tool-call abort, turn timeout, or late stdout delivery after the lane task completes), the onUpdate callback throws "Agent listener invoked outside active run" from pi-agent-core. This becomes an unhandled promise rejection that crashes the gateway.

Multiple users report this on both macOS and Windows with 2026.4.5. The stack trace is always:

Agent.processEvents (pi-agent-core/src/agent.ts:533)
  ← Object.onUpdate (pi-agent-core/src/agent-loop.ts:539)
  ← emitUpdate (bash-tools.exec-runtime)
  ← handleStdout
  ← Object.onSupervisorStdout
  ← Socket.<anonymous>

Root Cause

emitUpdate() guards on session.backgrounded || session.exited, which covers the common cases. However, there is a race where:

  1. The agent run completes (lane task done)
  2. The exec process is still running or its stdout pipe still has buffered data
  3. Late stdout arrives → handleStdoutemitUpdateopts.onUpdate()
  4. pi-agent-core throws because the agent run is no longer active

The session is not yet marked as exited (process still running) and not backgrounded (foreground mode), so the guard passes.

Fix

  1. try-catch on onUpdate: Wrap opts.onUpdate() in a try-catch so late-arriving stdout from a finished agent run does not become an unhandled rejection
  2. updateSuppressed flag: On first error, set a flag so subsequent stdout/stderr chunks skip onUpdate entirely instead of repeatedly throwing
  3. Debug logging: Log a [exec] onUpdate suppressed for session <id> debug message on the first suppression, including the original error message — visible in openclaw logs for troubleshooting without being noisy at info/warn level

The exec process itself continues to run and its output is still captured in the session buffer. Only the streaming updates to the (now-dead) agent run are suppressed.

Limitations and future work

  • The catch is broad (catches all errors, not just the expected "Agent listener invoked outside active run"). This is intentional as a defensive measure — any onUpdate failure should not crash the gateway. If more granular handling is needed, error type discrimination can be added later.
  • The root cause is a lifecycle mismatch between agent runs and exec processes. A cleaner long-term fix would be for pi-agent-core to expose a cancellation signal or detach hook so exec can proactively stop calling onUpdate when the run ends, rather than discovering it via a thrown error.

Test Plan

  • Added test: "does not crash when onUpdate throws (agent run ended while exec still producing output)"
  • Verifies exec completes normally, onUpdate was called at least twice, and the thrown error was silently caught
  • All existing bash-tools tests pass
  • Boundary invariant test updated for upstream setup-registry.runtime.ts allowlist drift

Changed files

  • src/agents/bash-tools.exec-runtime.ts (modified, +24/-13)
  • src/agents/bash-tools.test.ts (modified, +33/-0)

Code Example

23:22:42+00:00 debug cron {"module":"cron","storePath":"/Users/mitchellcomardo/.openclaw/cron/jobs.json"} {"nextAt":1775518051092,"delayMs":60000,"clamped":true} cron: timer armed
23:22:56+00:00 error [openclaw] 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 (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:508:20)
    at addChunk (node:internal/streams/readable:564:12)

---
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

I'm on 2026.4.5. I commonly tail the openclaw logs via openclaw logs --follow and noticed my logs were dropping out due to the gateway disconnecting. I'm seeing this stack trace in the logs what the gateway recycles. That's it. No AI slop in the description, thought I just raise to y'all's attention.

23:22:42+00:00 debug cron {"module":"cron","storePath":"/Users/mitchellcomardo/.openclaw/cron/jobs.json"} {"nextAt":1775518051092,"delayMs":60000,"clamped":true} cron: timer armed
23:22:56+00:00 error [openclaw] 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 (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1546:4)
    at Object.onSupervisorStdout [as onStdout] (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1610:3)
    at file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:1007:21
    at Socket.<anonymous> (file:///opt/homebrew/lib/node_modules/openclaw/dist/exec-defaults-uj0McX2k.js:568:4)
    at Socket.emit (node:events:508:20)
    at addChunk (node:internal/streams/readable:564:12)

Steps to reproduce

  1. Start Openclaw
  2. openclaw logs --follow

Occasionally just drops out. I'm not actively working with the agent though there could be some background crons running.

Expected behavior

Gateway doesn't randomly restart.

Actual behavior

Gateway randomly restarts.

OpenClaw version

2026.4.5

Operating system

macOS Tahoe 26.3.1

Install method

npm global

Model

openai-codex gpt5.4

Provider / routing chain

openclaw -> openai subscription

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The issue might be related to an unhandled promise rejection in the openclaw agent, causing the gateway to disconnect and restart.

Guidance

  • Investigate the Agent.processEvents function in @mariozechner/pi-agent-core to understand why the agent listener is being invoked outside an active run.
  • Check the cron jobs configuration in openclaw to see if there are any issues with the scheduling or execution of background tasks.
  • Verify if the openclaw logs --follow command is properly handling disconnections and reconnects to the gateway.
  • Consider updating to a newer version of openclaw if available, as the current version (2026.4.5) may have known issues.

Notes

The provided stack trace suggests an issue with the openclaw agent, but without more information about the cron jobs or the gateway configuration, it's difficult to provide a more specific solution.

Recommendation

Apply workaround: Implement a script to automatically restart the openclaw logs --follow command when the gateway disconnects, to minimize the impact of the issue until a more 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…

FAQ

Expected behavior

Gateway doesn't randomly restart.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING