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
omega-mv / evidence / DUAL / 3a-jspace-tap / receipt.md
| 1 | # DUAL-3a receipt: read-only observation tap at decision site `jspace.residency` |
| 2 | |
| 3 | Lane: DUAL-3a (ADR 0031 section 7.3 and section 8 row DUAL-3; `DUAL_CURRENT_STATE.md` slice 5). |
| 4 | Repository: aien-dev/omega. Branch `dual/3a-jspace-tap`. |
| 5 | Host only (CPU); no GPU, no chip test touched. |
| 6 | |
| 7 | | Field | Value | |
| 8 | |---|---| |
| 9 | | Base (GitHub main at clone, re-fetched) | `cb7cc216147664549484fcca8e8ceadbd6f6cdbf` | |
| 10 | | Candidate, implementation commit | `9f78d35` (parent `cb7cc216`) | |
| 11 | | Candidate, final | the commit carrying this receipt (PR head) | |
| 12 | | Working tree at each run | clean, `git status --short` empty (section 6) | |
| 13 | | Compiler | `gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0` | |
| 14 | | Flags, tap suite | `-std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -Isrc -pthread`; ASan/UBSan leg adds `-O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all` | |
| 15 | | Flags, existing suite | repository `CFLAGS` (`-std=gnu11 -Wall -Wextra -Werror -MMD -MP -D_GNU_SOURCE -O2 ...`) with `PHYSICS_DIR=$HOME/workspace/physics` | |
| 16 | | Verdict | **DUAL-3a tap IMPLEMENTED; DUAL_ADVISORY_SCHEDULER NOT CLAIMED** | |
| 17 | |
| 18 | ## 1. What changed |
| 19 | |
| 20 | `src/runtime/rx_jspace.h`, `src/runtime/rx_jspace.c` only (production). Decision changes: none. |
| 21 | |
| 22 | - `choose()` is now a wrapper over `decide()`, a pure extraction of the same body |
| 23 | with its working set exposed (the alternatives built, in build order, each |
| 24 | alternative's score when it frees bytes, the cheapest score). Same conditions, |
| 25 | same arithmetic, same strict `<` tie rule, same keep test. The alternative |
| 26 | table literal is untouched; scores go to a side array. |
| 27 | - `js_forge_enforce` / `enforce_u`: one NULL check per decision selects |
| 28 | `observed_u()` when `s->dual_observer` is set, else `choose()` as before. |
| 29 | - `observed_u()` makes the same `decide()` call, builds one |
| 30 | `JsDualObservation`, encodes it canonically, digests it, hands the `const` |
| 31 | record to the observer and returns the chooser's own local result. The |
| 32 | observer cannot change the decision by type; writing into the record (a |
| 33 | copy) changes nothing (scenario `record-tamper`). |
| 34 | - `js_dual_set_observer(JsSpace *, JsDualObserver, const void *ctx)`; default |
| 35 | NULL = today's behaviour; `dual_seq` advances only while an observer is set. |
| 36 | - `js_dual_observation_encode()`: canonical little-endian layout. |
| 37 | - No limit, error path, `JsPolicyReport` field, pruning or externalization |
| 38 | changed. No wall clock anywhere in the record. |
| 39 | |
| 40 | ## 2. Record schema (version 1) |
| 41 | |
| 42 | Kind byte `0xD3`, version `1`, digest domain `omega.dual.site.jspace_residency.v1`, |
| 43 | decision-site id `jspace.residency`. Canonical encoding is 302 bytes, fixed |
| 44 | little-endian layout, kind and version first; `digest = SHA-256(domain || 0x00 || canonical bytes)`. |
| 45 | |
| 46 | | Offset | Bytes | Field | |
| 47 | |---|---|---| |
| 48 | | 0 | 1 | kind `0xD3` | |
| 49 | | 1 | 1 | version `1` | |
| 50 | | 2 | 1 | site id length (16) | |
| 51 | | 3 | 16 | site id `jspace.residency` | |
| 52 | | 19 | 8 | seq (u64, monotonically increasing per space) | |
| 53 | | 27 | 8 | pressure (f64 bits; the value the chooser used: `1e9` or `1e3`) | |
| 54 | | 35 | 1 | pressure case: 1 = CAPACITY (total residency over budget, stays hard), 2 = SOFT (hot arena over half the budget) | |
| 55 | | 36 | 1 | allow_move | |
| 56 | | 37 | 1 | chosen action (`JsAction`; 8 = keep) | |
| 57 | | 38 | 1 | number of priced alternatives | |
| 58 | | 39 | 4 x 34 | alternatives in chooser order MOVE, COMPRESS, SPILL, EVICT: action u8, status u8 (0 inadmissible, 1 built but frees nothing, 2 priced), now_ns f64, later_ns f64, freed_bytes f64, score f64 | |
| 59 | | 175 | 8 | best score (cheapest priced; 0 when none) | |
| 60 | | 183 | 8 | keep threshold = pressure x retain_ns_per_byte | |
| 61 | | 191 | 8 | expected reads | |
| 62 | | 199 | 4 | realization slot (`JsRealId.slot`) | |
| 63 | | 203 | 8 | realization generation (`JsRealId.gen`) | |
| 64 | | 211 | 3 | realization type, placement, recipe | |
| 65 | | 214 | 16 | unit bytes, held (resident) bytes | |
| 66 | | 230 | 8 | holders u32, refs u32 | |
| 67 | | 238 | 8 | last_use (J-Space logical clock) | |
| 68 | | 246 | 32 | semantic state id | |
| 69 | | 278 | 24 | budget bytes, resident bytes, hot-arena bytes at the instant of the decision | |
| 70 | |
| 71 | ## 3. R16 loop-inventory rule and how it is met |
| 72 | |
| 73 | Rule (spec/r16-orchestrator-retirement.md section 4; scanner |
| 74 | `tools/r16_loop_inventory.c`, `--patterns`): every `while(`/`for(`/`do{` in a |
| 75 | tracked `.c/.h/.rs` file is a site when it is unbounded (`while(1)`, `for(;;)`, |
| 76 | ...) or its condition/body contains a wait word (`sleep poll recv heartbeat tick |
| 77 | dispatch schedule orchestrate turn pulse yield epoll`), or when a line names |
| 78 | `run_until_complete`, `max_steps`, `max_turns`. New code under `src/runtime/` |
| 79 | must add no site. |
| 80 | |
| 81 | Check: `./tools/r16_loop_inventory.sh` before: `sites=387 unclassified=60` |
| 82 | (pre-existing drift in other repositories, unrelated), zero sites in |
| 83 | `src/runtime/rx_jspace.c`. After (new test files tracked): `sites=387 |
| 84 | unclassified=60`, zero sites in `src/runtime/rx_jspace.c`, |
| 85 | `tests/runtime/rx_dual_jspace_tap.c`, `tests/runtime/rx_dual_jspace_tap_bench.c`. |
| 86 | Every new loop is bounded and contains no wait word; the tap polls nothing, |
| 87 | sleeps nowhere and sequences nothing. |
| 88 | |
| 89 | ## 4. Pre-registered benchmark thresholds |
| 90 | |
| 91 | Workload (`tests/runtime/rx_dual_jspace_tap_bench.c`, public API only, in |
| 92 | `9f78d35`): fan-out 256 branches over a depth-4 root, 4096-byte units, fixed |
| 93 | `JsCosts`, 40 rounds per trial, each round two timed `js_forge_enforce` calls |
| 94 | (SOFT case at budget 3/2 of residency, CAPACITY case at budget 1/2), 7 trials |
| 95 | per leg, legs interleaved, medians reported. Three legs: base commit |
| 96 | `rx_jspace.c` (observer absent from the code), candidate with observer NULL, |
| 97 | candidate with a recording observer that encodes every record and folds its |
| 98 | digest. |
| 99 | |
| 100 | - T1 (cost when off): median wall of candidate/observer=NULL within +-10 % of |
| 101 | the base commit's median. Below -10 % is noise, not a win claim. |
| 102 | - T2 (cost when on): added nanoseconds per record = (median on - median off) / |
| 103 | records <= 10 000 ns. |
| 104 | - T3 (bookkeeping): records emitted == decisions considered; bytes emitted == |
| 105 | 302 x records. |
| 106 | - The on/off wall ratio is reported as information, not a bar: the tap is off |
| 107 | in production and the per-decision work in this synthetic workload is a few |
| 108 | hundred nanoseconds, so the ratio measures SHA-256 against memcpy. |
| 109 | |
| 110 | A miss is recorded as FAIL in section 6 and not re-run silently. |
| 111 | |
| 112 | **Pre-registration caveat (honest record).** This section was written to this |
| 113 | file and staged before the benchmark ran, and the implementation commit |
| 114 | `9f78d35` was meant to carry it. It did not: `evidence/DUAL/` was gone from |
| 115 | the working tree and the index by the time that commit was made (cause |
| 116 | UNKNOWN; `crumb compile` was tested afterwards and does not remove it; no |
| 117 | Makefile rule touches `evidence/`). The thresholds were therefore written |
| 118 | before the run but first committed after it, in the commit carrying this |
| 119 | receipt. The workload and the bench program were committed before the run in |
| 120 | `9f78d35`; the threshold numbers rest on this statement. A reader who wants |
| 121 | a stronger pre-registration should treat T1-T3 as declared-then-run, not |
| 122 | committed-then-run. |
| 123 | |
| 124 | ## 5. Tests and commands |
| 125 | |
| 126 | ### 5.1 Existing suite covering rx_jspace.c |
| 127 | |
| 128 | `make test-jspace-prod PHYSICS_DIR=$HOME/workspace/physics` |
| 129 | |
| 130 | - before (base `cb7cc21`): `checks=40376 failed=0`, `M20_JSPACE_PROD=PASS` |
| 131 | - after (`9f78d35`): `checks=40376 failed=0`, `M20_JSPACE_PROD=PASS` |
| 132 | |
| 133 | Other targets that compile rx_jspace.c: |
| 134 | |
| 135 | - `build/rx_branch_reuse`: builds after the change (not run: it is the |
| 136 | OMEGA_BRANCH_STATE_REUSE gate with energy counters and 128 forked |
| 137 | processes, out of scope for a host-only slice). |
| 138 | - `build/rx_compose_test` (with `AIENOS_LOCK_REPO=$HOME/workspace/dual/aienos`): |
| 139 | builds after the change, exit 0 (not run). |
| 140 | - `rx_compose_living` / R13 living and C4 requalification binaries: not built |
| 141 | (chip-side or long-running gates; out of scope). |
| 142 | |
| 143 | ### 5.2 New targets (`mk/dual_jspace_tap.mk`, not part of `all` or `test`) |
| 144 | |
| 145 | `make test-dual-3a` = purity + hygiene + parity (plain and ASan/UBSan) + hostile. |
| 146 | |
| 147 | Parity suite `tests/runtime/rx_dual_jspace_tap.c` (includes `rx_jspace.c` |
| 148 | as one translation unit so the reference oracle can call the static cost |
| 149 | helpers). Per scenario three legs: silent, observer A, observer B. Asserted: |
| 150 | identical `js_forge_enforce` return codes, identical `JsPolicyReport`, |
| 151 | identical `JsStats`, identical final space digest (every branch, unit, |
| 152 | placement, extent, content check, then full content digests); A and B record |
| 153 | streams byte-identical; records == considered; seq 1..n; 302 bytes each; |
| 154 | digest recomputed equal; chosen == chooser rule over the record's own |
| 155 | alternatives; chosen == the placement transition that realization (slot, |
| 156 | generation) underwent in the silent run (the failed last decision of an |
| 157 | error-terminated round excepted, and asserted as such); pressure value and |
| 158 | case consistent with the recorded budget and residency. |
| 159 | |
| 160 | What "identical sequence of chosen actions" means here: the silent run |
| 161 | exposes no per-decision sequence (that is the point of the tap), so sequence |
| 162 | identity is proven per realization against the silent run (every record's |
| 163 | chosen action equals what the silent run did to that very realization, keyed |
| 164 | by slot and generation) and as a byte-identical record stream between the two |
| 165 | observer legs. |
| 166 | |
| 167 | Scenarios: under-budget (0 records), soft-hot-arena (1e3), over-total-capacity |
| 168 | (1e9, then SOFT in the same call once total residency is back under budget), |
| 169 | ties (COMPRESS == EVICT exactly, first built wins), exactly-at-budget, |
| 170 | one-byte-below, one-byte-above, spill-exhaustion (`max_spill_bytes` = 2 units, |
| 171 | rc `JS_ERR_FULL` (-2) in both legs), evict-drain (budget 0), fanout-500 (and |
| 172 | 32 in the others), rep-null, record-tamper (observer writes into the const |
| 173 | record: decisions unchanged). Pure extraction: 1752 decisions over 3 cost sets |
| 174 | x 4 pressures x 2 allow_move on mixed placements, `choose()` == verbatim |
| 175 | pre-tap body, 0 mismatches; `js_forge_choose` agrees as well. |
| 176 | |
| 177 | Result: `DUAL_3A_JSPACE_TAP_PARITY=PASS (failures=0)` in the plain and the |
| 178 | ASan/UBSan build (no leak, no UB report). |
| 179 | |
| 180 | ### 5.3 Negative control (REQUIRED) |
| 181 | |
| 182 | `make test-dual-jspace-tap-hostile` builds the same suite with |
| 183 | `-DDUAL_TAP_HOSTILE_TEST`: the leg-A observer casts its ctx to the space and |
| 184 | sets `costs.retain_ns_per_byte = 0` on its third record, so the chooser keeps |
| 185 | everything afterwards. Output (abridged): |
| 186 | |
| 187 | ``` |
| 188 | DUAL-3a jspace.residency tap: parity [HOSTILE NEGATIVE CONTROL: the observer mutates the space; this run must FAIL] |
| 189 | FAIL: soft: a record chose something other than MOVE |
| 190 | FAIL: soft-hot-arena round 0: JsPolicyReport differs with observer |
| 191 | FAIL: soft-hot-arena round 1: JsPolicyReport differs with observer |
| 192 | FAIL: soft-hot-arena: JsStats differ with observer (resident silent 151552 A 151552 B 151552) |
| 193 | FAIL: soft-hot-arena: final space digest differs with observer |
| 194 | ... (2035 FAIL lines in all, across every scenario, including per-realization |
| 195 | "observer saw keep, silent run did move on slot N" lines) |
| 196 | DUAL_3A_JSPACE_TAP_PARITY=FAIL (failures=2035) |
| 197 | test-dual-jspace-tap-hostile: hostile observer detected (parity suite failed as required) |
| 198 | ``` |
| 199 | |
| 200 | The normal build has no such seam: `grep -rn DUAL_TAP_HOSTILE src/` finds |
| 201 | nothing (`make dual-jspace-tap-hygiene`). An earlier hostile variant that |
| 202 | raised the retain price a million-fold was found ineffective (every |
| 203 | alternative was already far below the keep threshold, so no decision moved and |
| 204 | only 1 assertion fired); it was replaced by the retain = 0 variant before the |
| 205 | implementation commit. Recorded so the negative control is known to be a real |
| 206 | one. |
| 207 | |
| 208 | ### 5.4 Purity |
| 209 | |
| 210 | `make dual-jspace-tap-purity`: `nm -u` on `rx_jspace.o` matches none of |
| 211 | `aienos_cap_`, `rx_gen_`, `aegis`. (The tap is inside rx_jspace.c; the object |
| 212 | was also clean before the change.) |
| 213 | |
| 214 | ## 6. Run log (in order; nothing edited after the fact) |
| 215 | |
| 216 | ### 6.1 Implementation commit |
| 217 | |
| 218 | `9f78d35` on `dual/3a-jspace-tap` (parent `cb7cc216`), working tree clean |
| 219 | (`git status --short | wc -l` = 0) when the benchmark below started. See the |
| 220 | section 4 caveat about the receipt file. |
| 221 | |
| 222 | ### 6.2 Existing and new suites at `9f78d35` |
| 223 | |
| 224 | - `make test-jspace-prod PHYSICS_DIR=$HOME/workspace/physics`: `checks=40376 failed=0`, `M20_JSPACE_PROD=PASS` |
| 225 | - `make test-dual-3a`: purity PASS, hygiene PASS, parity PASS (plain and ASan/UBSan, `failures=0`), hostile detected (`failures=2035`, exit 1 as required) |
| 226 | - `./tools/r16_loop_inventory.sh`: `sites=387 unclassified=60` before and after (pre-existing cross-repository drift; zero sites in the touched files) |
| 227 | - `make build/rx_compose_test PHYSICS_DIR=... AIENOS_LOCK_REPO=$HOME/workspace/dual/aienos`: exit 0 |
| 228 | |
| 229 | ### 6.3 Benchmark (`make bench-dual-jspace-tap`, wall clock, medians of 7 trials) |
| 230 | |
| 231 | Run 1 (the pre-registered run): |
| 232 | |
| 233 | ``` |
| 234 | bench[base] observer=NULL median_wall_ns=2520658 decisions=5410 records=0 bytes=0 (rounds 40, trials 7, fanout 256, unit 4096) |
| 235 | bench[tap] observer=NULL median_wall_ns=2510132 decisions=5410 records=0 bytes=0 (rounds 40, trials 7, fanout 256, unit 4096) |
| 236 | bench[tap] observer=record median_wall_ns=13637213 decisions=5410 records=5410 bytes=1633820 |
| 237 | bench[tap] ratio_on_off=5.433 added_ns_per_record=2056.8 records_equal_decisions=yes |
| 238 | ``` |
| 239 | |
| 240 | Run 2 (repeated once, for noise; not used to pick a result): |
| 241 | |
| 242 | ``` |
| 243 | bench[base] observer=NULL median_wall_ns=2498835 ... |
| 244 | bench[tap] observer=NULL median_wall_ns=2488819 ... |
| 245 | bench[tap] observer=record median_wall_ns=13628270 decisions=5410 records=5410 bytes=1633820 |
| 246 | bench[tap] ratio_on_off=5.476 added_ns_per_record=2059.0 records_equal_decisions=yes |
| 247 | ``` |
| 248 | |
| 249 | | Threshold | Measured (run 1) | Verdict | |
| 250 | |---|---|---| |
| 251 | | T1 observer NULL within +-10 % of base | 2 510 132 / 2 520 658 = -0.42 % (run 2: -0.40 %) | PASS | |
| 252 | | T2 added ns per record <= 10 000 | 2 056.8 ns (run 2: 2 059.0) | PASS | |
| 253 | | T3 records == decisions, bytes == 302 x records | 5410 == 5410; 1 633 820 == 302 x 5410 | PASS | |
| 254 | | ratio on/off (information only, not a bar) | 5.43x (run 2: 5.48x) | reported | |
| 255 | |
| 256 | Reading: with the observer off the change costs nothing measurable (T1). With |
| 257 | a recording observer every decision pays about 2.1 microseconds, almost all |
| 258 | of it the plain-C SHA-256 over 302 + 37 bytes; on this synthetic workload a |
| 259 | decision itself is about 0.46 microseconds (memcpy-sized moves and frees), so |
| 260 | the ratio is large while the absolute cost is small. The ratio is what a |
| 261 | DUAL-3b campaign must budget for when it turns the tap on; it is not a |
| 262 | production cost today because production has no observer. |
| 263 | |
| 264 | ## 7. Limits |
| 265 | |
| 266 | - Host only, synthetic workload, fixed costs; no claim about calibrated |
| 267 | costs, real workloads or GPU residency. |
| 268 | - The record is this site's own format (kind `0xD3`, version 1). The DUAL |
| 269 | record module (DUAL-0a, not merged) will reference these digests; no |
| 270 | dependency on it was taken. |
| 271 | - `rx_branch_reuse`, `rx_compose_test` were built, not run. |
| 272 | - `DUAL_ADVISORY_SCHEDULER` (DUAL-3 exit) is not claimed: no |
| 273 | `DualRecommendation`, no pre-registered workload set, no |
| 274 | recommendation-versus-actual analysis. This slice is the tap only. |