Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Variable Systems · Command Center

Deterministic WebAssembly Safety Envelopes for Embodied AI

A native desktop harness and benchmark suite demonstrating sub-0.1 ms WebAssembly guardrails that act as an active safety predicate — evaluating, passing, or clamping the output of an erratic ("hallucinating") agent before it reaches a physical actuator.

Ten physics environments, each with a hand-written #![no_std] Rust guardrail compiled to wasm32-unknown-unknown, driven from a PySide6 command center with live rendering, telemetry, and one-click A/B between raw chaos and WASM-guarded execution.


1. The problem: non-determinism at the hardware edge

Modern embodied agents — deep-RL policies, VLA models, LLM-driven planners — are statistical systems. Under distribution shift, adversarial noise, or simple under-training they emit commands that are not merely suboptimal but physically invalid: full-deflection torque reversals, max-thrust oscillations, joint commands that slam servos into their end-stops.

In simulation this costs a reset. On real hardware it costs a gearbox, a rotor, or a person standing next to the machine. The core hazard: the policy network and the motor driver share a control path with nothing deterministic between them.

2. The solution: an active safety predicate (not a deaf override)

Each guardrail is a filter, not a deaf override. It computes a deterministic safe response from live telemetry, compares the agent's proposed command against it, and clamps only the unsafe portion — the agent keeps authority whenever it is physically safe.

  • Pure Rust, #![no_std], zero heap. Static linear-memory buffers and arithmetic only; artifacts are 0.5–1 KB of WebAssembly.
  • Deterministic by construction. The same (observation, proposed action) always yields the same verdict. No RNG, no learned weights — provable in a way a neural network is not.
  • Sub-0.1 ms execution. Each calculate_correction runs in a wasmtime instance over shared linear memory; measured per-tick latency is ~9–38 µs across all packages (well inside a 1 kHz control loop).
  • Portable to bare metal. Compiling to wasm32-unknown-unknown with no OS dependency means the same module embeds in firmware or an RTOS via any Wasm runtime — the simulator is the proving harness, not the deployment target.
host  --[ OBS: telemetry ]------------->  WASM linear memory
host  --[ ACT_IN: agent's proposed cmd ]->  WASM linear memory
                       calculate_correction()   (deterministic predicate, <0.1 ms)
WASM  --[ ACT: safe cmd + STATUS: verdict ]-->  host  -->  env.step()

3. Results

Every number below is measured by benchmarks/ab_command_center.py (3 seeds, headless), running the chaos agent RAW (straight to the actuators) vs GUARDED (routed through the package's real guardrail.wasm). Reproduce with python -m benchmarks.ab_command_center.

Clean Win — a cheap analytic safe action fully protects

Environment Metric RAW GUARDED Structural failures (R → G)
Lunar Lander (thrust-vectoring) episode reward −524 +279 3/3 → 0/3
CartPole balance steps 18 500 (cap) 3/3 → 0/3
Inverted Double Pendulum ⭐ balance steps 4 1000 (cap) 3/3 → 0/3
Pendulum (swing-up) upright steps 37 181

Hard-Stop Clamp — bound the command against a physical limit

Environment Metric RAW GUARDED Structural failures (R → G)
Hypersonic Interceptor (6-DOF) targets intercepted 0.0 3.0 3/3 → 0/3
Reacher (2-link arm) joint-ticks past limit 75 0
Shadow Hand (block manipulation) joint-ticks past limit 92 14

Honest Mitigation & Boundary — safety is the control problem

Environment Metric RAW GUARDED Structural failures (R → G)
Hopper survival steps 13 1000 (cap) 3/3 → 0/3
Humanoid survival steps 23 70 3/3 → 3/3
Bipedal Walker survival steps 66 87 3/3 → 3/3

Reading the regimes. Where a cheap analytic safe action exists, a tiny verifiable guardrail genuinely protects the hardware. Where staying upright is the hard problem (Humanoid, Bipedal) it can only mitigate — the Humanoid is delayed ~3× but not saved; the Bipedal barely moves. Hopper sits in between: the PD stance-hold actually keeps it healthy for the full cap (closer to a clean win). Mapping that boundary honestly — and reporting where the pattern fails — is a feature of the suite, not a gap.

Safety outcome at a glance

                        RAW  ───────────────►  GUARDED
Inverted Double Pend.   ▏4 steps              ████████████████████ 1000  (250×)
CartPole                ▏18                    ████████████ 500           (28×)
Hopper                  ▏13                    ████████████████████ 1000  (75×)
Lunar Lander            crash (−524)           soft landing (+279)
Hypersonic              0 hits / airframe lost  3 hits / 0 failures
Reacher                 75 ticks at hard-stop   0
Shadow Hand             92 ticks at hard-stop   14                         (−85%)

All guardrail latencies: ~9–38 µs/tick · WASM artifacts: 0.5–1 KB each.


4. The Command Center desktop app

A native PySide6 application (no browser, no local web server) that instantiates and steps the real environments and routes the chaos agent through the real guardrail.wasm:

  • Control Deck — target-environment dropdown (all 10), "Engage WASM Guardrails" toggle, render throttle, EXECUTE / HALT.
  • Live Telemetry — embedded render pane, real-time latency-matrix and structural-load charts, structural-integrity banner (NOMINAL → CRITICAL FAILURE), score + token-overhead metrics, scrolling execution log.
  • Physics runs on a background QThread, streaming frames and per-tick telemetry to the UI via Qt signals.

A note on the "Token Overhead" gauge. This suite contains no LLM and emits no tokens. Rather than fabricate a figure, the gauge shows a transparent projection from the measured count of envelope violations (ON → O(1) per tick; OFF → compounds on each boundary violation), with the formula shown in the UI. Latency, load, clamps, and failures are all measured live.

Run from source

pip install -r requirements.txt
python -m command_center

Build a standalone Windows .exe

.\build.ps1        # compile + stage every guardrail.wasm (needs Rust + wasm32 target)
.\build_exe.ps1    # PyInstaller -> dist\VariableSystemsCommandCenter\...exe

The exe ships a headless self-verifier — VariableSystemsCommandCenter.exe --selftest exercises the bundled physics + wasm for all 10 environments and writes selftest_report.txt (current status: 20/20 PASS).


5. Repository layout

.
├── command_center/                 # PySide6 desktop app (engine + UI + entrypoint)
├── benchmarks/
│   └── ab_command_center.py        # headless A/B that produces the results table above
├── build.ps1                       # compile + stage every guardrail.wasm
├── build_exe.ps1                   # PyInstaller -> standalone .exe
├── command_center.spec             # PyInstaller bundle definition
├── requirements.txt
│
├── cartpole_wasm_guardrail/        # CartPole-v1                  (clean win)
├── lander_wasm_guardrail/          # LunarLanderContinuous        (clean win)
├── pendulum_wasm_guardrail/        # Pendulum-v1                  (clean win)
├── double_pendulum_wasm_guardrail/ # InvertedDoublePendulum-v4    (clean win, LQR)
├── hypersonic_wasm_guardrail/      # custom MuJoCo 6-DOF intercept (hard-stop clamp)
├── reacher_wasm_guardrail/         # Reacher-v4                   (hard-stop clamp)
├── shadowhand_wasm_guardrail/      # HandManipulateBlock-v1       (hard-stop clamp)
├── hopper_wasm_guardrail/          # Hopper-v4                    (PD stance-hold)
├── humanoid_wasm_guardrail/        # Humanoid-v4                  (honest mitigation)
└── bipedal_wasm_guardrail/         # BipedalWalker-v3             (honest mitigation)

Each *_wasm_guardrail/ package is self-contained: Cargo.toml + src/lib.rs (the WASM spine) and a README.md. The original six also ship a main.py / benchmark.py that runs the package standalone; the four newer ones are driven entirely by the Command Center.

6. Prerequisites

  • Python 3.10+ with the packages in requirements.txt (gymnasium[box2d,mujoco], gymnasium-robotics, mujoco, wasmtime, PySide6, pyqtgraph).
  • Rust toolchain (rustup) with the wasm32-unknown-unknown target — only needed to rebuild the .wasm files; the compiled artifacts are committed so the app runs as-is.
rustup target add wasm32-unknown-unknown

License

Provided as a reference benchmark suite. Add your preferred license before publishing.

About

Compilation of ai benchmarks to test the before and after effect of enabling the wasm guardrails.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages