Metadata-Version: 2.4
Name: deadkey
Version: 1.2.0
Summary: Headless 0-VRAM Epistemic World-Model & Verification Kernel — bi-temporal SQLite entity_claims, Subjective Logic + 28B DK wire, 0.01ms commit gate, 9-tool MCP, NIM/TRT-LLM proxy, and NeMo Relay worker.
License: Apache-2.0
Project-URL: Homepage, https://deadkey.dev
Project-URL: Repository, https://github.com/deadkey-labs/deadkey
Project-URL: Issues, https://github.com/deadkey-labs/deadkey/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Provides-Extra: nemo-relay
Requires-Dist: nemo-relay-plugin>=0.11.0; extra == "nemo-relay"
Dynamic: license-file

# DEADKEY

> **Headless 0-VRAM Epistemic World-Model & Verification Kernel — in zero dependencies.**
> Typed bi-temporal SQLite `entity_claims` + Subjective Logic `(b, d, u, a)` + 28-byte binary `DK` wire (`0 MiB` GPU VRAM), a `0.01 ms` deterministic epistemic latch, 9-tool MCP server, NVIDIA NIM / TensorRT-LLM sidecar, and live gRPC-verified NeMo Relay worker — Apache-2.0, pure Python 3.10+ standard library.

*On bare-metal terminals, a dead key holds output until a verified state completes. In Deadkey, nothing commits until the receipt locks.*

### Hero Proof #1 — Sealed 4-Arm `LongMemEval-V2` (`42.76M` Tokens, `N=264` Unseen, Zero LLM Judge)

Compiled strictly zero-leak from 200 raw environment trajectories (never opening evaluation questions) into a `19.24 MB` typed bi-temporal SQLite world-model (`10×` compression, `0 MiB` GPU VRAM) and evaluated under identical `max_tokens=512`, `temp=0`, `seed=42` (`Gemma-4-31B-NVFP4+MTP`) across all `264` unseen held-out questions (`val_milestone=131` + one-shot untouched `test_sealed=133`):

| Arm (Pooled Unseen `N=264`, Deterministic `\boxed{}`) | Overall Acc | Dynamic-Env (`N=76`) | Static-Env (`N=124`) | Avg Tools/Q | Paired McNemar vs Runbook v2 |
|---|---:|---:|---:|---:|---|
| `FLAT_SINGLE` (flat FTS5 RAG) | `78/264` (`29.5%`) | `14/76` (`18.4%`) | `36/124` (`29.0%`) | `0.00` | `+14.8 pp`, `58W/19L`, **`p = 9.8e-6`** |
| `FLAT_TOOLS` (agentic search over flat RAG) | `80/264` (`30.3%`) | `15/76` (`19.7%`) | `43/124` (`34.7%`) | `3.00` | `+14.0 pp`, `63W/26L`, **`p = 0.00011`** |
| `DEADKEY_BT_TOOLS` (Wave 1 bi-temporal SQLite) | `97/264` (`36.7%`) | `22/76` (`28.9%`) | `47/124` (`37.9%`) | `3.03` | `+7.6 pp`, `56W/36L`, **`p = 0.0470`** |
| **`DEADKEY_RUNBOOK_V2` (Schema v2 + Turn-0 Hybrid)** | **`117/264` (`44.3%`)** | **`34/76` (`44.7%`, `2.43×`)** | **`52/124` (`41.9%`)** | **`0.88` (`3.41×` fewer)** | **`dynamic-env` Holm `p_adj = 0.00054`** |

*One-shot locked `test_sealed` (`N=133`, never used during iteration): `FLAT_SINGLE 33.1%` / `FLAT_TOOLS 33.1%` (`2.95` tools) → `DEADKEY_RUNBOOK_V2 43.6%` (`0.94` tools, `p=0.020` vs `FLAT_SINGLE`, `p=0.034` vs `FLAT_TOOLS`; `dynamic-env` `17.9% → 41.0%`, `p=0.0225`).*

### Hero Proof #2 — Official ICLR 2025 `LongMemEval` (`knowledge-update`, `N=312` across 4 Architectures & 2 GPUs)

- **Pooled (`N=312`, `0 MiB` GPU VRAM, sha `821a2034d219`):** Flat FTS5 RAG **`219/312` (`70.2%`, 95% CI `64.9–75.0%`)** → **Deadkey Bi-Temporal SQLite: `239/312` (`76.6%`, 95% CI `71.6–81.0%`, `+6.4 pp`, exact two-sided McNemar `p=0.0205`)** — no model regressed overall (`44` questions flipped to right, `24` flipped to wrong).

| Model Architecture & GPU | Flat FTS5 RAG | Deadkey Bi-Temporal (`0 MiB` VRAM) | Delta | Paired (BT/Flat, McNemar) |
|---|---:|---:|---:|---:|
| `Gemma-4-31B Dense (RTX 5090 32 GB)` | `60/78` (`76.9%`, 95% CI `66.4–84.9%`) | **`65/78` (`83.3%`, 95% CI `73.5–90.0%`)** | **`+6.4 pp`** | `9W / 4L` (`p=0.2668`) |
| `GLM-4.7-Flash 30B-A3B MoE (RTX 5090 32 GB)` | `45/78` (`57.7%`, 95% CI `46.6–68.0%`) | **`58/78` (`74.4%`, 95% CI `63.7–82.7%`)** | **`+16.7 pp`** | `19W / 6L` (`p=0.0146`) |
| `Ternary-Bonsai-2.5-27B 1.58b (RTX 4080 12 GB)` | `55/78` (`70.5%`, 95% CI `59.6–79.5%`) | **`57/78` (`73.1%`, 95% CI `62.3–81.7%`)** | **`+2.6 pp`** | `8W / 6L` (`p=0.7905`) |
| `Qwen3.8-27B Dense (RTX 5090 32 GB)` | `59/78` (`75.6%`, 95% CI `65.1–83.8%`) | **`59/78` (`75.6%`, 95% CI `65.1–83.8%`)** | **`+0.0 pp`** | `8W / 8L` (`p=1.0000`) |
| **POOLED (`N=312`)** | **`219/312` (`70.2%`)** | **`239/312` (`76.6%`)** | **`+6.4 pp`** | **`44W / 24L` (`p=0.0205`)** |

## Watch It Hold in 10 Seconds (Zero GPU Required)

```bash
# 1. Schema v2 Typed World-Model + Turn-0 Hybrid Preload (0.62 ms, 0 MiB VRAM)
python examples/world_model_demo.py

# 2. 3-Trap Side-by-Side Epistemic Gate Demo (3.82 ms, 0 MiB VRAM)
python examples/confessor_demo.py

# 3. Stale RAG vs Bi-Temporal SQLite + Disk-Equals-Truth Latch
python -m bench.demo_break_vs_hold
```

```python
from deadkey import MemoryStore, EpistemicCommitGate, EpistemicOpinion

store = MemoryStore("./world_model.db")
store.upsert_claim(namespace="prod", entity_type="cluster", entity_key="eu-west", predicate="primary_node", value="node-a")
store.upsert_claim(namespace="prod", entity_type="cluster", entity_key="eu-west", predicate="primary_node", value="node-b")  # auto-supersedes node-a!
preload = store.recall_hybrid("eu-west primary_node", namespace="prod")  # <1 ms Turn-0 hybrid preload
```

Runs side-by-side on any Python 3.10+ machine:
1. **Stale RAG Poisoning vs. Bi-Temporal SQLite:** Flat RAG leaks both an outdated 5K time (`27:12`) and the updated time (`25:50`). Deadkey supersedes `27:12` cleanly while preserving the full audit trail (`0` stale leaks).
2. **Hallucinated Disk Claim & Fake Test Pass vs. `0.01 ms` Latch:** Blocks `"service.conf is 4,096 bytes"` (`0.13 ms`) and `"all 42 tests passed"` (`0.03 ms`) against real disk receipts while passing truthful claims (`0.04 ms`).

*Think you can sneak a lie past the latch? Submit a PR → **[CHALLENGE.md](CHALLENGE.md)**.*

---

![Deadkey Architecture](assets/deadkey_chart_4_architecture.png)

## Why Deadkey Exists (And How It Differs From Zep / Graphiti / Wrappers)

Bi-temporal memory isn't a new idea — great systems like **Zep** and **Graphiti** exist. **Deadkey** owns a radically different lane: **zero external dependencies, zero Neo4j/Docker containers, `0 MiB` GPU VRAM, and one portable SQLite file** paired directly with a deterministic runtime verifier:
- **Bi-Temporal SQLite Memory (`0 MiB` GPU VRAM):** Tracks *valid time* vs. *transaction time*. Contradicted facts are superseded with timestamps rather than silently overwritten or leaked.
- **Two-Tier Epistemic Gate (Honest Boundary):**
  - *Tier 1 (`~0.01 ms` deterministic):* Covers **checkable claims** — byte sizes, line counts, SHA-256 hashes, and tool/action executions verified against immutable `EvidenceReceipt`s (**Disk-Equals-Truth**). No LLM in the loop to get talked out of it.
  - *Tier 2 (probabilistic selective critic):* Skips benign chat/math at `0 ms` overhead; audits risky drafts for paraphrased fabrications and abstract policy violations.
- **Cartridge Isolation & Open Protocols (Headless-First):** Native **9-tool MCP Server** (`deadkey-mcp`, including Schema v2 `claim_upsert` & `claim_query` plus Subjective Logic `epistemic_fuse` & `memory_opinion`), 1-command **`deadkey-init`** installer (Claude Code, Cursor, Antigravity, Hermes), drop-in **OpenAI / NVIDIA NIM / TensorRT-LLM Proxy** (`deadkey-proxy`), live gRPC-verified **NVIDIA NeMo Relay Worker** (`deadkey-relay-worker`), and **A2A Peer Protocol** (`/.well-known/agent.json` + `/a2a`) with an enforced Hard Privacy Wall.
- **New in `v1.2.0` — Deadkey Core Schema v2 + Live NeMo Relay gRPC Worker + Headless Detox:**
  - **Typed Bi-Temporal World-Model (`entity_claims`):** Promotes our sealed `N=264` LongMemEval-V2 breakthrough directly into `MemoryStore` with automatic slot-keyed Subjective Logic cumulative fusion on corroboration, automatic bi-temporal superseding + `CLAIM_TRANSITION` audit ledger on state mutation, strict `CONFLICT_ESCALATE` mode, `<1 ms` `inspect_entity`, and Turn-0 `recall_hybrid` preload.
  - **9-Tool MCP & Clean Headless Surface:** Added `claim_upsert` & `claim_query` to `deadkey-mcp`, moved heavy GPU training scripts out of the runtime package into `examples/training/`, and exported the minimal headless API directly from `deadkey`.
  - **Live gRPC-Verified NVIDIA NeMo Relay Worker (`deadkey-relay-worker`):** Verified end-to-end over `grpc-v1` against `nemo-relay-plugin==0.11.2` (`Handshake`, `Health`, `Validate`, `Register`, `Shutdown`), injecting Schema v2 `recall_hybrid` context and enforcing the `0.01 ms` commit gate with 28-byte `DK` wire receipts (`pip install 'deadkey[nemo-relay]'`).
- **New in `v1.0.1` — Hardened Tier-1 Epistemic Gate (19-Model Dual-GPU Gate-Crashing Audit):** Blocks forged `[VERIFIED RECEIPT ...]` headers synthesized in assistant output (`forged_receipt_in_output`, 17/17 attacks blocked with `0` FPs), fixes horizontal-whitespace matching (`[ \t]*`) to eliminate multiline key-value (`Bytes: 96\nLines: 4`) newline-bleed false positives, and adds contrast/refutation awareness so honest refutations of stale screenshots or unverified test claims pass cleanly.
- **New in `v1.0.0` — Continuous Non-Boolean Subjective Logic + 28-Byte Binary Wire:** Replaces brittle `True/False` gating with Jøsang `(b, d, u, a)` opinions (`deadkey/epistemic_algebra.py`), live wall-clock temporal decay & Cumulative Dempster–Shafer Fusion inside `MemoryStore`, continuous conflict detection (`CONFLICT_ESCALATE`), fixed 28-byte binary wire frames, and an interactive browser visualizer (`bench/epistemic_simplex_lab.html` · `https://deadkey.dev/simplex.html`).

---

## Full Measured Benchmarks & Raw Receipts (All Checked Into `data/`)

![Bi-Temporal Memory & 100k Scale](assets/deadkey_chart_3_bitemporal_memory.png)

### Scale & Concurrency Proof (`100,000` Records, `0 MiB` GPU VRAM)
- **`100,000`-Record SQLite WAL Stress (`data/memory_scale_100k_report.json`):** `39.77 MB` single file, `0.72 s` insert, **`200/200` contradiction fidelity (`0` stale leaks)**, `0.05 ms` FTS5 p50 (`132.7 ms` broad-token p99), **`0` lock errors** across 8 concurrent threads (`600` ops in `0.14 s`).
- **`10,000`-Record Hybrid 768-d CPU Vector RRF (`data/memory_scale_10k_report.json`):** `11.89 MB` DB, `100/100` fidelity (`0` leaks), `5.17 ms` p50 FTS5 / `18.68 ms` p50 hybrid CPU RRF.

### Runtime Invariance — Dual-GPU Blind Epistemic Gauntlet (24 Probes)
*Note: 24 probes is not a claim of universal 100% — it is a claim of **runtime invariance** across 10+ models and 2 GPU tiers. Full probe suite is in `bench/blind_abstract_gauntlet.py`; submit PRs that beat the gate in [CHALLENGE.md](CHALLENGE.md).*

![Blind Gauntlet Dual-GPU Results](assets/deadkey_chart_1_blind_gauntlet.png)

### 4-Way Controlled Blind Out-of-Sample A/B (`Qwen3-8B`, `4.68 GiB` Q4_K_M, 24 Blind Probes)

With **non-thinking mode (`--reasoning-budget 0`)**, `125B-Teacher DPO` raised RAW blind accuracy from **`7/24 (29.2%)` → `12/24 (50.0%, +20.8 pp)`** and Tier 1 from **`15/24 (62.5%)` → `19/24 (79.2%, +16.7 pp)`**, reaching **`24/24 (100.0%, 0.0% FPR)`** at `701 ms` critic latency (`doom_8b_epistemic_dpo_blind_v1.json`).

With **default Qwen3 `<think>` mode ON** (`rlvr_vs_dpo_4way_blind_v1.json`), hidden chain-of-thought talked itself into complying with adversarial traps across all 4 checkpoints (`25.0%–37.5%` RAW) — proving why weight-only alignment is fragile under CoT and why **Deadkey's external runtime latch still lifted all 4/4 checkpoints to `24/24 (100.0%, 0.0% FPR)`**:

| Training Method (Zero-PII, `<think>` ON) | RAW Blind | Tier 1 Frozen | Tier 1+2 Hybrid (FPR) | Tier 2 Rescues |
|---|---:|---:|---:|---:|
| `Stock Qwen3-8B` | `9/24` | `16/24` | **`24/24`** (`0.0%` FPR) | `8` |
| `125B-Teacher DPO` | `6/24` | `16/24` | **`24/24`** (`0.0%` FPR) | `8` |
| `Teacher-Free RLVR-GRPO` | `8/24` | `16/24` | **`24/24`** (`0.0%` FPR) | `8` |
| `DPO + RLVR-GRPO` | `6/24` | `16/24` | **`24/24`** (`0.0%` FPR) | `8` |

![RLVR vs DPO Ablation](assets/deadkey_chart_2_rlvr_vs_dpo.png)

### `v0.9.6` — `80.75 KiB` GGUF Control Vector vs. `5.03 GB` DPO & The Over-Refusal Cliff

We exported a sparse **`80.75 KiB`** (`82,688 B`, 5 F32 tensors across layers `[10, 11, 12, 14, 15]`) native `llama.cpp` GGUF control vector (`data/deadkey_qwen3_8b_cvec_v1.gguf`, zero weight updates, `+4 MiB` VRAM, `-0.9%` tok/s at `~245 t/s`) via `bench/export_steering_to_gguf.py` and benchmarked it head-to-head against our `5.03 GB` QLoRA DPO checkpoint on stock `Qwen3-8B Q4_K_M` (`NO-THINK`, RTX 5090):

```bash
llama-server -m Qwen3-8B-Base-Q4_K_M.gguf --control-vector-scaled data/deadkey_qwen3_8b_cvec_v1.gguf:1.8
```

![80.75 KiB Control Vector vs 5.03 GB DPO and Over-Refusal Cliff](assets/deadkey_chart_5_cvec_pareto_cliff.png)

| Arm (`Qwen3-8B Q4_K_M`, NO-THINK) | Artifact Delta | Fresh Held-Out 24-Probe (`6/6` benign) | Paired McNemar (Held-Out) | External `LongMemEval` (`N=78`, BT) | Paired McNemar (`LongMemEval`) |
|---|---:|---:|---:|---:|---:|
| `Base (s=0.0)` | `0 B` | `16/24` (`66.7%`, CI95 `[46.7, 82.0]`) | — | `59/78` (`75.6%`, `1` ref) | — |
| `5.03 GB DPO (s=0.0)` | `5.03 GB` | `17/24` (`70.8%`, CI95 `[50.8, 85.1]`) | `1W/0L` (`p=1.0` vs base) | `59/78` (`75.6%`, `1` ref) | `1W/1L` (`p=1.0` vs base) |
| **`80.75 KiB CVEC (s=1.8, frozen)`** | **`80.75 KiB`** | **`22/24` (`91.7%`, CI95 `[74.2, 97.7]`, `16/18` adv, `6/6` benign)** | **`6W/0L` (`p=0.0312` vs base; `5W/0L`, `p=0.0625` vs DPO)** | `57/78` (`73.1%`, CI95 `[62.3, 81.7]`, `4` ref) | `5B/3C` (`p=0.7266` vs base) |
| **`80.75 KiB CVEC (s=3.0)`** | `80.75 KiB` | `22/24` (`91.7%`, `16/18` adv, `6/6` benign) | `7W/1L` (`p=0.0703` vs base) | **`35/78` (`44.9%`, `54/78` false refusals!)** | **`25B/1C` (`p < 1e-6` vs base)** |
| `DPO + CVEC (s=3.0)` | `5.03 GB + 80.75 KiB` | — | — | `34/78` (`43.6%`, `55/78` false refusals) | `p < 1e-6` (does not compound) |

- **Honest Takeaways & Method Disclosures:**
  1. At frozen `s=1.8`, the `80.75 KiB` control vector significantly outperformed base (`p=0.0312`, `6W/0L`) and edged the `5.03 GB` DPO checkpoint (`5W/0L`, `p=0.0625`, not statistically significant at `N=24`) on 24 unseen held-out probes while answering `6/6` benign controls cleanly.
  2. **The Over-Refusal Cliff (`s >= 2.2`):** Cranking static steering to `s=3.0` added `0` net points on held-out probes (`22/24`) while collapsing external `LongMemEval` from `75.6% → 44.9%` (`54/78` false refusals, `p < 1e-6`) — demonstrating empirically why global activation steering is a blunt dial and why local agents still need an external `0.01 ms` deterministic truth gate + bi-temporal memory.
  3. **Statistical & Judge Disclosures:** On `LongMemEval`, `N=78` is underpowered to prove zero accuracy loss at `s=1.8` (`73.1%` vs `75.6%`, `p=0.7266`, overlapping 95% Wilson CIs). All `LongMemEval` arms were graded by a single fixed unsteered judge (`Qwen3-8B-Base-Q4_K_M`, `scale=0.0` — the base model grading its own variants), alongside deterministic exact-substring match counts in `data/four_arm_dpo_vs_cvec_v1.json`, `data/cvec_pareto_sweep_v1.json`, and `data/heldout_and_mcnemar_v1.json`.

### Honest Failures, Negative Results & Rejected Candidates (Zero Cherry-Picking)
- **Qwen3 `<think>` CoT Rationalization:** Turning hidden chain-of-thought ON made `Qwen3-8B` talk itself into complying with adversarial traps across all 4 checkpoints (`25%–37.5%` RAW), even after `125B-DPO` — while the external runtime latch stayed invariant at `24/24 (100%, 0% FPR)`.
- **RLVR-GRPO Reward-Sparsity Wall:** Programmatic `EpistemicCommitGate` GRPO climbed `+0.410` (`25% → 44%` pass) on a 24-task short pool, but hit reward sparsity when scaled cold-start to 54 harder tasks (`-0.303 → -0.432`); warm-starting from DPO LoRA recovered positive ascent (`-0.307 → -0.154`, `+0.153`).
- **Rejected Candidates:** `Tenet-Gemma4-26B-IQ3_XXS` degraded at sub-3-bit (miscopied receipts + HTTP 500s) and was dropped. `DSpark` block-diffusion speculative decoding slowed our 12 GB sparse MoE (`51.3 → 43.2 tok/s`, `50.6%` acceptance) and is off by default.

---

## 3-Command Quickstart (< 2 Minutes on Any Machine)

```bash
# 1. Watch it break vs. hold in 10 seconds (0 GPU required)
python -m bench.demo_break_vs_hold

# 2. Verify environment & reproduce core benchmarks (< 2 seconds, 0 GPU required)
python -m deadkey.doctor && python -m bench.reproduce_all --quick

# 3. Launch the Deadkey Web UI + Live 3-Way Epistemic Proof Lab
python -m deadkey.server --cartridge cartridges/blank-lab/manifest.json --tools cartridges/blank-lab/tools_catalog.json --port 8765
```

Open `http://127.0.0.1:8765` — switch themes in the top bar (**`Deadkey`**, **`1978`**, **`Paper`**) and open **Inspector → Sleep → Live Epistemic Proof Lab**.

![Deadkey UI](assets/ui_deadkey_theme.png)

### Drop-In Integrations (0 MiB GPU VRAM Sidecar)
- **New in `v1.1.0` — NVIDIA NIM & TensorRT-LLM Sidecar (`deadkey-proxy`):** Native `--provider` presets (`nvidia_nim_local`, `nvidia_nim_cloud` with loopback-locked `NVIDIA_API_KEY` bind guard, `tensorrt_llm`, `vllm`, `llama_cpp`), live `X-Deadkey-Gate-Passed` + 28-byte `X-Deadkey-Wire-Hex` response headers, and zero-GPU offline demo (`examples/nvidia_nim_sidecar.py --demo-offline`).
  ```bash
  # Self-hosted NVIDIA NIM container or TensorRT-LLM (trtllm-serve on :8000)
  deadkey-proxy --provider nvidia_nim_local --port 8788 --db ./nim_memory.db
  deadkey-proxy --provider tensorrt_llm --upstream http://127.0.0.1:8000 --port 8788

  # NVIDIA NIM Cloud / API Catalog (reads NVIDIA_API_KEY automatically; keep --host 127.0.0.1!)
  # Security note: server-side API-key injection is restricted to loopback by default so
  # unauthenticated LAN callers cannot spend your NVIDIA API quota.
  deadkey-proxy --provider nvidia_nim_cloud --default-model nvidia/llama-3.3-nemotron-super-49b-v1

  # Zero-GPU self-contained demo (bi-temporal superseding + forged-receipt block + 28B DK wire)
  python examples/nvidia_nim_sidecar.py --demo-offline
  ```
- **NVIDIA NeMo Relay `grpc-v1` Worker Plugin (`deadkey-relay-worker`):** Install optional `pip install 'deadkey[nemo-relay]'` and point NeMo Relay at `examples/nemo_relay/relay-plugin.toml` (`deadkey.nemo_relay_worker:main`).
- **9-Tool MCP Server (Hermes / Claude Desktop / Cursor / Antigravity):** `deadkey-mcp --db ./deadkey_memory.db`
- **OpenAI Epistemic Proxy (`llama.cpp` / vLLM / NIM / TRT-LLM):** `deadkey-proxy --provider llama_cpp --upstream http://127.0.0.1:11455 --port 8770 --semantic-critic`
- **A2A Peer Discovery (optional `deadkey-server`):** `GET http://127.0.0.1:8765/.well-known/agent.json` & `POST /a2a`
- **Optional Research Training Scripts (outside core runtime):** `python examples/training/train_epistemic_rlvr_grpo.py --max-steps 90 --num-generations 6`

---

## License & Trademarks
Licensed under the **Apache License 2.0** (see [LICENSE](LICENSE) and [NOTICE](NOTICE)).
Contributions require DCO sign-off (`git commit -s` — see [CONTRIBUTING.md](CONTRIBUTING.md)).
`"Deadkey"` and `"Deadkey Labs"` are trademarks of **Deadkey LLC**.
