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 / spec / omega-incremental-semantics.md
| 1 | # Omega semantic variables and incremental recomputation |
| 2 | |
| 3 | Gate: `OMEGA_INCREMENTAL_SEMANTICS_PASS` |
| 4 | Code: `src/runtime/rx_semantic.{h,c}` |
| 5 | Test: `tests/runtime/rx_sem_incremental.c` (`make test-sem-incremental`) |
| 6 | |
| 7 | ## Objective |
| 8 | |
| 9 | Do not recompute cognition or derived state when nothing relevant changed. |
| 10 | |
| 11 | ## Model |
| 12 | |
| 13 | **SemanticValue** (`RxSemValue`) has these fields: |
| 14 | - `semantic_id` |
| 15 | - `type` |
| 16 | - `value_version` |
| 17 | - `dependencies[]` |
| 18 | - `generation` |
| 19 | - `derivation_id` |
| 20 | - `confidence` (ppm) |
| 21 | - `evidence_refs[]` |
| 22 | - the value words and their content digest. |
| 23 | |
| 24 | Semantic values come in two kinds: |
| 25 | - **Source.** One field of one world object slot. The id is |
| 26 | `(kind, object id, field)`. The generation is the world object's generation. |
| 27 | The evidence is the causal crumb that last wrote the field. |
| 28 | - **Derived.** One pure function over named inputs. The id is structural: |
| 29 | `H(derivation, inputs)`, so the same question has the same id in every |
| 30 | branch. The generation is the function's implementation generation. |
| 31 | |
| 32 | **DerivedSemanticValue** (`RxSemDerived`) is one immutable cache entry: |
| 33 | - `function_id` |
| 34 | - `input_versions[]`: for each input, its semantic id, generation, value digest, |
| 35 | branch-local version, and evidence |
| 36 | - `result` |
| 37 | - producer provenance: branch, agent, task, J-Space candidate, and measured |
| 38 | compute time |
| 39 | - an entry digest over all of the above. |
| 40 | |
| 41 | ## Rule |
| 42 | |
| 43 | A result is reused if and only if all of these match: |
| 44 | |
| 45 | ``` |
| 46 | derivation_id = H(name, out_type, implementation generation, implementation digest) |
| 47 | for every input: semantic_id, generation, digest(type, value words) |
| 48 | ``` |
| 49 | |
| 50 | The key is SHA-256 over exactly these values. A cache hit also compares the |
| 51 | full stored input record, not only the digest. |
| 52 | |
| 53 | The key leaves out the following, on purpose: |
| 54 | - branch-local versions; |
| 55 | - which branch, agent, task or candidate asked; |
| 56 | - evidence; |
| 57 | - wall-clock time. |
| 58 | |
| 59 | None of these change meaning. |
| 60 | |
| 61 | ## Three layers |
| 62 | |
| 63 | Each layer is cheaper than the next one. |
| 64 | |
| 65 | 1. **Branch memo.** A CLEAN node is served with no work. |
| 66 | 2. **Early cutoff.** A DIRTY node rebuilds its key. If the key is unchanged, |
| 67 | the memo is still exact and nothing runs. |
| 68 | 3. **Content-addressed cache.** The cache is shared by every branch, agent, |
| 69 | task and J-Space candidate in the engine. A hit reuses a result computed |
| 70 | elsewhere from identical inputs. A miss runs the function once and files |
| 71 | the result. |
| 72 | |
| 73 | ## Invalidation (field-granular) |
| 74 | |
| 75 | Writing a source changes one field. It marks DIRTY only the nodes that |
| 76 | declared that field, plus their transitive readers, and only in the branch |
| 77 | that was written. Two kinds of change mark nothing: |
| 78 | - a write of the same content and generation; |
| 79 | - a change to any other field or object. |
| 80 | |
| 81 | Example: a temperature change dirties thermal placement and the plan that |
| 82 | reads it. It does not dirty any of these: |
| 83 | - repository analysis |
| 84 | - memory retrieval |
| 85 | - capability resolution |
| 86 | - fan health, which reads another field of the same machine object. |
| 87 | |
| 88 | The test measures an object-granular baseline for comparison. |
| 89 | |
| 90 | `rx_sem_sync_world` pulls bound fields from `rx_world`. It skips any field |
| 91 | whose world `field_version` did not move. Retiring an object has two effects: |
| 92 | - Its sources become stale. Everything downstream fails with |
| 93 | `RX_SEM_ERR_STALE` until `rx_sem_rebind`. |
| 94 | - The re-created object carries a new generation. Results from the old object |
| 95 | are therefore never served for it, even when the bytes are identical. |
| 96 | |
| 97 | ## Branches and J-Space |
| 98 | |
| 99 | A branch is a forked semantic view with its own source values and its own |
| 100 | memo. A J-Space candidate is a branch that has a candidate id (see |
| 101 | aien-architecture `docs/06-jspace.md`). A write in one branch never reaches |
| 102 | the parent, a sibling, or the world. The cache can be shared safely because |
| 103 | its keys are the complete content of what each result was derived from. |
| 104 | |
| 105 | ## Provenance |
| 106 | |
| 107 | Every PRODUCE and REUSE is a hash-chained event: |
| 108 | - A REUSE names the entry it served, the consumer (branch, agent, task, |
| 109 | candidate), and a digest of the consumer's own input evidence. |
| 110 | - A served value's `evidence_refs` point to its producing entry. |
| 111 | - A source input's evidence is the digest of the world causal crumb that wrote |
| 112 | it. |
| 113 | |
| 114 | `rx_sem_verify` checks all of the following: |
| 115 | - It recomputes every key, every entry digest and every event link. |
| 116 | - Every CLEAN memo in every live branch equals its entry's result. |
| 117 | - Every entry's inputs equal what that branch holds now. This is the |
| 118 | no-stale-memo invariant. |
| 119 | |
| 120 | ## Qualification |
| 121 | |
| 122 | The qualification has two parts: PROVE, which checks correctness, and MEASURE, |
| 123 | which replays the same workload four ways. |
| 124 | |
| 125 | ### PROVE |
| 126 | |
| 127 | All of these run against a real `rx_world` with capabilities: |
| 128 | |
| 129 | | check | what it shows | |
| 130 | |---|---| |
| 131 | | dependency_tracking | Inputs match the declarations. The reverse index is right. Downstream of temperature is exactly {placement, plan}. Node ids are idempotent. A missing input is refused. | |
| 132 | | correct_invalidation | 400 unrelated world writes cause 0 invalidations and 0 runs. Temperature change: 2 nodes dirty, 4 stay clean, exactly 2 runs. Fan change: fan health only. A same-value write invalidates nothing. Early cutoff: the plan is not rerun when the placement comes back the same. | |
| 133 | | no_stale_reuse | 200,000 randomized operations: writes from a small value domain (so values recur), forks, drops and gets over up to 12 branches. Every get is compared with a from-scratch evaluator, and every hit is recomputed in audit mode. Also a directed A-B-A case. | |
| 134 | | generation_isolation | An object retired and re-created with the same bytes is refused while stale, then recomputed. A promoted function generation is recomputed and never served generation-1 results. | |
| 135 | | branch_isolation | Two candidates with different writes. The parent memo, the parent values and the world digest are unchanged. A sibling does not see the other's writes. A parent world change does not reach forked candidates. Dropping one candidate leaves the other intact. | |
| 136 | | cross_branch_valid_reuse | Another agent on another task gets the whole plan from the cache with 0 runs. 16 J-Space candidates with 4 distinct proposals: 8 runs and 24 cache hits, and duplicates are identical. | |
| 137 | | causal_provenance | A reused value explains back to its producer and to the world crumb that wrote its input. World crumbs verify. A REUSE event exists for the consumer. A tampered entry or event is detected. | |
| 138 | |
| 139 | ### MEASURE |
| 140 | |
| 141 | One deterministic organism trace: 600 ticks. |
| 142 | - On every tick: |
| 143 | - 8 noise objects are written; |
| 144 | - the fan jitters; |
| 145 | - the agent asks for a plan. |
| 146 | - Every 3 ticks the temperature moves; 80% of those moves stay inside the same |
| 147 | 5 °C bucket. |
| 148 | - Rarer changes: |
| 149 | - the repository changes every 50 ticks; |
| 150 | - the memory topic changes every 25 ticks; |
| 151 | - the capability table changes every 100 ticks. |
| 152 | - Every 20 ticks, J-Space evaluates 6 candidate settings, each drawn from 3. |
| 153 | |
| 154 | The four replay modes: |
| 155 | |
| 156 | | mode | what it does | |
| 157 | |---|---| |
| 158 | | FULL | Recomputes every derivation on every query. | |
| 159 | | OBJECT | Memo plus cutoff, with object-granular invalidation. | |
| 160 | | FIELD | Memo plus cutoff, with field-granular invalidation. | |
| 161 | | ENGINE | FIELD plus the shared cache. | |
| 162 | |
| 163 | Checks: |
| 164 | - Every mode's answer to every query equals FULL's answer. |
| 165 | - An audited ENGINE replay recomputes every hit, and the gate requires |
| 166 | `false_hits == 0`. |
| 167 | |
| 168 | The receipt reports: |
| 169 | - recomputation avoided; |
| 170 | - compute saved; |
| 171 | - latency saved, with p50 and p99; |
| 172 | - cache-hit rate; |
| 173 | - false-hit rate; |
| 174 | - unnecessary invalidation rate for each mode; |
| 175 | - energy. |
| 176 | |
| 177 | **Energy method.** The measurement uses the on-device counters for package, |
| 178 | CPU-E and CPU-P from hwmon `aien_spbm`, as described in the R15 research |
| 179 | notes. |
| 180 | - Each pair is two windows of equal length, each running the trace 8 times |
| 181 | (one replay saves only a few joules, inside the noise of a shared machine): |
| 182 | - a FULL replay; |
| 183 | - an ENGINE replay followed by idle time until its window is as long as the |
| 184 | FULL one. |
| 185 | - Saved energy is the FULL window minus the ENGINE window. |
| 186 | - The gate judges the CPU clusters (CPU-E + CPU-P), pair by pair. The median |
| 187 | saving must be above zero, and at least 4 of the 5 pairs must show a saving. |
| 188 | - The package counter is reported but not gated. It also carries memory, |
| 189 | graphics and every other process on the machine. On a shared machine, its |
| 190 | swing between windows (a few joules) is larger than this saving (about |
| 191 | 0.25 J of CPU energy per replay of the trace). |
| 192 | - There are 5 repetitions, the order alternates, and the median is reported. |
| 193 | - Overflow indicators are checked before and after every read. A backwards |
| 194 | counter invalidates the window. |
| 195 | |
| 196 | This measures the marginal energy of the work. It is not a wall-outlet |
| 197 | measurement and not a quiet-machine R15 qualification. |
| 198 | |
| 199 | ### Gate values |
| 200 | |
| 201 | | value | when | |
| 202 | |---|---| |
| 203 | | `PASS` | All checks pass, energy was measured and valid, and the run is bound to a clean candidate commit (`OMEGA_CANDIDATE_COMMIT` equals HEAD and the tree is clean). | |
| 204 | | `PASS_UNBOUND` | Everything passes, but the run is not bound to a clean candidate commit. | |
| 205 | | `HOST_PASS_ENERGY_UNMEASURED` | Everything passes on a host with no energy counter, such as CI. | |
| 206 | | `FAIL` | Anything else. | |
| 207 | |
| 208 | The host gate (`tests/gates/run.sh rx-host-reference`) requires the value that |
| 209 | matches the machine: `PASS` on a host whose hwmon exposes the `aien_spbm` |
| 210 | package energy counter, `HOST_PASS_ENERGY_UNMEASURED` on a host without it. It |
| 211 | records which one as the observation `incremental_semantics_verdict`. |
| 212 | `PASS_UNBOUND` and `FAIL` fail the gate on every host (omega-mv#404 item 2). |
| 213 | |
| 214 | ## Limits |
| 215 | |
| 216 | - Functions must be pure over their declared inputs. The engine cannot see an |
| 217 | undeclared read; the audit replay is how that would show. |
| 218 | - A fork copies the branch tables. This is the simple reference, not |
| 219 | copy-on-write. |
| 220 | - The cache is bounded and never evicts. Once it is 7/8 full, new results are |
| 221 | not filed; this is counted. |
| 222 | - There is one mutex and one process. The cache does not survive a restart. |
| 223 | - Cache reuse is not gated by capabilities. A result is visible to any branch |
| 224 | of the engine that presents the same inputs. |
| 225 | - The derivations in the test are stand-ins with real CPU cost. They are not |
| 226 | the AIEN model. |