Core Thesis: Models are ephemeral compute; PostgreSQL is the brain. Keep workflow, context, tests, and approvals consistent while making models interchangeable. Deterministic gates do not guarantee that a model's plan is semantically right; they bound blast radius, block repeatable defect classes, and guarantee clean rollback when verification fails.
⚡ 5-Minute External Engineer Verification & Recorded 5-Step Demo
▶️ Watch 20s Recorded Live Execution (720p MP4) · Raw Terminal Output (.txt) · Source (scripts/demo-full-harness-loop.mjs) · 15s SIGKILL-Only Clip
Real execution against PostgreSQL 16 and Bubblewrap (bwrap --unshare-net) with zero mocks: (1) stages a flawed AI billing patch in krusch_staged_diffs without touching disk, (2) fails isolated sandbox tests (exitCode=1) and rejects the diff (status=REJECTED), (3) stages and sandbox-verifies the repaired 2-file integer-cent fix (exitCode=0), (4) kills applyDiffBatch() mid-apply with SIGKILL after file 1 is renamed and rolls back torn state via cold-worker recoverInFlightApplies(), and (5) cleanly applies both files (status=APPLIED).
Agent-Assisted Setup
Ask your coding agent (Claude Code, Codex, Cursor, Windsurf, or Antigravity):
Read https://raw.githubusercontent.com/kruschdev/krusch-coding-harness/main/INSTALL.md and set up krusch-coding-harness on this machine.
Path A: Zero-Postgres, Zero-API-Key Verification (<30 seconds)
Runs in-process using built-in PGlite and deterministic fixtures (no Docker, no database server, no API keys):
git clone https://github.com/kruschdev/krusch-coding-harness.git
cd krusch-coding-harness
npm ci
# 1. Run 52 fast unit tests (AST indexer, router gate, Slack HITL, cost kill-switch, SSRF fallback, policy floor)
npm run test:unit
# 2. Replay all 100 golden trajectories across 10 failure categories
npm run eval:trajectories
# 3. Verify TypeScript .d.ts declarations and run a complete ephemeral PGlite task
npm run typecheck
./bin/krusch-coding-harness.js run "Verify arithmetic module fix" --mock --ephemeral --auto-approve
Path B: Full PostgreSQL 16 + Bubblewrap 5-Step Crash-Recovery Loop (<3 minutes)
# 1. Start PostgreSQL 16 (defaults to postgresql://postgres:postgres@localhost:5432/krusch)
docker compose up -d
# 2. Apply all 11 SQL schema & row-lock invariant migrations
npm run migrate
# 3. Run all 118 unit, ephemeral, and PostgreSQL integration tests (includes real SIGKILL crash test)
npm test
# 4. Run the live 5-step stage -> fail -> repair -> SIGKILL recovery -> apply loop
node scripts/demo-full-harness-loop.mjs
When simpler suffices: For a single interactive developer session, an isolated git worktree, staged diff, and sandboxed test run (the zero-Docker SQLite default in krusch-stack) achieves practical safety with less operational surface. PostgreSQL write-ahead journaling targets unattended background daemons and multi-worker queues where crash recovery, file-lease concurrency, and durable audit state justify a database.
What You Get If You Only Clone krusch-coding-harness
When you clone this repository, you get a fully functional, self-contained headless execution engine with zero external cloud API dependencies:
┌────────────────────────────────────────────────────────────────────────┐
│ IN-TREE CAPABILITIES IN THIS REPO │
├────────────────────────────────────────────────────────────────────────┤
│ ✓ Pre-Commit Staging Engine: SHA-256 content-addressed blobs │
│ ✓ PostgreSQL FSM: Row-locked phase transitions (INIT ➔ COMMITTED) │
│ ✓ Isolated VERIFY Sandbox: Bubblewrap (bwrap) / process jail │
│ ✓ Capability Allowlist: Test runners only; freeform shells blocked │
│ ✓ "2PC" Apply Journal: crash-recoverable fsync + per-file rename │
│ ✓ In-Memory Postgres: Zero-setup local evaluation via PGlite │
│ ✓ AST Symbol Indexer: JS, TS, Python, Go, Rust structural symbols │
│ ✓ Async HITL Slack Gate: 72h lease + fail-closed HMAC-SHA256 resume │
│ ✓ $0.50 Cost Kill-Switch: Loop-depth & local Ollama fallback router │
│ ✓ API-to-Browser Fallback: SSRF-hardened REST ➔ GUI failover │
│ ✓ Golden DAG CI Gate: 100-trajectory PR blocker across 10 categories │
│ ✓ OpenTelemetry Spans & Cost Ledger: Audit trace JSON per task │
│ ✓ Unified Control Plane: Doctor, :3778 HTTP Bridge & 7-Tool MCP │
└────────────────────────────────────────────────────────────────────────┘
[!NOTE]
Decoupled Architecture: Sibling packages (krusch-pre-router, krusch-cascade-router, krusch-context-mcp, krusch-git) are dynamically resolved adapters. This repository includes its own in-tree regex heuristic gate and deterministic mock adapter that run out of the box with zero external git dependencies or cloud keys.
Architecture Diagram
flowchart TD
subgraph ControlPlane ["Unified Headless Control Plane"]
CLI["CLI (bin/krusch-coding-harness.js | bin/krusch.js: doctor / ci / serve / bench)"]
Bridge["HTTP Control Bridge (127.0.0.1:3778)"]
MCP["MCP Server (stdio - 7 tools)"]
end
subgraph Workflow ["Workflow & Safety Engine"]
FSM["KruschStateMachine (Row-Locked FSM)"]
Guard["TrajectoryGuard (Loop & Escalation)"]
Classifier["ModularRSI (Failure Attribution)"]
end
subgraph StorageEngine ["PostgreSQL Brain (ACID State)"]
Tasks["krusch_tasks (Budgets & Revisit Caps)"]
Blobs["krusch_blobs (Content-Addressed Deduplication)"]
Diffs["krusch_staged_diffs (Leases & Pre-Commit Hashes)"]
Journal["krusch_apply_journal (2PC State & Preimages)"]
Runs["krusch_verification_runs (Replay Tokens & Envs)"]
end
subgraph Sandbox ["Isolated VERIFY Sandbox"]
Bwrap["Bubblewrap (bwrap) / Process Jail"]
BaseRO["Base Tree (Read-Only Bind)"]
Overlay["Overlay / Staged Tree Copy"]
Allowlist["Capability Allowlist (Test Runners Only)"]
Bwrap --> BaseRO
Bwrap --> Overlay
Bwrap --> Allowlist
end
subgraph Disk ["Physical Working Tree"]
WorkingTree["Physical Disk Files"]
end
CLI --> FSM
MCP --> FSM
FSM --> StorageEngine
FSM --> Sandbox
Sandbox -->|Record Results & Exit Code| Runs
StorageEngine -->|Verified & Approved: 2PC Crash-Recoverable Apply| WorkingTree
🧭 System Principles & Invariants
- State Lives in PostgreSQL: Primary task state, turns, events, and proposed file edits never live in transient scratchpads. All state persists to relational tables.
- Pre-Commit Staging Invariant: File edits generated by models are staged into
krusch_staged_diffs with SHA-256 validation. Physical disk files are never touched until tests pass and approval is granted.
- Hard Sandbox Isolation: Verification does not run unconstrained on the user's checkout. It executes in an unprivileged Bubblewrap container (or process jail) with a read-only base tree, network isolation (
--unshare-net), scrubbed credentials (cleanEnv), memory/time limits, capability allowlisting, and process group termination.
- Actionable Failure Attribution: Failures are classified into specific modules (
ContextManagement, ToolUse, ObservationManagement, AgentLoop) using KruschFailureClassifier rather than blind re-prompting.
- Storage-Engine-Grade Apply Journal: the 2PC apply journal (my name for a journaled, crash-recoverable multi-file apply protocol) provides per-file atomic replacement, upfront drift detection, and idempotent crash recovery. It does not make a multi-file batch atomically visible: other processes can observe a partly-applied batch until it completes or is rolled back.
📊 Empirical Benchmarks (95/95 Clean-Room SHA-256 Gates, Self-Run in Lab)
Evaluation Provenance & Third-Party Reproduction Status: Every benchmark below uses a public external dataset run in my lab, with 49 SHA-256-pinned raw audit log bundles (64 files) across 335,000+ queries/traces and 14 external suites published openly on Hugging Face at krush420/sovereign-g4-benchmarks and interactively at krush420/sovereign-router-arena (including the maintainer-merged RouteWorks/RouterArena PR #169 receipt bundle on main @ 844e93b). No outside party has yet re-run these harness evaluations; reproduction issues and independent verification attempts are welcome.
1. Aider Polyglot (225 / 225 Multi-Language Coding Tasks)
Evaluated hermetically across all 225 official Aider-AI/polyglot-benchmark tasks (cpp, go, java, javascript, python, rust with mandatory upstream test un-skipping: --include-ignored, xtest → test, -DEXERCISM_RUN_ALL_TESTS=1, @Disabled stripped, pristine test-hash verification, and clean-workspace .meta/.docs/test exclusion) pairing open-weights gpt-oss:120b with isolated bwrap sandbox test execution + evaluateVerifyOnStop:
| Track |
Exercises |
1-Shot Pass@1 |
krusch-coding-harness 2PC Verify-on-Stop Pass@2 |
Tasks Self-Healed |
Multiplier |
Overall (Aider Polyglot) |
225 |
19.56% (44/225) |
51.56% (116/225) |
+72 |
2.64x (+32.00 pp) |
Rust (cargo test -- --include-ignored) |
30 |
36.67% (11/30) |
66.67% (20/30) |
+9 |
1.82x |
JavaScript (npm test, xtest unskipped) |
49 |
18.37% (9/49) |
59.18% (29/49) |
+20 |
3.22x |
Go (go test ./...) |
39 |
25.64% (10/39) |
53.85% (21/39) |
+11 |
2.10x |
Python (pytest) |
34 |
14.71% (5/34) |
47.06% (16/34) |
+11 |
3.20x |
C++ (cmake -DEXERCISM_RUN_ALL_TESTS=1) |
26 |
3.85% (1/26) |
42.31% (11/26) |
+10 |
11.00x |
Java (./gradlew test, @Disabled stripped) |
47 |
17.02% (8/47) |
40.43% (19/47) |
+11 |
2.38x |
Attribution: The 19.56% -> 51.56% lift (+72 tasks) comes from isolated sandbox test execution, compiler/test error feedback, and bounded repair retries (Pass@2 Verify-on-Stop), reaching parity with published single-model Claude 3.5 Sonnet (51.6%) reference scores at $0 external API cost with 0 truncated diffs committed.
2. BIRD-SQL Mini-Dev (500 / 500 Dirty Enterprise SQLite Queries × 11 Databases)
Evaluated across all 500 official birdsql/bird_mini_dev queries (11 SQLite databases, runtime JS Proxy blocking .SQL / .gold_sql, read-only DatabaseSync(..., { readOnly: true }) schema/FK/cell-value grounding, createKruschPolicyFloor DDL/DML blocklist, and evaluateVerifyOnStop execution-error / empty-set self-healing on gpt-oss:120b):
| Strategy |
Queries |
Execution Accuracy (EX) |
R-VES |
Valid Executable SQL |
Verify-on-Stop Healed |
raw_ddl_oneshot (Raw CREATE TABLE DDL Only) |
500 |
26.00% (130/500) |
24.15% |
97.80% |
0 |
schema_value_grounded_pass1 (FK + Sample Cell Grounded) |
500 |
37.60% (188/500) |
33.30% |
99.40% |
0 |
krusch_2pc_sql_heal (krusch-coding-harness 2PC) |
500 |
40.20% (201/500, 1.55x) |
35.75% |
100.00% (500/500) |
+13 (45 retries = 0.09/q) |
Lifts toxicology 5.00x (12.50% → 62.50%), moderate difficulty from 32.40% → 50.00%, and challenging difficulty from 27.87% → 39.35% while eliminating 100% of invalid/syntax-errored SQL.
3. ETH SpyLab AgentDojo v1.2.2 (1,046 / 1,046 Indirect Prompt-Injection Episodes)
Evaluated across all 1,046 official ethz-spylab/agentdojo (v1.2.2) episodes (97 benign user tasks + 949 ImportantInstructionsAttack adversarial episodes across workspace, banking, slack, and travel on gpt-oss:120b, zero hardcoded benchmark tokens):
| Defense Strategy |
Benign Utility (n=97) |
Attacked Utility (n=949) |
Targeted Attack Success Rate (ASR ↓) |
Defense Rate (↑) |
Policy-Floor Blocks |
raw_unprotected_agent (No Guard) |
61.86% (60/97) |
55.32% |
19.28% (183/949 hijacked) |
80.72% |
0 |
spotlighting_delimited_only (<UNTRUSTED_CONTENT> Only) |
69.07% (67/97) |
54.58% |
14.86% (141/949 hijacked) |
85.14% |
0 |
krusch_sovereign_defense (createKruschPolicyFloor + Taint Guard) |
61.86% (0.00 pp loss) |
49.95% |
0.00% (0/949 hijacked) |
100.00% |
83 |
Scope Qualification: 0/949 hijacked (0.00% ASR across 1,046 episodes) is a benchmark-specific finding under active import-frozen Object.freeze policy floors, network-disabled bwrap --unshare-net sandboxes, and taint guards, not a claim of universal prompt-injection immunity.
4. Official DolphinBench & Generalized 2PC Tool-Action Harness (28 Runs, 16,800 openai/gpt-5.6-sol Traces, 6 Families)