OpenClaw version: latest npm
OS: Windows 10 x64 (Node.js v24.14.1)
What happens:
Gateway crashes (process exits, needs manual restart) when a background exec process continues writing to stderr/stdout after the agent's turn has completed.
Error in log:
Unhandled promise rejection: Error: Agent listener invoked outside active run
at Agent.processEvents (pi-agent-core/src/agent.ts:533:10)
at Object.onUpdate (agent-loop.ts:539:7)
at emitUpdate (exec-defaults-uj0McX2k.js:1524:8)
at Object.handleStderr [as onStderr] (exec-defaults-uj0McX2k.js:1553:4)
at Socket.<anonymous> (exec-defaults-uj0McX2k.js:573:4)
How to reproduce:
Start a long-running exec with background: true (e.g. a Node.js scraper running 5–10 minutes)
Agent turn ends (response delivered to user)
Background process continues writing output
Gateway crashes shortly after
Second crash pattern (same session, happens on gateway restart):
SyntaxError: Invalid regular expression: /node_modules/()//: Stack overflow
RangeError: Maximum call stack size exceeded
This one seems to happen in the Anthropic plugin loader on restart.
Impact: Gateway crashes ~5 times per day when doing heavy background work. Each crash requires manual restart (Scheduled Task re-runs it, but there's a 1–2 min gap).
Workaround attempted: Redirecting output to file (> out.log 2>&1) helps somewhat, but the agent still monitors the process and the crash can happen on any stderr output that arrives after turn completion.
Question: Is there a safe way to fully detach a background exec from the agent's listener once the turn ends? Or is this a known issue with a fix in progress?