zhc-early-warning-system

The fleet Early Warning System, a deterministic, zero-model-call sentinel that runs on every OpenClaw box and tells the OPERATOR (never the client) the moment something breaks or drifts. It pins a per

SKILL.md

GitHub

ZHC Early Warning System (Skill 60)

"ZHC" = Zero Human Company. Spelled out once; the skill's surfaces never use the acronym unprompted. This skill watches the MACHINE, not the work: it is a deterministic sentinel on every fleet box that makes "something changed" a computable fact and hands the operator a revert command at the moment of the alert. It is not a model router, not a config manager, not a client-facing anything, and (by default) not an auto-healer.

The fleet's failure-discovery mechanism today is: the operator notices, or the client notices first. Both are too late, and the second one breaks move-in- silence by definition. This system moves discovery to minutes, silently, to the operator only.

The binding doctrine (every code path honors these)

  1. ZERO model calls, ever, anywhere in the sentinel. Every check is deterministic file / stat / diff / arithmetic work. The heartbeat token-burn trap does not apply because there is no model turn to bill. guard-no-anthropic-runtime.py still ships and rides the merge gate, statically, because a future contributor might be tempted to add an LLM-judged anomaly check. They must not: deterministic or it does not ship.
  2. OPERATOR-ONLY, CLIENT-SILENT, STRUCTURALLY. DELIVERY (v1.3.0): on a CLIENT box a P1 that stays open for 30 minutes is admitted to Rescue Rangers (durable ticket via the shared rescue admission client, run after every cron-tick, with backoff on failure); P2/P3 are recorded in the ledger only (ews-entry.sh audit), never messaged. Each problem is recorded and routed ONCE, when it appears, and resolved when it goes away. Client boxes carry no "operator" Telegram account, so the old direct send failed on every attempt. On the OPERATOR box alerts still route through its own OpenClaw gateway to the OPERATOR account, with deliver:false semantics on any agent-loop injected event. The client's bot, chats, and Telegram account are never recipients. Move in silence toward clients is structural here, not policy. ONE narrow, approved exception: on the OPERATOR's OWN box only (never a client box), S3's 85%-handoff case ALSO sends the operator a plain-language self-notice about that box's own context health (Lane 2, context.operator_self_notify) -- because on that one box the finding's subject and the operator are the same person. It is gated structurally on the box's own ledger role meta being "operator" in code (ews_alert.py route_finding), never on a config flag alone, so it cannot be misconfigured onto a client box. Every other D5 case and every other signal in this skill stays exactly as client-silent as before.
  3. NEVER print, echo, grep, or paste a secret VALUE. Credentials are reported by LABEL and POSTURE only (SET / NOT SET / signed-in / signed-out). A leaked-secret finding reports file:line and CLASS only; the value is never reproduced, not even partially.
  4. CONFIG WRITES RUN AS THE BOX USER, never root (node on VPS, wrapped in docker exec -u node). A root-owned config freezes the gateway - the exact S6 incident this system exists to catch. Every config-touching path refuses to run as root.
  5. NEVER commingle clients. The sentinel reads only its OWN box; it never reads or probes another client's box, account, or credentials. The aggregator collects tiny digests over the fleet's existing sanctioned access paths, never config contents.
  6. NEVER silently change a client's chosen model (S1/S2 alert; they never act - client model choice is sovereign) and NEVER auto-change a client box by default: safety-cap enforcement is ALERT-ONLY fleet-wide (D2). Auto-revert (enforce_caps) exists as code but defaults OFF everywhere; it is a per-box opt-in only.
  7. NOTHING Anthropic-family runs at runtime. The sentinel calls no model at all, so the rule is satisfied vacuously at runtime AND enforced statically over every shipped file. NEVER ship a claude-* / anthropic/* / us.anthropic.* runtime identifier; the signature catalog names those families only as deny data.
  8. PROVE ON THE OPERATOR BOX, THEN HOLD. The full install plus drill battery is proven on the OPERATOR box first; fleet rollout is HELD at repo-only until the operator's explicit word. A repo merge is not a roll. The system obeys the laws it enforces.

Reuse before rebuild (this skill integrates, it does not reinvent)

Fleet asset reused What Skill 60 does with it
Native ~/.openclaw/logs/config-audit.jsonl The sentinel TAILS this event stream from a persisted byte offset; it does not invent a config watcher. Every config.write row already carries ts, argv, pid, ppid, previousHash, nextHash, existsBefore.
Session *.trajectory.jsonl (modelId/provider per event) Ground truth for S2 runtime-fallback detection, independent of what the config claims.
Skill 58 alert-dedup.py pattern Operator-only gateway send, per-class dedup windows, storm cap. Reused, not rebuilt (ews_alert.py).
Skill 58 guard-cron-inventory.py pattern One-cron / no-heartbeat / no-poller inventory law and the cadence-bound math.
Skill 59 four-scanner merge-gate family guard-no-anthropic-runtime.py, scan-no-secrets.sh, scan-no-client-identifiers.sh, scan-no-json-exports.sh, same 0/1/2/3/4 exit contract and value-free doctrine.
scripts/skill-content-hash.sh (repo root) Auto-picks up 60-* as a hashed skill dir; the update stamp gate covers Skill 60 with no extra wiring. (S9 no longer runs it per tick - v1.3.0.)
update-skills.sh Re-pins the Skill 60 baseline at the end of every fleet update (the operator-sanctioned change), so approved changes never become permanent drift.
Skill 59 single-writer ledger pattern One SQLite-WAL writer (ews_ledger.py); every other script goes through it.

The ten detection signals (full catalog in docs/SIGNAL-CATALOG.md)

# Signal Source of truth Default severity
S1 Model / provider config drift vs pinned baseline openclaw.json model keys, diffed each tick P2, P1 on a client box for a claude-* / anthropic/* / paid-tier change
S2 Runtime fallback (ground truth) trajectory modelId/provider per event P2, P1 for out-of-allowlist paid/Anthropic-family on a client box
S3 Context vs compaction live usage (_context_usage(), off the newest trajectory file) vs effective ceiling (contextWindow minus SUBTRACTIVE softThresholdTokens) broken-config = P1 to OPERATOR; running-low = to the BOX'S OWN agent (D5), not the operator, EXCEPT the operator's own box also self-notifies at 85% (Lane 2, narrow approved exception)
S4 Safety-cap raise (never-silently) enumerated cap keys vs baseline + approval stamp P1 on an unstamped RAISE; ALERT-ONLY (D2), emits a revert
S5 Furnace / idle-burn (hybrid, billing-aware) heartbeat cadence/model, cron inventory, idle paid-model activity, per-box BILLING MODEL P1 idle burn; framed as usage-consumed vs dollars-spent per billing type (D9)
S6 Config-write hygiene + reversibility config-audit.jsonl tail + ownership stat P1 root-owned; SNAPSHOT on every write
S7 Surfaces dark (gateway / dashboard / tunnel) local process/port probes + build marker P1 gateway unreachable; dead-man covers a box that cannot speak
S8 Secret leaked into transcript/log new bytes scanned with the secret-CLASS detector P1, value-free (file:line + class only)
S9 Skills missing / stale downgrade each skill's skill-version.txt vs the pinned versions (v1.3.0: no tree hashing; upgrades raise the pinned level) P2 missing, P2 version went down
S10 Cron / delivery drift cron entries vs baseline P2 new cron, P1 announce cron on a non-operator chat

Two deliberate NON-signals, stated so nobody adds them later: (a) the sentinel never reads another client's box, account, or credentials; (b) the sentinel never evaluates CONTENT quality - that is the Quality Control protocol's job.

Single-writer state vocabulary

~/.openclaw/ews/ews.db (VPS /data/.openclaw/ews/ews.db), SQLite WAL, written ONLY by ews_ledger.py. Tables: events (signal, severity, key path or file:line, class, tick ts, ack state), offsets (config-audit byte offset, per-log scan offsets so S8 reads only NEW bytes), snapshots (path, ts, sha256, trigger event id, revert command text), baseline_stamps (S4 approval records), digests (what was sent when, for dedup). The pinned baseline is ~/.openclaw/ews/baseline.json (0600, box user); reality is diffed against it and never silently becomes it.

Enforcement pointers (a rule without a gate is a suggestion)

Rule (from the spec) The script/gate that enforces it
Never silently raise a safety limit ews_baseline.py approval stamp + ews_sentinel.py S4 (unstamped raise = P1)
Configuration changes are backed up and reversible ews_snapshot.py (snapshot on every write) + ews_revert.py (restore as box user, byte read-back)
Model / fallback switches are detected ews_sentinel.py S1 (config) + S2 (trajectory ground truth)
A handoff is requested while context remains ews_sentinel.py S3 (_context_usage() feeds live 70/85% thresholds; running-low to the box's own agent, D5)
The box's own agent can actually see its self-notices ews_alert.py read_box_agent_notices() / ews-entry.sh notices (D3 fix: box-agent-notices.jsonl previously had no reader)
Operator-only, never client-facing ews_alert.py (gateway-only, operator account, dedup, deliver:false)
Zero Anthropic at runtime vacuous at runtime + guard-no-anthropic-runtime.py at the merge gate
No secret value ever printed scan-no-secrets.sh class detector reused everywhere; alerts carry class only
Config as the box user, never root root-refusal in every config-touching path; docker exec -u node on VPS
One cron, zero model calls guard-cron-inventory.py pattern; thresholds.json owns the 15-minute cadence
A detection can never switch the sentinel off the cron is registered as ews-entry.sh cron-tick, which maps the sentinel's exit 10 (findings present) to 0. The scheduler counts any non-zero exit as a failed run and auto-disables a job after 10 consecutive ones, so a bare tick registration made a box with a standing finding silence its own guard. Every other non-zero exit still passes through, and every install re-enables a tick the scheduler had already switched off
Weekly cadence, pinned ews_cadence.py (recommends only; default never self-changes, D8)

Entry and verify

bash 60-zhc-early-warning-system/ews-entry.sh tick            # one sentinel tick, by hand
bash 60-zhc-early-warning-system/ews-entry.sh cron-tick       # what the CRON runs (exit 10 -> 0)
bash 60-zhc-early-warning-system/ews-entry.sh audit           # read-only diff table
bash 60-zhc-early-warning-system/ews-entry.sh --self-test     # every script self-test
bash 60-zhc-early-warning-system/verify.sh                    # drill battery (failable proof)

The sentinel tick and every companion command route through the ONE sanctioned entry (ews-entry.sh). Every script implements --self-test (deterministic, no network, no model). verify.sh is the independent, failable end-to-end proof, including a [DRILL] message through the REAL alert path to the operator account.