Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/runtime/rx_r15_parity.c # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / runtime / rx_r15_parity.c` 277 lines · 13767 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_r15_parity.c -- R15 SEQ semantic parity gate (spec §16 C1 item 9). 19 * 20 * SEQ may serve as the R15 baseline only if it does the same semantic work. 21 * Each pair builds the R13 body twice from the same initial state, once as 22 * RES-1 and once as SEQ, and drives the same stimulus: placement A725, 23 * production requests with the §4 seed schedule, placement X925, and one 24 * goal with the same target. The side that runs first derives the target 25 * from AIEN's confirmed cost; the other is given it. Pairs alternate which 26 * side goes first. 27 * 28 * Gated, exactly equal between the two sides of every pair: goal, plan, 29 * search epoch, the verified selected realization, the GPU experiment 30 * evidence, AIEN's belief, generation identity, the in-force realization 31 * and the authority outcome. Gated on each side: goal MET, crumbs verify, 32 * no crumb overflow, no illegal transition, no wrong result, no use of a 33 * realization not in force, and no lost trigger. 34 * 35 * Both sides see the same costs: the rig gives Omega a fixed cost table 36 * (r15_use_cost_model) in place of wall-clock time, while the work itself 37 * still runs. Measured time differed between the two sides of a pair, and 38 * under machine load it crossed AIEN's and Omega's thresholds on one side 39 * only (a 20% miss read as drift opened an extra search; an X925 cost over 40 * the target left the goal UNMET), so a pair could differ for reasons that 41 * are not orchestration. With equal cost inputs any difference is the 42 * orchestration's. Costs are printed and not compared; the detector that 43 * reads them is also configured (see main) so that host timing noise cannot 44 * change a compared plan field. 45 * 46 * R15_PARITY_PAIRS (default 5) sets the number of pairs. 47 * Exit status 0 = SEQ_SEMANTIC_PARITY PASS. 48 */ 49 #include "rx_r15_rig.h" 50 51 #include 52 #include 53 #include 54 #include 55 56 #define U(x) ((unsigned long long)(x)) 57 58 static int g_fail; 59 60 static void check_side(int pair, const char *side, const R15Outcome *o, const char *first) { 61 const char *bad = NULL; 62 if (!o->ok) bad = "goal not MET"; 63 else if (!o->crumbs_verified) bad = "crumbs do not verify"; 64 else if (o->crumb_overflow) bad = "crumb log overflowed"; 65 else if (o->illegal) bad = "illegal lifecycle transition"; 66 else if (o->wrong) bad = "wrong production result"; 67 else if (o->unpromoted_use) bad = "production ran a realization not in force"; 68 else if (o->lost_triggers) bad = "lost trigger"; 69 else if (o->selected_verdict != RX_OMEGA_PASSED) bad = "selected realization not verified"; 70 else if (o->gen_after != o->gen_before + 1 && o->lineage_after != o->lineage_before + 1) 71 bad = "generation did not advance exactly once"; 72 else if (o->aegis_woken || o->root_woken) bad = "AEGIS or root woke during the episode"; 73 else if (o->promote_result != RX_GEN_OK) bad = "promotion refused"; 74 if (bad) { 75 g_fail++; 76 fprintf(stderr, " FAIL pair %d %s: %s%s%s\n", pair, side, bad, 77 first && first[0] ? " -- " : "", first ? first : ""); 78 } 79 } 80 81 #define SAME(name) do { \ 82 if (a->name != b->name) { \ 83 g_fail++; \ 84 fprintf(stderr, " FAIL pair %d: %s differs: RES-1 %llu, SEQ %llu\n", \ 85 pair, #name, U(a->name), U(b->name)); \ 86 } \ 87 } while (0) 88 #define SAME_ARR(name, n) do { \ 89 for (uint32_t j_ = 0; j_ < (n); j_++) \ 90 if (a->name[j_] != b->name[j_]) { \ 91 g_fail++; \ 92 fprintf(stderr, " FAIL pair %d: %s[%u] differs: RES-1 %llu, SEQ %llu\n", \ 93 pair, #name, j_, U(a->name[j_]), U(b->name[j_])); \ 94 } \ 95 } while (0) 96 97 static void compare(int pair, const R15Outcome *a, const R15Outcome *b) { 98 SAME(target_ns); 99 SAME(goal_seq); SAME(goal_regime); SAME(goal_status); SAME(goal_class); 100 SAME(plan_action); SAME(plan_regime); SAME(plan_condition); SAME(plan_reason); 101 SAME(plan_goal); 102 SAME(search_epoch); SAME(selection_epoch); SAME_ARR(selection_id, 4); 103 SAME(selection_regime); SAME(selected_verdict); 104 SAME_ARR(evidence, 5); 105 SAME_ARR(belief, 4); 106 SAME(gen_before); SAME(gen_after); SAME(lineage_before); SAME(lineage_after); 107 SAME(inforce_epoch); SAME_ARR(inforce_id, 4); SAME(inforce_regime); 108 SAME(inforce_generation); 109 SAME(promote_result); SAME(promotion_active); 110 SAME(aegis_woken); SAME(root_woken); 111 SAME(gpu_claims); SAME(seat_commits); 112 } 113 114 static int run_side(R15Config c, uint64_t target, R15Outcome *o, char *first, size_t n) { 115 R15Rig *r = calloc(1, sizeof *r); 116 if (!r) return -1; 117 int rc = r15_start(r, c); 118 if (rc != 0) snprintf(o->why, sizeof o->why, "setup failed at stage %d%s%s", r->stage, 119 r->stage_why ? ": " : "", r->stage_why ? r->stage_why : ""); 120 else rc = r15_episode(r, target, o); 121 if (rc == 0 && o->lost_triggers) r15_lost_triggers(r, first, n); 122 r15_stop(r); 123 free(r); 124 return rc; 125 } 126 127 static void print_side_tag(const char *side, const R15Outcome *o, const char *tag) { 128 printf(" %-5s%s goal status %llu, plan action %llu reason %llu, epoch %llu, " 129 "selected %016llx (verdict %llu), evidence %llu/%llu trials, belief %llu, " 130 "generation %llu -> %llu, in force %016llx; costs: incumbent %llu ns, " 131 "selected %llu ps, reference %llu ps, served %llu, crumbs %llu\n", 132 side, tag, U(o->goal_status), U(o->plan_action), U(o->plan_reason), U(o->selection_epoch), 133 U(o->selection_id[0]), U(o->selected_verdict), U(o->evidence[4]), U(o->evidence[3]), 134 U(o->belief[2]), U(o->gen_before), U(o->gen_after), U(o->inforce_id[0]), 135 U(o->incumbent_ns), U(o->selected_ps), U(o->reference_ps), U(o->served), 136 U(o->crumbs)); 137 } 138 139 static void print_side(const char *side, const R15Outcome *o) { print_side_tag(side, o, ""); } 140 141 /* The lost-trigger detector must see a trigger that did not run. With no 142 * run slots, a production request (it triggers workload.matvec.serve) is 143 * left unrun; the detector must count it. With slots back, the reaction runs 144 * and the count returns to zero. */ 145 static void detector_control(R15Config c) { 146 R15Rig *r = calloc(1, sizeof *r); 147 if (!r) { g_fail++; return; } 148 char first[200] = ""; 149 if (r15_start(r, c) != 0) { 150 g_fail++; 151 fprintf(stderr, " FAIL detector control %s: setup stage %d %s\n", r15_config_name(c), 152 r->stage, r->stage_why ? r->stage_why : ""); 153 r15_stop(r); 154 free(r); 155 return; 156 } 157 RxResourceBudget keep = r->w.budget, none = r->w.budget; 158 none.slots = 0; 159 rx_world_set_resources(&r->w, &none); 160 RxMutation m[4] = {{r->omega.o.request, 0, 1}, {r->omega.o.request, 1, R15_M}, 161 {r->omega.o.request, 2, R15_N}, 162 {r->omega.o.request, 3, 0x2545F4914F6CDD1Dull}}; 163 int pub = rx_world_publish_external(&r->w, r->ext_request, m, 4) > 0; 164 struct timespec ts = {0, 200000000L}; 165 nanosleep(&ts, NULL); 166 uint64_t starved = r15_lost_triggers(r, first, sizeof first); 167 rx_world_set_resources(&r->w, &keep); 168 int quiet = rx_world_wait_quiescent(&r->w, 10000) == RX_OK; 169 uint64_t after = r15_lost_triggers(r, NULL, 0); 170 printf(" detector control %s: starved %llu (%s), after slots restored %llu\n", 171 r15_config_name(c), U(starved), first, U(after)); 172 if (!pub || starved == 0 || !quiet || after != 0) { 173 g_fail++; 174 fprintf(stderr, " FAIL detector control %s\n", r15_config_name(c)); 175 } 176 r15_stop(r); 177 free(r); 178 } 179 180 int main(void) { 181 signal(SIGPIPE, SIG_IGN); 182 setvbuf(stdout, NULL, _IONBF, 0); 183 int pairs = getenv("R15_PARITY_PAIRS") ? atoi(getenv("R15_PARITY_PAIRS")) : 5; 184 if (pairs < 1) pairs = 1; 185 #ifdef R15_SILICON 186 printf("R15 SEQ parity: GB10 resident seat\n"); 187 #else 188 printf("R15 SEQ parity: processor stand-in seat (host)\n"); 189 #endif 190 /* Diagnostic only (not the gate): R15_PARITY_REPEAT=: 191 * runs n episodes of one configuration and reports each outcome, with 192 * measured (wall-clock) costs. */ 193 const char *rep = getenv("R15_PARITY_REPEAT"); 194 if (rep) { 195 R15Config c = strncmp(rep, "SEQ", 3) == 0 ? R15_SEQ 196 : strncmp(rep, "RES4", 4) == 0 ? R15_RES4 : R15_RES1; 197 const char *colon = strchr(rep, ':'); 198 int n = colon ? atoi(colon + 1) : 10, bad = 0; 199 for (int i = 0; i < n; i++) { 200 R15Outcome o; 201 char lost[200] = ""; 202 memset(&o, 0, sizeof o); 203 int rc = run_side(c, 0, &o, lost, sizeof lost); 204 if (rc != 0) bad++; 205 printf(" %s episode %d: %s%s incumbent %llu ns target %llu ns expected after " 206 "%llu ns (selected %llu ps, reference %llu ps) served %llu crumbs %llu\n", 207 r15_config_name(c), i, rc ? "FAIL " : "ok", rc ? o.why : "", 208 U(o.incumbent_ns), U(o.target_ns), U(o.final_expected_ns), 209 U(o.selected_ps), U(o.reference_ps), U(o.served), U(o.crumbs)); 210 } 211 printf("R15 repeat %s: %d of %d failed\n", r15_config_name(c), bad, n); 212 return bad ? 1 : 0; 213 } 214 r15_use_cost_model(1); 215 /* AIEN's drift detector reads Omega's serve costs; without the cost model 216 * above they are wall-clock. Under host 217 * load one side can see two consecutive intervals outside the tolerance, 218 * fail its prediction, and research the regime because of DRIFT (plan 219 * reason 2, condition A725, no goal) where the other side researches 220 * because of the GOAL (reason 3, condition X925, goal 1): the same work 221 * for a different reason, and the gate rightly fails. The stimulus here 222 * has no drift, so both sides get a detector whose miss streak cannot 223 * fail a prediction within an episode, and a hit band that one preempted 224 * baseline interval cannot defeat: within 20 percent of a baseline mean 225 * that one such interval inflated, a normal interval never lands, so 226 * the confirmation the episode waits for never comes. Everything else 227 * stays the product default and every compared field is still compared. */ 228 RxAienConfig ac; 229 rx_aien_default_config(&ac); 230 ac.misses_to_fail = UINT32_MAX; 231 ac.tolerance_pct = 99; 232 r15_set_aien_config(&ac); 233 detector_control(R15_RES1); 234 detector_control(R15_SEQ); 235 for (int p = 0; p < pairs; p++) { 236 R15Outcome res, seq; 237 char lost_res[200] = "", lost_seq[200] = ""; 238 memset(&res, 0, sizeof res); 239 memset(&seq, 0, sizeof seq); 240 int res_first = (p % 2) == 0; 241 int rc_a, rc_b; 242 if (res_first) { 243 rc_a = run_side(R15_RES1, 0, &res, lost_res, sizeof lost_res); 244 rc_b = rc_a == 0 ? run_side(R15_SEQ, res.target_ns, &seq, lost_seq, sizeof lost_seq) 245 : -1; 246 } else { 247 rc_b = run_side(R15_SEQ, 0, &seq, lost_seq, sizeof lost_seq); 248 rc_a = rc_b == 0 ? run_side(R15_RES1, seq.target_ns, &res, lost_res, sizeof lost_res) 249 : -1; 250 } 251 printf(" pair %d (%s first, target %llu ns)\n", p, res_first ? "RES-1" : "SEQ", 252 U(res_first ? res.target_ns : seq.target_ns)); 253 /* Print the numbers this pair produced, including the failing side's. 254 * A failure reason with no measurement behind it cannot be diagnosed: 255 * a side that stops early leaves zeroed fields, so its line is tagged. */ 256 if (rc_a == 0) print_side("RES-1", &res); 257 else if (res.why[0]) print_side_tag("RES-1", &res, " (at failure)"); 258 if (rc_b == 0) print_side("SEQ", &seq); 259 else if (seq.why[0]) print_side_tag("SEQ", &seq, " (at failure)"); 260 if (rc_a != 0 || rc_b != 0) { 261 g_fail++; 262 /* The second side runs only if the first completed; say so, or a 263 * blank reason reads as a pass. */ 264 const char *skipped = "not run: the first side failed"; 265 fprintf(stderr, " FAIL pair %d: episode did not complete: RES-1 [%s] SEQ [%s]\n", p, 266 rc_a ? (res.why[0] ? res.why : skipped) : "ok", 267 rc_b ? (seq.why[0] ? seq.why : skipped) : "ok"); 268 continue; 269 } 270 check_side(p, "RES-1", &res, lost_res); 271 check_side(p, "SEQ", &seq, lost_seq); 272 compare(p, &res, &seq); 273 } 274 printf("R15 SEQ parity: %d pairs, %d failures\n", pairs, g_fail); 275 printf("SEQ_SEMANTIC_PARITY=%s\n", g_fail ? "FAIL" : "PASS"); 276 return g_fail ? 1 : 0; 277 }