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 / src / runtime / rx_living.h

254 lines · 13110 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * rx_living.h -- R13: the faculties as one resident causal system (ADR 0016).
19 *
20 * Nothing here sequences the faculties. These are five more reactions on the
21 * caller's one RxWorld, each made ready only by the state it reads:
22 *
23 * living.experiment.prepare Omega search epoch taken up for an AIEN plan
24 * -> GPU input, trial 0
25 * living.blackwell.add GPU input -> GPU output field 0
26 * (the resident R12 seat; R5 admission, R7
27 * authority read from an R8 capability slot)
28 * living.experiment.evidence GPU output -> checked sum; the next trial
29 * until RX_LIVING_TRIALS, then evidence
30 * generation.prepare Omega selection + AIEN experiment belief
31 * -> R9 draft proposed, candidate object
32 * generation.promote candidate object -> rx_gen_promote under a
33 * separate subject; on success the in-force
34 * record production reads
35 * generation.restore (R14) body started -> the active R9 generation's
36 * bytes, verified again by Omega -> in-force record
37 *
38 * AIEN's belief about the evidence (rx_aien_register_experiment) and Omega's
39 * wait for that belief (rx_omega_require_evidence) live in those faculties.
40 * Production reads the in-force record (rx_omega_serve_from): Omega's
41 * selection is only eligible until the promotion authority promotes it.
42 *
43 * The GPU operation is R12's fixed add of fields 0 and 1 (low 32 bits). It is
44 * a physical witness of the experiment and its authority path. It is not the
45 * matvec realization and does not measure matvec cost.
46 */
47#ifndef RX_LIVING_H
48#define RX_LIVING_H
49
50#include "rx_aegis.h"
51#include "rx_aien.h"
52#include "rx_omega.h"
53#include "rx_generation.h"
54#include "rx_cortex_record.h"
55
56/* Objects in the caller's RxWorld. Not a second world, not a device namespace.
57 * input: 0 operand a, 1 operand b, 2 search epoch it is for, 3 trial,
58 * 4 plan seq
59 * output: 0 low 32 bits of input 0 + input 1 (GPU seat)
60 * evidence: 0 epoch (set when the experiment ends), 1 expected, 2 observed
61 * (last trial), 3 every trial matched (1), 4 trials matched
62 * candidate: 0 R9 candidate id, 1 epoch, 2..5 realization id, 6 regime,
63 * 7 selected ps per call (prepare)
64 * promotion: 0 candidate id taken up, 1 rx_gen_promote result (signed),
65 * 2 barrier ns, 3 active generation after (promote)
66 * inforce: selection layout: 0 epoch, 1..4 realization id, 5 ps per call,
67 * 6 regime, 7 generation it came from (promote) */
68/* Physical trials per experiment. Each is one claim on the resident seat
69 * under the same live grant. */
70#define RX_LIVING_TRIALS 16u
71#define RX_LIVING_RES_BASE 0x6130000ull
72enum { RX_LIVING_RES_INPUT, RX_LIVING_RES_OUTPUT, RX_LIVING_RES_EVIDENCE,
73 RX_LIVING_RES_CANDIDATE, RX_LIVING_RES_PROMOTION, RX_LIVING_RES_INFORCE,
74 RX_LIVING_RES_RESTORE };
75enum { RX_LIVING_SUBJ = 61, RX_LIVING_SEAT_SUBJ = 62,
76 RX_LIVING_PREPARE_SUBJ = 63, RX_LIVING_PROMOTE_SUBJ = 64 };
77enum { RX_OT_LIVING_INPUT = 0x6130, RX_OT_LIVING_OUTPUT,
78 RX_OT_LIVING_EVIDENCE, RX_OT_LIVING_CANDIDATE, RX_OT_LIVING_PROMOTION,
79 RX_OT_LIVING_INFORCE, RX_OT_LIVING_RESTORE };
80
81/* restore (R14): 0 boot sequence (outside: this body started), 1 boot taken
82 * up, 2 outcome, 3 active generation read, 4 realization id word 0 restored,
83 * 5 refusal reason, 6 lineage (restore) */
84enum { RX_LIVING_RESTORE_REFERENCE = 1, RX_LIVING_RESTORE_RESTORED,
85 RX_LIVING_RESTORE_REFUSED };
86/* Refusal reasons in restore field 5 besides an R9 or Omega code. */
87enum { RX_LIVING_RESTORE_WHY_CONFIG = 1, RX_LIVING_RESTORE_WHY_IDENTITY };
88
89typedef struct {
90 RxObjRef input, output, evidence, candidate, promotion, inforce;
91 RxObjRef restore; /* only after rx_living_register_restore */
92} RxLivingObjects;
93
94/* Durable provenance written into the R9 candidate. Each link is the causal
95 * crumb that last published that node and the crumb's digest. */
96enum { RX_LINK_GOAL, RX_LINK_PLAN, RX_LINK_SEARCH, RX_LINK_GPU_INPUT, RX_LINK_GPU_OUTPUT,
97 RX_LINK_EVIDENCE, RX_LINK_BELIEF, RX_LINK_SYNTH, RX_LINK_VERDICT, RX_LINK_MEASURE,
98 RX_LINK_SELECTION, RX_LINK_COUNT };
99typedef struct {
100 RxObjRef obj;
101 uint32_t reaction; /* UINT32_MAX for an outside publication */
102 uint64_t crumb;
103 uint8_t digest[32];
104} RxLivingLink;
105typedef struct {
106 char magic[8]; /* "R13PROV1" */
107 uint64_t epoch, goal_seq, plan_seq;
108 RxLivingLink link[RX_LINK_COUNT];
109} RxLivingProvenance;
110
111/* Configuration needed to rebuild the selected realization from its bytes. */
112typedef struct {
113 char magic[8]; /* "R13CONF1" */
114 uint64_t regime, margin_pct, kind, code_len;
115 uint8_t identity[32];
116} RxLivingConfig;
117
118typedef struct {
119 char magic[8]; /* "R13EVID1" */
120 uint64_t epoch, expected, observed;
121 uint64_t selected_ps, reference_ps, trials;
122} RxLivingEvidence;
123
124/* The lesson the body wrote into Cortex for one epoch (G1/N6); zero when no
125 * recorder was attached. Written by generation.prepare, read by
126 * generation.promote. */
127typedef struct {
128 uint64_t epoch, candidate, evidence_ref, promotion; /* promotion: 0 until recorded */
129 CxStore *store;
130 uint8_t digest[32]; /* rx_living_object_digest of the evidence object */
131} RxLivingLesson;
132
133typedef struct {
134 /* living.experiment.prepare (RX_LIVING_SUBJ) */
135 RxCapRef plan_read, search_read, input_write;
136 /* living.blackwell.add (RX_LIVING_SEAT_SUBJ); output WRITE is in the slot */
137 RxCapRef input_seat_read;
138 RxObjRef output_slot;
139 RxCapRef output_slot_read;
140 /* living.experiment.evidence (RX_LIVING_SUBJ) */
141 RxCapRef output_read, evidence_write;
142 /* generation.prepare (RX_LIVING_PREPARE_SUBJ) */
143 RxCapRef selection_read, belief_read, evidence_prepare_read, candidate_write;
144 RxCapRef goal_prepare_read, plan_prepare_read, search_prepare_read, output_prepare_read;
145} RxLivingCaps;
146
147/* Kept apart from the proposer. Only generation.promote gets this context,
148 * and only the native authority can validate its promotion right. */
149typedef struct {
150 RxWorld *world;
151 RxGenStore *store;
152 const struct AienosCapView *authority;
153 RxObjRef candidate, promotion, inforce;
154 RxLivingLesson *lesson; /* the proposer's lesson record (set by rx_living_register) */
155 RxCapRef candidate_read, promotion_write, inforce_write, promotion_authority;
156 uint32_t reaction;
157 int result;
158 /* R16 C5: the promotion subject's credential (rx_caller.h), apart from
159 * the proposer's; null in a world without bound callers. */
160 const RxCallerKeyring *keys;
161} RxLivingPromoter;
162
163typedef struct {
164 RxWorld *world;
165 RxAienFaculty *aien;
166 RxOmegaFaculty *omega;
167 RxGenStore *store;
168 const struct AienosCapView *authority;
169 RxLivingObjects o;
170 RxLivingCaps caps;
171 uint32_t r_prepare, r_seat, r_evidence, r_candidate, r_restore;
172 /* An R9 proposal is an effect outside the world. If the reaction that
173 * made it is invalidated and runs again for the same epoch, it reuses
174 * the proposal instead of making a second one. */
175 uint64_t proposed_epoch, candidate_id;
176 RxLivingLesson lesson;
177 uint64_t refusals; /* observability: why nothing was proposed */
178 int last_refusal;
179 /* R16 C5: credentials of the living subjects other than the promotion
180 * subject (rx_caller.h); null in a world without bound callers. */
181 const RxCallerKeyring *keys;
182} RxLiving;
183
184/* Why generation.prepare declined (last_refusal). Never a semantic decision
185 * by the harness; these are the reaction's own checks. */
186enum { RX_LIVING_WHY_AUTHOR = 1, RX_LIVING_WHY_STORE, RX_LIVING_WHY_CHAIN,
187 RX_LIVING_WHY_GRANT, RX_LIVING_WHY_PROPOSE };
188
189int rx_living_create(RxLiving *l, RxWorld *w, RxAienFaculty *aien,
190 RxOmegaFaculty *omega, RxGenStore *store,
191 const struct AienosCapView *authority);
192int rx_living_register(RxLiving *l, const RxLivingCaps *caps,
193 RxLivingPromoter *promoter);
194
195/* R14. generation.restore: the promotion subject rebuilds the in-force record
196 * from R9 when the body starts. Woken by an outside publication of a new boot
197 * sequence into restore field 0 (the body starting is an outside event). It
198 * reads the active generation's realization, config and evidence through
199 * rx_gen_read_blob, has Omega verify the bytes again (rx_omega_readmit), and
200 * only then names them in force. Genesis leaves production on the reference;
201 * anything that does not check out is refused and also leaves the reference.
202 * `restore_write` is RW on RX_LIVING_RES_RESTORE for RX_LIVING_PROMOTE_SUBJ.
203 * Creates the restore object. Call after rx_living_register. */
204int rx_living_register_restore(RxLiving *l, RxLivingPromoter *promoter, RxCapRef restore_write);
205/* R16 C6: the production subjects' runtime-issued caller credentials, one
206 * keyring per component; each component holds only its own. */
207typedef struct {
208 RxCallerKeyring omega; /* RX_OMEGA_SUBJ_SERVE, RX_OMEGA_SUBJ_OMEGA */
209 RxCallerKeyring aien; /* RX_AIEN_SUBJ */
210 RxCallerKeyring aegis; /* RX_AEGIS_SUBJ, RX_AEGIS_ROOT_SUBJ */
211 RxCallerKeyring living; /* RX_LIVING_SUBJ, _SEAT_SUBJ, _PREPARE_SUBJ */
212 RxCallerKeyring promoter; /* RX_LIVING_PROMOTE_SUBJ */
213} RxLivingKeyrings;
214/* Enrolls every production subject into w (rx_world_enroll_caller) and sets
215 * one keyring per component (the faculties' .keys pointers are set by the
216 * caller). Does not bind: the caller enrolls any further subjects, then calls rx_world_bind_callers. */
217int rx_living_enroll_callers(RxWorld *w, RxLivingKeyrings *k);
218/* The native promotion authority (aienos_cap_validate on an AienosCapView as
219 * ctx), for rx_gen_bind_authority. */
220int rx_living_native_authority(void *ctx, uint32_t cap_id, uint64_t generation,
221 uint32_t subject, uint64_t resource, uint32_t rights);
222
223/* Same content digest the world gives an object: SHA-256 over
224 * "AIEN_RX_OBJECT_V1", type and the eight fields. */
225void rx_living_object_digest(uint32_t type, const uint64_t field[RX_MAX_FIELDS],
226 uint8_t out[32]);
227
228/* ---- Cortex journal of the experience (G1) ----------------------------------
229 * A lesson is a CX_K_CANDIDATE. It becomes a fact only through
230 * rx_living_lesson_promote, which refuses unless the evidence record is a
231 * CX_K_EVIDENCE_REF that verifies and whose payload words
232 * RX_LIVING_EV_DIGEST0.. hold `object_digest`, the rx_living_object_digest of
233 * the R13 evidence object. cx_promote alone only checks record kinds. */
234enum { RX_LIVING_EV_DIGEST0 = 0, RX_LIVING_EV_CRUMB = 4, RX_LIVING_EV_WORDS = 5 };
235/* RX_OK, RX_ERR_NOT_FOUND (no such record), RX_ERR_ARG (wrong kind or digest
236 * mismatch), RX_ERR_IDENTITY (record fails its digest check). */
237int rx_living_lesson_evidence_ok(const CxStore *s, uint64_t evidence, const uint8_t object_digest[32]);
238/* The gate above, then rx_cortex_promote_in on the attached writer of `s`. */
239int rx_living_lesson_promote(RxWorld *w, CxStore *s, uint64_t candidate, uint64_t evidence,
240 const uint8_t object_digest[32], uint64_t *out_id);
241/* Layout of the CX_K_CANDIDATE lesson generation.prepare writes (words):
242 * the RxLivingEvidence, the realization id (4), the regime, the condition key
243 * rx_aien_key(core class, regime). Its subject is the evidence object slot + 1,
244 * its tag the epoch; links {experiment belief, evidence ref, evidence}. */
245enum { RX_LIVING_LESSON_REALIZATION = 7, RX_LIVING_LESSON_REGIME = 11, RX_LIVING_LESSON_KEY = 12,
246 RX_LIVING_LESSON_WORDS = 13 };
247/* Condition keys of the PROMOTED lessons about `subject` (typed recall of
248 * CX_K_PROMOTION; each promotion, its candidate and its evidence ref must
249 * verify and agree). An un-promoted candidate contributes nothing. Up to
250 * `max` distinct keys, oldest first; returns the number. Call when no writer
251 * is appending (restart, or before the body runs). */
252uint32_t rx_living_explored_keys(CxStore *s, uint64_t subject, uint64_t *keys, uint32_t max);
253
254#endif