Two-layer runtime defense that protects the Openclaw gateway against hallucinating LLM streams and host resource exhaustion.
Activate this skill once per fresh gateway deployment or whenever the
gateway binary ( openclaw.mjs) is rebuilt / updated.
Patches global.fetch to intercept every LLM streaming response
( text/event-stream, application/x-ndjson, application/stream+json).
For each active stream it:
process.nextTick.AbortController.abort() with reason
HALLUCINATION_LOOP_DETECTED_BY_ENTROPY_BREAKER, severing the stream.Bounded memory: accumulated text is truncated to the last 4096 characters when it exceeds 8192. A 30-second registry cleanup removes stale streams.
Runs as a separate daemon outside the gateway process. Polls every 2
seconds via psutil.
RuleTriggerActionRedline breachCPU >= 90% OR RAM >= 90% OR Disk >= 90%Log warning + audit entryPoison pillChild process CPU > 95% with 0 I/O for 15 sKill process tree + incident snapshotMemory leakRSS monotonically grows > 100 MB over 60 s, CPU > 30%Kill process tree + incident snapshotCrash loopGateway PID changes 3+ times in 120 sIncident snapshot + 30 s cooldown
Incident snapshots capture journalctl and dmesg excerpts into
~/.openclaw/workspace/memory/core/incidents/.
Run the deterministic deploy script. It is safe to run multiple times (idempotent).
bash
export OPENCLAW_APP_DIR=/app # path to openclaw installation root
bash deploy.sh
The script will:
python3, psutil, and $OPENCLAW_APP_DIR/openclaw.mjs exist.$OPENCLAW_APP_DIR/dist/llm_stream_guard/.openclaw.mjs (skipped if already present).openclaw.mjs before any modification.After deployment, restart the Openclaw gateway to activate.
bash
# Node.js layer tests (no network, no side effects)
node test-entropy-breaker.js
# Python layer tests (mocked psutil, no real process interaction)
python3 test-watchdog.py
Both test suites are deterministic and produce exit code 0 on success, 1 on failure.
FilePurposesrc/stream-entropy-breaker.cjsFetch-patching + stream transform + abort logicsrc/entropy-engine.cjsZlib compression ratio calculator + repetition detectorhost-resource-watchdog.pySystem resource monitor daemondeploy.shDeterministic deployment scripttest-entropy-breaker.jsJS test suite (16 tests)test-watchdog.pyPython test suite (14 tests)
Remove the injected block from openclaw.mjs (between the
[LLM_STREAM_GUARD_START] and [LLM_STREAM_GUARD_END] markers), delete
$OPENCLAW_APP_DIR/dist/llm_stream_guard/, and kill any running
host-resource-watchdog.py process.