Bug
Gateway crashes with an unhandled promise rejection when a background exec process emits output after the agent run that spawned it has already completed.
Error
Unhandled promise rejection: Error: Agent listener invoked outside active run
at Agent.processEvents (pi-agent-core/src/agent.ts:533:10)
at pi-agent-core/src/agent.ts:380:21
at Object.onUpdate (pi-agent-core/src/agent-loop.ts:539:7)
at emitUpdate (exec-defaults-BjdtpCtu.js:1524:8)
at handleStdout (exec-defaults-BjdtpCtu.js:1546:4)
at Object.onSupervisorStdout (exec-defaults-BjdtpCtu.js:1610:3)
Reproduction
- Agent run starts a long-running background exec (e.g.
curl ... | sudo sh to install software)
- Agent run completes and replies to user
- Background process continues emitting stdout (download progress)
- Stdout handler calls
emitUpdate → Agent.processEvents → throws because no active run
Expected behavior
Background exec output after the spawning run completes should either be silently buffered or ignored, not crash the gateway.
Impact
Gateway process exits, requiring manual restart. Any ongoing conversations and cron jobs are interrupted.
Environment
- OpenClaw 2026.4.5, running from source on Linux
- Triggered by
exec tool with background: true and timeout: 300
- Crash timestamp: 2026-04-06T09:10:54+08:00
Bug
Gateway crashes with an unhandled promise rejection when a background exec process emits output after the agent run that spawned it has already completed.
Error
Reproduction
curl ... | sudo shto install software)emitUpdate→Agent.processEvents→ throws because no active runExpected behavior
Background exec output after the spawning run completes should either be silently buffered or ignored, not crash the gateway.
Impact
Gateway process exits, requiring manual restart. Any ongoing conversations and cron jobs are interrupted.
Environment
exectool withbackground: trueandtimeout: 300