#Bug: Gateway crashes when background exec process emits output after agent turn ends

1 messages · Page 1 of 1 (latest)

sturdy plinth
#

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?

cerulean abyssBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

crisp geyserBOT
#

Yep — this is a known issue, and your repro is excellent.

Short answer to your main question: on current releases, there isn’t a first-class “detach this exec from agent listener” switch.
The good news: there’s already a fix on main:

  • Agents/exec fix: stops streaming tool_execution_update after an exec backgrounds, specifically to prevent stale-listener gateway crashes from delayed stdout/stderr (#61627).

Your first stack trace matches that fix almost exactly (Agent listener invoked outside active run).

For the second crash pattern (Invalid regular expression ... node_modules ... / stack overflow), there are also recent unreleased fixes in plugin/provider init paths (recursive snapshot/load and Windows loader path handling), so that one also looks like it’s in the same “already being fixed” bucket.


Could you paste the exact result of:

#
openclaw --version

(“latest npm” is helpful, but exact version tells whether you’re before/after those fixes when they ship.)


Practical workaround right now

If you need to avoid crashes before the release lands, use a truly detached child process so OpenClaw only tracks the short launcher command (not the long-running writer). On Windows, that means spawning with Start-Process (or start) and redirecting output to files.

Also relevant docs:

If you want, I can give you a copy-paste-safe Windows launcher command for your scraper shape.

sturdy plinth
# crisp geyser ```bash openclaw --version ``` (“latest npm” is helpful, but exact version tell...

OpenClaw 2026.4.5 (3e72c03)
Thanks for the confirmation — good to know both crashes are already in the fix pipeline.

Re workaround: we actually already landed on Start-Process + file redirect independently today (exactly what you described), and it worked perfectly — the scraper ran to completion without touching the gateway.

Looking forward to the release. Appreciate the fast response!

crisp geyserBOT
#

Awesome — perfect, and thanks for confirming version + workaround behavior.

Yep, 2026.4.5 is consistent with “pre-fix” for that background exec listener crash path, so your Start-Process detach is the right move until the next release lands.

Glad that helped! 🎉
If this fixed it, please right-click the solution message → Apps → ✅ Mark Solution.
This helps Answer Overflow index it for future users.