interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / ng / replay / README.md

61 lines · 4855 bytes Raw Blame History Rendered
1# `seed/ng/replay/` — Stage 2 (Pillar 4): Reversible & Counterfactual Time-Travel Execution
2
3Pure seeded OM-2 (`.om`) implementation of Sovereign Intelligence 2.0 Stage 2:
4hash-chained `tok`-boundary journaling, periodic `SLAB`+VM checkpointing, live
5`ngrun` trap-to-cause backwards stepping, multi-branch counterfactual forking,
6and compact semantic state-stream delta reconstruction.
7
8## Files
9
10| File | Purpose |
11|---|---|
12| `tok_journal.om` | Hash-chained `tok`-boundary effect journal (`"OTKJ"` v1, SHA-256 chain) backed by growable OM-2 run-time pools (`global ... *`, no small hard cap), disk file persistence, direct unbounded streaming writer, configurable byte alarm threshold, and fail-closed verification. |
13| `slab_ckpt.om` | Periodic `SLAB` + VM register/PC checkpointing using hybrid keyframes + sparse deltas in growable run-time pools. Every checkpoint stores a 32-byte SHA-256 digest of full logical state; `sck_restore_nearest` jumps directly to the nearest checkpoint `<= target_step` and fails closed on any 1-bit corruption. |
14| `cf_fork.om` | Counterfactual fork engine running deterministic baseline timelines over `SLAB` + `tok_journal` + `slab_ckpt`, then forking `>= 16` (18 in matrix) isolated branches from checkpoint `T` with mutated `tok` events (12 W power drop 300 ms earlier, delayed/dropped network packet `#42`, sensor faults, SLAB store perturbation) and reporting the exact first causal divergence `(step, block, op_idx, tok_seq, field_mask, base_val, cf_val, slab_off)`. |
15| `state_stream.om` | Compact semantic state-stream delta codec (`"OSTM"` v1) coalescing contiguous mutated SLAB byte spans + changed registers per `tok` frame with per-frame full-state SHA-256 verification. Shrinks multi-megabyte raw state dumps to kilobytes with bit-exact reconstruction. |
16| `gate_replay.om` | Standalone pure-OM-2 verification gate covering all 5 stages (in-process journal/checkpoint/18-branch counterfactual/state-stream + live `ngrun` trap-to-cause backwards stepping & regression checks) and 12 fail-closed negative controls. |
17
18Also adds a cleanly-gated additive hook in `seed/ng/ngrun.om` (`--journal PATH`,
19`--rewind`, `--ckpt-every N`) that leaves standard `ngrun` behavior, exit codes,
20stderr, and all `gate-ir` / `gate-front-ir` mutant checks 100% unchanged.
21
22## Wire Formats
23
24### `"OTKJ"` v1 (`tok_journal.om` and `ngrun --journal`)
25- **Header (16 B, little-endian):** `magic[4] = "OTKJ"`, `version u8 = 1`, `flags u8 = 0`, `reserved u16 = 0`, `entry_count u64`.
26- **Entry (`85 + payload_len` B, little-endian):**
27 `seq u64`, `op_kind u8 (1..13)`, `block_id u32`, `op_idx u32`, `payload_len u32`,
28 `payload_bytes[payload_len]`, `prev_hash[32]`, `entry_hash[32]`.
29- **Chain Hash:** `entry_hash = SHA-256("OTKJ1\0" || seq || op_kind || block_id || op_idx || payload_len || payload_bytes || prev_hash)`.
30- **Fail-closed refusals:** bad magic (`1`), version/reserved (`2`), truncation (`3`), trailing bytes (`4`), non-monotonic/duplicate `seq` (`5`), unknown `op_kind` (`6`), broken `prev_hash` chain (`7`), digest mismatch (`8`).
31
32### `"OSTM"` v1 (`state_stream.om`)
33- **Header (24 B, little-endian):** `magic[4] = "OSTM"`, `version u8 = 1`, `reserved[3] = 0`, `n_regs u32`, `slab_size u32`, `frame_count u64`.
34- **Frame:** `frame_seq u64`, `tok_seq u64`, `reg_delta_cnt u16` + `(reg_idx u16, val u64)*`, `span_cnt u32` + `(off u32, slen u16, bytes[slen])*`, `state_hash[32] = SHA-256("OSTM1\0" || n_regs || slab_size || regs || slab)`.
35
36## Live `ngrun` Backwards Stepping (Target 1)
37
38```sh
39# Build ngrun (unchanged 2-unit composition)
40cat seed/ng/src/ir.om seed/ng/ngrun.om | seed/out/omc > ngrun && chmod +x ngrun
41
42# Run any ΩIR program with periodic SLAB checkpoints + trap-to-cause rewind + OTKJ journal
43./ngrun prog.ir --rewind --ckpt-every 4 --journal /tmp/run.otkj
44```
45
46When the program hits an explicit trap (`chk.bounds`, `chk.divz`, `chk.add`, `chk.sub`, `chk.mul`, `chk.conv`, `chk.fuel`, `chk.true`, `trap`, etc.), `ngrun` jumps to the nearest checkpoint before the trap step, replays forward to verify bit-exact parity (`replay_parity=EXACT`), walks backwards across SSA definitions, `br` block parameters, `call` arguments, and `load`→`store` memory dependencies (stepping back across checkpoint windows as needed), emits a structured `ngrun-rewind:` causal report on stderr, flushes the SHA-256 `"OTKJ"` v1 journal, and exits with the exact trap code (`100 + code`).
47
48## Building & Running the Verification Gate (Linux AArch64)
49
50```sh
51cat seed/ng/src/ir.om seed/ng/sha256.om \
52 seed/ng/replay/tok_journal.om \
53 seed/ng/replay/slab_ckpt.om \
54 seed/ng/replay/cf_fork.om \
55 seed/ng/replay/state_stream.om \
56 seed/ng/replay/gate_replay.om | seed/out/omc > /tmp/gate_replay
57chmod +x /tmp/gate_replay
58
59mkdir -p /tmp/replay_scratch
60/tmp/gate_replay /tmp/ngrun /tmp/replay_scratch
61```