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 / spec / typed-result-constraints.md

187 lines · 10743 bytes Raw Blame History Rendered
1# Omega typed result constraints (OMEGA_TYPED_RESULT_CONSTRAINTS)
2
3Code: `src/runtime/rx_contract.{c,h}`. Test: `tests/runtime/rx_typed_results.c`,
4`make test-typed-results` (`TYPED_RESULTS_N`, default 400 requests per kind
5and path). Receipt: `evidence/TYPED_RESULTS/`.
6
7## Purpose
8
9When cognition is asked for a structured semantic object, an invalid answer
10must be impossible to generate, or be caught before it is published. The
11contract an answer must meet is typed Omega state. JSON is one way to write
12an object down; it is never the contract, and a JSON text is only accepted
13after it has been parsed back into typed state and checked.
14
15## Contracts
16
17A contract (`RcContract`) is typed fields, a generation order, and a table of
18rules. Its identity is SHA-256 over a canonical binary encoding of kind, field
19types, derived flags, order, rules and the published object type. Field names
20are serialization keys and are not part of the identity.
21
22| Contract | Fields | Published as |
23|---|---|---|
24| Plan | AIEN plan layout (seq, action, regime, condition, hypothesis, reason, goal) | `RX_OT_PLAN` |
25| Hypothesis | AIEN hypothesis layout (seq, kind, prediction, classes, expected, observed, state) | `RX_OT_HYPOTHESIS` |
26| CapabilityNeed | principal, operation, resource, rights ceiling, effect classes, locality, latency budget, approval | contract type |
27| ActionGraph | digest, subject, node/effect/evidence counts, goal kind; the `AgGraph` is attached | contract type |
28| Skill invocation | skill, arity, three arguments, attempts, principal | contract type |
29| World mutation | object, generation, field, value, principal, resource (derived) | contract type |
30| Effect proposal | effect resource, value, verdict evidence, irreversible, approval, principal, kind | contract type |
31| Generation candidate | candidate, parent, authority epoch, evidence, proofs, objects, proposer, lineage | contract type |
32| Evidence | subject kind, subject, run, checks, failures, verdict, digest, producer | contract type |
33
34CapabilityNeed follows the capability query's meaning (`rx_capq.h`, what AIEN
35needs done, not who does it). Its fields are the part of `CqNeed` a single
36semantic object carries; the query's type lists and trade-offs stay in the query.
37
38### Constraint types
39
40| Type | Rule | Examples |
41|---|---|---|
42| type | field type (u32, bool, enum < 64, bits, object id, subject, resource) | every field |
43| range | `f in [k, k2]` | plan regime, hypothesis expected, evidence checks |
44| enum | `f in set` | plan reason, hypothesis state, effect kind |
45| structural | nonzero, bits within a mask, attached graph validates | rights ceiling, evidence digest, ActionGraph |
46| cross-field | guarded comparison between fields | reason GOAL needs a goal; PASS has no failures |
47| authority | principal is the producer; principal holds rights now; no privileged rights | every kind; mutation and effect targets |
48| generation | object live at that generation; parent is the active generation; next; epoch | mutation, generation candidate |
49| referential | context object field, next sequence, skill and arity, live object, resource of object | plan, hypothesis, skill, mutation |
50| required evidence | a published PASS evidence record names this subject | effect verdict, generation evidence |
51| effect | forbidden resources, allowed effect resources, effect budget, approval for irreversible, graph clear | capability need, effect proposal, ActionGraph |
52
53Authority is checked through the world's authority view (validation, never
54mint). `rx_contract.o` is linked alone first and the build fails if it
55references an AIENOS admin operation.
56
57## Two paths
58
59**Constrained.** `rc_compile` decides, per rule, whether it can become a
60per-field domain given the fields before it in the generation order.
61`rc_domain` then gives the allowed values of one field (interval, enum, bit
62mask, explicit set, exclusions, excluded interval) from the fields already
63chosen and the live context. A backend that decodes under a mask only
64chooses inside it. Rules that cannot become a domain (the attached graph's
65structure, the graph's forbidden requirements) are checked once the candidate
66is complete. An empty domain on the first field means nothing could be valid
67in this context: the request ends before anything is generated.
68An empty domain later is a dead end and costs a retry (there is no lookahead).
69
70**Free.** `rc_produce` generates, checks, repairs what the contract marks
71repairable, otherwise rejects and generates again, up to a bound.
72
73Both paths end in `rc_check`. Nothing is returned as publishable unless it
74passed.
75
76### Repair
77
78Two repairs exist, both declared on the rule:
79
80- **derive**: recompute a field the contract marks derived (sequence number,
81 an object's resource, a graph's digest and counts);
82- **narrow**: clear bits a rule forbids (a capability need asking for fewer
83 rights).
84
85Nothing else is repaired. Stale generations, missing evidence, wrong
86principals, broken references and effect restrictions reject.
87
88### Generation order
89
90Derived fields come after the fields they are derived from. The World
91mutation contract first chose its resource and then objects of that
92resource. A slip in the resource then steered the object, so it was
93published valid but wrong. It now chooses the object and derives the
94resource.
95
96## The publish gate
97
98`rc_gate_register` adds one resident reaction per contract (faculty OMEGA).
99Its trigger is the draft object that cognition writes. It holds the only WRITE
100capability on the published object. It checks every draft again against the
101contract and the live World, applies only the repairs above, and either
102publishes all fields or records the rejection in its status object (verdict,
103first violated rule, violated constraint types, counts). A draft that
104produce accepted can still be rejected there: the World may have changed
105between generation and publication.
106
107Cognition holds WRITE on drafts and READ on what is published. A
108publication around the gate is refused by the authority. So is a reaction
109of cognition that presents the gate's capability.
110
111## Serialization
112
113- canonical binary (`rc_encode` / `rc_decode`): kind, contract identity, fields;
114- object identity: SHA-256 of that encoding, with the attached graph's digest;
115- JSON (`rc_to_json` / `rc_from_json`): one flat object. The parser is strict:
116 exact keys, unsigned decimal integers only, no duplicates, no unknown keys,
117 nothing after the object.
118
119## What the test proves
120
121| Claim | How |
122|---|---|
123| every constraint type is defined and caught | each type used by a contract; each type reported on a real violation |
124| the checker is right | every sweep candidate also judged by a hand-written reference per kind; zero disagreements; every single mistake reported under its own type |
125| compiled domains are sound | uniform draws inside every domain never violate a compiled rule |
126| compiled domains are complete | every field of every intended answer lies inside its domain given its own prefix |
127| impossible where fully compiled | constrained path: zero invalid candidates for every contract with no after-check rule |
128| never publish invalid | every published object re-read from the World and re-checked by contract and reference |
129| no bypass | cognition's direct write and a stolen-capability reaction both blocked; every published field written by its gate |
130| hostile drafts | every catalogued mistake written straight into the draft: rejected, or repaired only when repair is declared and restores the intended meaning |
131| stale before publication | a mutation target retired after generation is rejected by the gate as a generation violation |
132| unsatisfiable context | effect budget exhausted: constrained path stops with zero draws; free path spends every retry |
133| JSON is one serialization | binary and JSON round trips keep the identity; malformed texts refused; faulty JSON candidates caught |
134
135### Measures (per path, per kind, in the receipt)
136
137invalid candidate rate, repair rate, retries, draws and checks (compute),
138compute avoided (constrained against free), produce time and end-to-end
139latency (p50, p99), semantic failure rate (published objects whose
140meaning-bearing fields differ from the intended answer), rejected and
141unsatisfiable requests.
142
143### The backend
144
145The backend is synthetic. It has an intended answer (valid by construction)
146and makes mistakes at a fixed rate (35 % of candidates, a quarter of those
147with a second mistake) from a catalogue per kind. Each mistake is labelled
148with the constraint type it breaks, or "valid but wrong". Both paths see the
149same mistakes for the same request and attempt. Under a mask, a backend
150whose preferred value is not allowed takes its intended value if allowed,
151otherwise the nearest allowed one. That is the model of masked decoding the
152measures rest on.
153
154## Findings
155
156- Constraints guarantee validity, not truth. A valid-but-wrong answer passes
157 every contract on both paths and is counted as a semantic failure.
158- The constrained path's semantic failure rate is close to the free path's,
159 not lower. A mistake that breaks one field and silently changes another is
160 half-fixed by the mask and published. The free path rejects the whole
161 candidate and draws again. In this model, a retry often clears both.
162- Draws avoided are the compute saving that transfers to a backend whose
163 draw is expensive. The synthetic draw costs almost nothing. Computing
164 domains means World scans, authority validation and graph validation. So
165 here the constrained path is slower in wall-clock time, not faster: its
166 produce time is a few times the free path's, and end to end (gate
167 included) it is somewhat slower. It pays off only when one backend draw
168 costs more than one domain computation.
169
170## Limits
171
172- The backend is synthetic, not neural. No LLM or learned decoder is claimed.
173- AIEN's live R11 reactions do not yet write through the gate. Plan and
174 Hypothesis contracts use their exact layouts, so routing them is a wiring
175 step.
176- Domains have no lookahead. A choice can lead to an empty later domain, and
177 that costs a retry (counted as `dead_ends` in the receipt).
178- The gate validates an attached ActionGraph on a worker thread.
179 `rx_graph_validate` reads the World's object table without the world lock
180 (this predates this gate; TSan was clean on this workload).
181- The gate reads World objects outside its declared snapshot (for generation
182 and reference checks). An object retired between that read and the commit
183 is not re-checked at commit.
184- The evidence registry is bounded (256 records). Evidence it could not keep
185 cannot be cited.
186- Host processor only; the authority is the native C library, not the AIENOS
187 kernel.