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 / tests / runtime / rx_r15_rig.h
| 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_r15_rig.h -- the R13 living body built for an R15 configuration |
| 19 | * (spec/r15-performance-proof.md §3, §4). Shared by the SEQ parity gate and |
| 20 | * the R15 harness so both drive exactly the same objects, reactions, |
| 21 | * authority, crumbs, R9 store and seat. |
| 22 | * |
| 23 | * RES-4 / RES-1: rx_world_init_native with 4 / 1 workers; a transport thread |
| 24 | * moves seat completions into the world (it decides nothing). |
| 25 | * SEQ: rx_world_init_native_sequential_reference; one orchestrator thread |
| 26 | * runs rx_seq_pulse over the §2.2 faculty order, rebuilt whenever a |
| 27 | * reaction is registered, and host-waits for each GPU claim. |
| 28 | * |
| 29 | * The harness side only publishes outside stimuli (placement, goal, |
| 30 | * production requests) and reads objects. It never calls a faculty. |
| 31 | */ |
| 32 | #ifndef RX_R15_RIG_H |
| 33 | #define RX_R15_RIG_H |
| 34 | |
| 35 | #include "runtime/rx_living.h" |
| 36 | #include "runtime/rx_resident_gpu.h" |
| 37 | #include "runtime/rx_seq_reference.h" |
| 38 | |
| 39 | #include <pthread.h> |
| 40 | #include <sched.h> |
| 41 | #include <stdatomic.h> |
| 42 | #include "r15_stage_clock.h" |
| 43 | |
| 44 | typedef enum { R15_RES4, R15_RES1, R15_SEQ } R15Config; |
| 45 | |
| 46 | #define R15_M 64u |
| 47 | #define R15_N 256u |
| 48 | #define R15_CLASS_A725 0xd87u |
| 49 | #define R15_CLASS_X925 0xd85u |
| 50 | |
| 51 | typedef struct { |
| 52 | R15Config config; |
| 53 | AienosCapAdmin *admin; |
| 54 | AienosCapView *view; |
| 55 | RxWorld w; |
| 56 | RxOmegaFaculty omega; |
| 57 | RxAienFaculty aien; |
| 58 | RxAegisFaculty aegis; |
| 59 | RxLiving living; |
| 60 | RxLivingPromoter promoter; |
| 61 | RxGenStore *gen; |
| 62 | RxGpuSeat *seat; |
| 63 | RxObjRef intent; |
| 64 | RxCapRef ext_request, ext_goal, ext_placement, ext_intent; |
| 65 | RxCapRef seat_input, seat_output; |
| 66 | uint32_t r_ask; |
| 67 | uint64_t minted; |
| 68 | char generation_dir[128]; |
| 69 | /* production client */ |
| 70 | uint64_t request_seq, served, wrong, unpromoted_use; |
| 71 | pthread_t producer; |
| 72 | atomic_int producer_stop, producer_error; |
| 73 | int producer_live; |
| 74 | char serve_why[320]; /* why the last failed request failed */ |
| 75 | /* RES: completion transport */ |
| 76 | pthread_t transport; |
| 77 | atomic_int transport_stop, transport_error; |
| 78 | int transport_live; |
| 79 | /* SEQ: orchestrator */ |
| 80 | pthread_t orchestrator; |
| 81 | atomic_int orch_stop, orch_error; |
| 82 | int orch_live; |
| 83 | uint32_t order[RX_MAX_REACTIONS]; |
| 84 | RxSeqPlan plan; |
| 85 | uint32_t plan_for; /* n_reactions the plan was built for */ |
| 86 | /* lost-trigger baseline, taken when the body is built */ |
| 87 | uint64_t baseline[RX_MAX_REACTIONS][RX_MAX_DEPS]; |
| 88 | int stage; /* setup stage reached, for diagnostics */ |
| 89 | const char *stage_why; /* which step of that stage failed, if known */ |
| 90 | /* R15 harness: optional measurement points inside r15_episode (all NULL |
| 91 | * for the parity gate, which then runs exactly as before). */ |
| 92 | const struct R15Hooks *hooks; |
| 93 | int64_t goal_crumb; /* crumb of the goal publication */ |
| 94 | /* R16 G4: runtime-issued caller credentials, one keyring per faculty |
| 95 | * (each holds only its own subjects), plus harness fixture subjects. */ |
| 96 | RxCallerKeyring keys_omega, keys_aien, keys_aegis, keys_living, keys_promoter; |
| 97 | RxCallerKeyring keys_rig; /* the rig's own R8 ask reaction (seat subject) */ |
| 98 | RxCallerKeyring fixtures; /* r15_start_with fixture subjects */ |
| 99 | R15StageClock stop_clock; /* time stamps of each r15_stop step (teardown diagnostics, reported only) */ |
| 100 | int leave_valid; /* r15_stop read the seat's words at finish */ |
| 101 | int leave_rc; /* rx_gpu_seat_finish_ex return, 0 = clean */ |
| 102 | uint32_t leave_marker, leave_sem; /* what the host read (stale or missing reads show here) */ |
| 103 | } R15Rig; |
| 104 | |
| 105 | /* Called on the episode's thread; a nonzero return fails the episode. |
| 106 | * idle: A725, confirmed, producer not yet running (idle baseline); |
| 107 | * before: A725, producer running (BEFORE window); |
| 108 | * after: X925, goal MET on the in-force record, producer still running |
| 109 | * (AFTER window). */ |
| 110 | typedef struct R15Hooks { |
| 111 | int (*idle)(struct R15Hooks *h, R15Rig *r); |
| 112 | int (*before)(struct R15Hooks *h, R15Rig *r); |
| 113 | int (*after)(struct R15Hooks *h, R15Rig *r); |
| 114 | void *ctx; |
| 115 | } R15Hooks; |
| 116 | |
| 117 | /* Semantic outcome of one W-EPISODE. Exact fields must agree between |
| 118 | * configurations; `measured` fields are timing and are only reported. */ |
| 119 | typedef struct { |
| 120 | int ok; /* the episode ran to goal MET */ |
| 121 | char why[480]; |
| 122 | uint64_t target_ns; |
| 123 | /* exact */ |
| 124 | uint64_t goal_seq, goal_regime, goal_status, goal_class; |
| 125 | uint64_t goal_status_final; /* after the AFTER window (hooks only); reported */ |
| 126 | uint64_t plan_action, plan_regime, plan_condition, plan_reason, plan_goal; |
| 127 | uint64_t search_epoch, selection_epoch, selection_id[4], selection_regime; |
| 128 | uint64_t selected_verdict; /* verdict state of the slot that produced it */ |
| 129 | uint64_t evidence[5]; |
| 130 | uint64_t belief[4]; |
| 131 | uint64_t gen_before, gen_after, lineage_before, lineage_after; |
| 132 | uint64_t inforce_epoch, inforce_id[4], inforce_regime, inforce_generation; |
| 133 | int64_t promote_result; |
| 134 | uint64_t candidate_id, promotion_candidate, promotion_active; |
| 135 | uint64_t aegis_woken, root_woken; |
| 136 | uint64_t gpu_claims, seat_commits; |
| 137 | /* integrity */ |
| 138 | uint64_t crumbs_checked, crumb_overflow, illegal, wrong, unpromoted_use; |
| 139 | uint64_t lost_triggers; |
| 140 | int crumbs_verified; |
| 141 | /* measured (reported only) */ |
| 142 | uint64_t incumbent_ns, selected_ps, reference_ps, inforce_ps, final_expected_ns; |
| 143 | uint64_t plan_seq, served, crumbs; |
| 144 | /* per Omega slot, last search epoch (reported only): verdict state, |
| 145 | * measure state, candidate ps, reference ps measured in the same rounds */ |
| 146 | uint64_t slot_verdict[RX_OMEGA_SLOTS], slot_measure[RX_OMEGA_SLOTS]; |
| 147 | uint64_t slot_cps[RX_OMEGA_SLOTS], slot_rps[RX_OMEGA_SLOTS]; |
| 148 | } R15Outcome; |
| 149 | |
| 150 | /* The AIEN detector configuration the next r15_start uses (rx_aien_default_config |
| 151 | * when none is set; NULL clears it). The SEQ parity gate sets one whose miss streak |
| 152 | * cannot fail a prediction within an episode: its stimulus has no drift, so a failed |
| 153 | * prediction there can only come from host timing noise in Omega's serve costs, and |
| 154 | * it makes one side research the regime because of DRIFT where the other does so |
| 155 | * because of the GOAL. G7 and the R15 harness leave the product default. */ |
| 156 | void r15_set_aien_config(const RxAienConfig *cfg); |
| 157 | int r15_start(R15Rig *r, R15Config config); |
| 158 | /* As r15_start, and also enrolls up to RX_CALLER_KEYRING_MAX fixture subjects |
| 159 | * (harness-only callers) before the world's caller set is bound; their |
| 160 | * credentials are in r->fixtures. */ |
| 161 | int r15_start_with(R15Rig *r, R15Config config, const uint32_t *fixture_subjects, |
| 162 | uint32_t n_fixtures); |
| 163 | /* Runs the §4 episode shape without measurement windows: A725 warm-up until |
| 164 | * Omega's first selection and AIEN's confirmed prediction; production |
| 165 | * running; X925 placement and goal; until promotion; until AIEN assesses the |
| 166 | * goal MET on the in-force record; production stopped; quiescent. |
| 167 | * target_ns = 0 derives the goal from AIEN's confirmed cost (TARGET 55%); |
| 168 | * otherwise it is used as given (the parity gate gives both sides one). */ |
| 169 | int r15_episode(R15Rig *r, uint64_t target_ns, R15Outcome *out); |
| 170 | void r15_stop(R15Rig *r); |
| 171 | /* Mint a grant from the rig's authority (harness stimuli only). */ |
| 172 | RxCapRef r15_mint(R15Rig *r, uint32_t subject, uint64_t resource, uint32_t rights); |
| 173 | /* The closed-loop production client, outside an episode (L1/L2 only). */ |
| 174 | int r15_producer_start(R15Rig *r); |
| 175 | int r15_producer_stop(R15Rig *r); /* -1 if a request failed */ |
| 176 | int r15_placement(R15Rig *r, uint32_t cls); |
| 177 | /* Confine every thread of the process to one core class. */ |
| 178 | int r15_move_class(uint32_t cls); |
| 179 | const char *r15_config_name(R15Config c); |
| 180 | /* Rigs started after this call (on = 1) give Omega a fixed cost table in |
| 181 | * place of wall-clock time for serve and measure, so every rig sees the same |
| 182 | * costs whatever the machine's load. The SEQ parity gate uses it for its |
| 183 | * detector controls and pairs; every other rig user (G7, the R15 harness, |
| 184 | * R16 negative) keeps measured costs (default off). */ |
| 185 | void r15_use_cost_model(int on); |
| 186 | |
| 187 | /* Reactions whose last activation read an older version of a trigger field |
| 188 | * than the one now in the world (changes after the build baseline), in a |
| 189 | * quiescent world. Such a trigger was lost. Quarantined reactions and |
| 190 | * retired trigger objects are exempt and not counted. */ |
| 191 | uint64_t r15_lost_triggers(R15Rig *r, char *first, size_t n); |
| 192 | |
| 193 | #endif |