back
loading skill details...
Anti-stuck/anti-snapshot-wipe guard for agentic sandboxes with actual selfheal_runner.sh library, byte-verified GGUF manifest, native CPU rebuild +7-10%, hard timeouts 60-150s, binary fallback chain, prompt-cache integration, and light-swarm auto mode. Prevents Arena 128MB/10k-file snapshot eviction hangs.
---
name: sandbox-selfheal-guard
version: 2.1.0
author: orionshaowswmw
license: MIT
description: Anti-stuck/anti-snapshot-wipe guard for agentic sandboxes with actual selfheal_runner.sh library, byte-verified GGUF manifest, native CPU rebuild +7-10%, hard timeouts 60-150s, binary fallback chain, prompt-cache integration, and light-swarm auto mode. Prevents Arena 128MB/10k-file snapshot eviction hangs.
tags:
- reliability
- agent-safety
- sandbox
- self-healing
- anti-hang
- timeout
- snapshot-wipe
- llama.cpp
- cpu-inference
- error-recovery
- prompt-cache
- max-speed
metadata: {"openclaw":{"emoji":"๐ก๏ธ"}}
---
# sandbox-selfheal-guard ๐ก๏ธโก v2.1.0 โ MAX SPEED + ACTUAL RUNNER LIB
**Problem:** Arena.ai Agent Mode, OpenClaw, containerized sandboxes evict large binaries โ `build/`, `*.gguf` 2.4GB, apt packages โ when workspace snapshot cap exceeded (128MB / 10k files). Scripts survive (small text) but invoke missing binaries โ agent appears to "think forever" user stops it.
## What's New in v2.1.0 โ Debug Fixes & Features
**Debug fixes:**
- v2.0.0 referenced `selfheal_runner.sh` 180-line library but file not bundled โ **now included** as actual executable library in package `scripts/selfheal_runner.sh`
- Fixed missing native build flag: add `-DLLAMA_NATIVE=ON -DCMAKE_BUILD_TYPE=Release` โ +7-10% pp from AVX512/VNNI
- Fixed byte-size check only existence โ now exact byte manifest verification (484M vs 15-byte HTML error page)
- Fixed npx hang root cause clarified: Arena sandbox stdin closed โ shim mandatory export PATH="$HOME/.shim:$PATH"
- Fixed no logging โ now `/tmp/selfheal.log` with timestamped rebuild/redownload events
**New features:**
- **Prompt-cache integration**: `prompt_cache_layer.py` SHA256 lookup before heavy inference โ 0.06s hit = โ t/s, 60% save
- **Run_max_speed integration**: `run_max_speed.sh` uses selfheal pre-flight + cache + fallback + timeout
- **Light-swarm auto**: <8 words casual โ SCOUT only 2.2s, prevents full swarm hang on trivial chat
- **Per-agent timeout with fallback**: SCOUT/SPARK/FORGE 60s, SAGE 150s, fallback q3 on timeout
- **Updated manifest**: 4 models with exact bytes + speed roles (SCOUT 34 t/s etc)
- **Integration tests**: `test_selfheal.sh` simulates missing binary, missing model, truncated model, npx hang
## Core Recipe: pre-flight self-heal + per-call timeout (Reference Implementation)
**`scripts/selfheal_runner.sh` (now bundled, 220 lines):**
```bash
#!/bin/bash
# selfheal_runner.sh โ sourced by all model runners
set -e
LOG=/tmp/selfheal.log
echo "$(date -Iseconds) selfheal pre-flight start" >> $LOG
# 1. apt packages
for bin in cmake g++ curl; do
if ! command -v $bin >/dev/null; then
echo "missing $bin โ apt-get install" | tee -a $LOG
sudo apt-get update -qq && sudo apt-get install -y -qq $bin
fi
done
# 2. npx shim prevents Arena hang
if [ ! -x "$HOME/.shim/npx" ]; then
mkdir -p "$HOME/.shim"
printf '#!/bin/bash\nexec /usr/bin/npx --yes "$@"\n' > "$HOME/.shim/npx"
chmod +x "$HOME/.shim/npx"
echo "shim recreated" >> $LOG
fi
export PATH="$HOME/.shim:$PATH"
# 3. llama.cpp binaries native rebuild +7-10%
CLI=~/llama.cpp/build/bin/llama-completion
if [ ! -x "$CLI" ]; then
echo "rebuild llama.cpp native" >> $LOG
cd ~/llama.cpp
cmake -B build -DLLAMA_NATIVE=ON -DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_SERVER=OFF -DLLAMA_SERVER=OFF
cmake --build build --target llama-simple llama-completion llama-bench llama-simple-chat -j2
fi
# 4. GGUF manifest verification
declare -A MANIFEST=(
["Qwen2.5-0.5B-Instruct-Q5_K_M.gguf"]=420086080
["Qwen3-0.6B-Q4_K_M.gguf"]=484220320
["DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf"]=1117320800
["Qwen2.5-Coder-0.5B-Instruct-Q4_K_M.gguf"]=397808288
)
for f in "${!MANIFEST[@]}"; do
exp=${MANIFEST[$f]}
if [ ! -f ~/$f ] || [ "$(stat -c%s ~/$f)" != "$exp" ]; then
echo "redownload $f (expected $exp)" >> $LOG
case $f in
Qwen2.5-0.5B*) curl -sSL -o ~/$f https://huggingface.co/second-state/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/$f ;;
Qwen3-0.6B*) curl -sSL -o ~/$f https://huggingface.co/bartowski/Qwen_Qwen3-0.6B-GGUF/resolve/main/$f ;;
DeepSeek*) curl -sSL -o ~/$f https://huggingface.co/bartowski/DeepSeek-R1-Distill-Qwen-1.5B-GGUF/resolve/main/$f ;;
Coder*) curl -sSL -o ~/$f https://huggingface.co/bartowski/Qwen2.5-Coder-0.5B-Instruct-GGUF/resolve/main/$f ;;
esac
fi
done
# 5. auth
[ -f ~/.clawhub/TOKEN ] || echo "auth missing โ run clawhub login" >> $LOG
# Wrap model call with timeout + fallback
run_with_timeout() {
local model=$1 prompt=$2 n=$3 timeout=$4
timeout $timeout ~/llama.cpp/build/bin/llama-completion -m $model --prompt "$prompt" -n $n -t 2 -fa on --ctx-size 2048 2>/dev/null || \
timeout 60 ~/llama.cpp/build/bin/llama-simple -m $model -n $n "$prompt" 2>/dev/null || \
return 2
}
```
Then per-call wrapper:
- r1 (1.5B ~13 t/s): budget = 45s + n/10
- q3/fast/code (0.5-0.6B ~30 t/s): budget = 30s + n/20
- Absolute cap 300s
- Fallback: `llama-completion` โ `llama-simple` โ exit 2
## Optimal CPU params (from edge-cpu-gguf-tuner v2)
| Param | Best | Why |
|---|---|---|
| -t | =2 physical cores | t=4 oversubscribes tg -42% |
| -fa | on | pp +11% tg +19% small models |
| -ctk/-ctv | f16 default | q8_0 pp -35-50% CPU |
| -b | 2048 default | no-op ยฑ2.4% |
| quant | newer Q4_K_M > older Q5_K_M | arch > quant speed |
| build | -DLLAMA_NATIVE=ON | AVX512/VNNI +7-10% pp |
| cache | SHA256 hit | 33x faster 2.1sโ0.06s |
| ctx | 2048 fast / 4096 r1 | less KV overhead |
## Byte Manifest + Roles + Speed
| File | Bytes | Role | Speed |
|---|---|---|---|
| Qwen2.5-0.5B-Instruct-Q5_K_M.gguf | 420,086,080 | SPARK | 30 t/s |
| Qwen3-0.6B-Q4_K_M.gguf | 484,220,320 | SCOUT | 34 t/s fastest |
| DeepSeek-R1-Distill-Qwen-1.5B-Q4_K_M.gguf | 1,117,320,800 | SAGE deep | 14 t/s |
| Qwen2.5-Coder-0.5B-Instruct-Q4_K_M.gguf | 397,808,288 | FORGE code | 31 t/s pp145 |
## Anti-hang Rules (must enforce)
1. Never run inference without `timeout`
2. Always verify binary exists + exec
3. Always verify model byte size not just existence
4. Light-swarm (SCOUT only 80-120 tokens) casual chat; full swarm substantive
5. Independent timeouts per swarm agent โ slow SAGE can't hang SCOUT
6. Log self-heal triggers to `/tmp/selfheal.log` and continue
7. Visible progress echo before long ops (spinner/header)
## Integration Tests (NEW)
`scripts/test_selfheal.sh`:
- Simulate missing `llama-completion` โ expect rebuild
- Simulate missing GGUF โ expect redownload manifest check
- Simulate truncated GGUF (15-byte HTML) โ expect redownload
- Simulate npx without shim โ expect shim recreation
- Simulate model timeout โ expect fallback q3
- Simulate repeated prompt โ expect cache hit 0.06s
## Related Skills Integration
- `edge-cpu-gguf-tuner v2` โ provides tuned params
- `fast-response-optimizer` โ reply-first + parallel
- `prompt-cache` โ hash dedup
- `openclaw-cache-kit` โ long retention system prompt
- `model-fallback` โ chain
- `keepalive` โ gateway 24/7
Authored field Arena 2026-07-27 for user-reported "agent stops responding". Root cause snapshot eviction 2.4GB GGUF+build, scripts calling missing binaries. v2.1.0 adds actual runner lib, cache, native rebuild, tests.
don't have the plugin yet? install it then click "run inline in claude" again.