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/src/runtime/rxc_host_abi.h # 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 / src / runtime / rxc_host_abi.h` 309 lines ยท 16919 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 * rxc_host_abi.h -- NEXT-PHASE-1 cut 1a: a thin C ABI over COMPOSITION-2 19 * (rx_compose) for a host program in another language (the sovereign-core 20 * aien-omega-compose crate). 21 * 22 * A FACADE, nothing more: open = rx_compose_open on a fresh AIENOS authority, 23 * run = rx_compose_run, recall = cx_recall / cx_recall_id on the composition's 24 * own Cortex journal (/cortex.cx), close = rx_compose_close. No new 25 * scheduler, store or receipt format. The record of a run is the ordinary 26 * COMPOSITION-2 Cortex record (rx_compose.h): candidate claims, the AEGIS 27 * verification evidence, one promotion, one admission per loser. 28 * 29 * Pointer-light: one opaque handle, plain fixed-size structs, no pointer is 30 * kept from the caller except the skill/verify ctx it registers. 31 * 32 * Lifecycle: 33 * rxc_host_open identity check + Cortex torn-tail probe; nothing runs yet 34 * rxc_host_register_skill (0..RXC_HOST_MAX_SKILLS times) 35 * first rxc_host_run / rxc_host_recall / rxc_host_info: the Skill graph is 36 * built and the composition opens (OLD-or-NEW recovery). Registration 37 * closes here (RXC_HOST_E_STATE afterwards). 38 * rxc_host_close 39 * 40 * Skills. A Skill is a host callback; the composition calls it on a World 41 * worker thread with the run's task handle (the 64-bit `task` given to 42 * rxc_host_run, which the host maps to its own goal text). It returns 0 and 43 * a nonzero 64-bit result (a proposal handle the host can resolve), or 44 * nonzero to report failure. Up to RXC_K (2) Skills compete per goal; two 45 * may run at once, so the callback must be thread-safe. Every Skill is 46 * pinned to a 32-byte procedure digest (default: sha256 of its name). 47 * 48 * Verification. The AEGIS verifier enforces a contract on (task, result). 49 * With a verify callback the host decides (1 = meets the contract); without 50 * one the contract is "result != 0". The callback runs on a World worker. 51 * 52 * Bounds: RXC_HOST_MAX_HANDLES open handles per process (the composition 53 * contract and Skill functions take no user pointer, so each handle owns a 54 * fixed slot of trampolines). One handle per directory (the Cortex journal 55 * takes an exclusive writer lock; a second open of the same dir from any 56 * process fails at the first run with RXC_HOST_E_OPEN). 57 * 58 * Torn journal tail (cut 2: strict by default, repair only on request). 59 * rxc_host_open probes /cortex.cx read-only. If the journal ends 60 * inside a record it refuses with RXC_HOST_E_TORN (info->tail_torn = 1) and 61 * leaves every byte on disk as it was. A journal cut at a record boundary 62 * inside the committed prefix opens, and the first run/recall/info refuses 63 * with RXC_HOST_E_REPLAY (open_rc = RX_ERR_REPLAY: the journal is behind the 64 * J-Space checkpoint anchor). Neither refusal is permanent: the operator 65 * calls rxc_host_recover, which truncates the torn record 66 * (CX_OPEN_REPAIR_TAIL), keeps the cut bytes inside an explicit repair 67 * record (RXC_HOST_TAG_REPAIR_TAIL: byte range, dropped record count, sha256 68 * of the cut, the old anchor), re-anchors the J-Space checkpoint on the 69 * repaired journal, and returns the home to a state rxc_host_open accepts. 70 * rx_compose_open then answers any composition record the cut interrupted 71 * (rollback / recovered admissions, RxcHostInfo.rolled_back and 72 * recovered_completed). No open ever cuts the journal by itself. 73 * 74 * Host records (cut 2). rxc_host_note appends one operator record (a 75 * constraint, an authorization, an effect receipt) through the 76 * composition's own Cortex writer (rx_cortex_append_in on the attached 77 * link, exactly as rx_compose writes its candidates), on subject 78 * RXC_HOST_SUBJECT_HOST (0 = no World object), between runs. 79 * 80 * Production only: this file is part of build/librx_compose.a, which is 81 * built without AIEN_TEST_BUILD / RXC_TEST_HOOKS (mk/rx_compose_lib.mk). 82 */ 83 #ifndef RXC_HOST_ABI_H 84 #define RXC_HOST_ABI_H 85 86 #include 87 #include 88 89 #ifdef __cplusplus 90 extern "C" { 91 #endif 92 93 #define RXC_HOST_ABI_VERSION 2u /* 2: strict torn refusal, recover, note */ 94 #define RXC_HOST_MAX_HANDLES 4u 95 #define RXC_HOST_MAX_SKILLS 2u /* = RXC_K */ 96 #define RXC_HOST_NAME_MAX 64u 97 #define RXC_HOST_NONE 0xFFFFFFFFu /* winner: none */ 98 99 enum { 100 RXC_HOST_OK = 0, 101 RXC_HOST_E_ARG = -1, 102 RXC_HOST_E_IDENTITY = -2, /* machine.id in dir names another machine, or bad root */ 103 RXC_HOST_E_TORN = -3, /* journal ends inside a record (CX_ERR_TORN): rxc_host_recover */ 104 RXC_HOST_E_OPEN = -4, /* rx_compose_open refused (see RxcHostInfo.open_rc) */ 105 RXC_HOST_E_FULL = -5, /* RXC_HOST_MAX_HANDLES / RXC_HOST_MAX_SKILLS reached */ 106 RXC_HOST_E_STATE = -6, /* wrong lifecycle phase (registration closed, no Skill) */ 107 RXC_HOST_E_RUN = -7, /* rx_compose_run returned an error (RxcHostResult.run_rc) */ 108 RXC_HOST_E_NOMEM = -8, 109 RXC_HOST_E_NOT_FOUND = -9, /* recall: no such record */ 110 RXC_HOST_E_DIGEST = -10, /* recall: stored digest does not match the record */ 111 RXC_HOST_E_REPLAY = -11 /* journal behind / unlike the J-Space anchor, or a recorded state 112 is not durable (RX_ERR_REPLAY): rxc_host_recover */ 113 }; 114 115 /* rxc_host_open flags: none defined in ABI 2 (must be 0). The cut-1 flag 116 * RXC_HOST_OPEN_REFUSE_TORN is now the only behaviour. */ 117 118 /* Machine root kinds (= AIEN_MID_ROOT_*). */ 119 enum { RXC_HOST_ROOT_PROVISIONED = 1, RXC_HOST_ROOT_HARDWARE = 2 }; 120 121 /* Cortex subjects of the composition record (= RXC_CX_SUBJECT(slot)). */ 122 #define RXC_HOST_SUBJECT_GOAL 1ull 123 #define RXC_HOST_SUBJECT_STATE 5ull /* candidates, evidence, promotion, admissions */ 124 #define RXC_HOST_SUBJECT_HOST 0ull /* host records (rxc_host_note, repair): no World object */ 125 126 /* Host record tags (subject RXC_HOST_SUBJECT_HOST). */ 127 enum { 128 RXC_HOST_TAG_REPAIR_TAIL = 1, /* EVIDENCE / CX_K_ADMISSION: the cut admitted by recover */ 129 RXC_HOST_NOTE_CONSTRAINT = 2, /* CLAIM / CX_K_CLAIM: an operator constraint */ 130 RXC_HOST_NOTE_AUTHORIZATION = 3, /* EVIDENCE / CX_K_ADMISSION: an approval for one effect */ 131 RXC_HOST_NOTE_EFFECT = 4 /* EVIDENCE / CX_K_EVIDENCE_REF: an effect receipt */ 132 }; 133 /* Note payload: [0] byte length, [1..5) sha256 of the bytes (LE words), then 134 * the bytes packed little-endian, 8 per word. */ 135 #define RXC_HOST_NOTE_MAX 16384u 136 #define RXC_HOST_NP_LEN 0u 137 #define RXC_HOST_NP_SHA 1u 138 #define RXC_HOST_NP_BYTES 5u 139 /* Repair payload (RXC_HOST_TAG_REPAIR_TAIL). */ 140 enum { 141 RXC_HOST_RP_CUT_LO = 0, /* journal byte range cut: [lo, hi) */ 142 RXC_HOST_RP_CUT_HI, 143 RXC_HOST_RP_PARTIAL, /* incomplete trailing records truncated (0 or 1) */ 144 RXC_HOST_RP_ANCHOR, /* records the J-Space anchor named (0 = no anchor) */ 145 RXC_HOST_RP_KEPT, /* complete records kept */ 146 RXC_HOST_RP_DROPPED, /* records lost: max(kept + partial, anchor) - kept */ 147 RXC_HOST_RP_CAUSE, /* CX_ERR_TORN or RX_ERR_REPLAY (as int64) */ 148 RXC_HOST_RP_CUT_SHA, /* 4 words: sha256 of the cut bytes */ 149 RXC_HOST_RP_ANCHOR_HEAD = RXC_HOST_RP_CUT_SHA + 4, /* 4 words: old anchor head digest */ 150 RXC_HOST_RP_KEPT_BYTES = RXC_HOST_RP_ANCHOR_HEAD + 4, /* cut bytes stored below */ 151 RXC_HOST_RP_BYTES /* the cut bytes, packed LE */ 152 }; 153 #define RXC_HOST_REPAIR_KEEP_MAX 65536u 154 155 /* Composition outcomes (= RXC_OUT_*). */ 156 enum { 157 RXC_HOST_OUT_COMMITTED = 1, RXC_HOST_OUT_NO_WINNER = 2, RXC_HOST_OUT_NOT_COMMITTED = 3, 158 RXC_HOST_OUT_NOT_DURABLE = 4, RXC_HOST_OUT_RECORD_FAILED = 5 159 }; 160 161 typedef struct RxcHost RxcHost; 162 163 /* 0 + *result (nonzero) = proposal; nonzero return = the Skill failed. */ 164 typedef int (*RxcHostSkillFn)(void *ctx, uint64_t task, uint64_t *result); 165 /* 1 = result meets the contract for task, 0 = it does not. */ 166 typedef int (*RxcHostVerifyFn)(void *ctx, uint64_t task, uint64_t result); 167 168 typedef struct { 169 uint32_t abi_version; /* RXC_HOST_ABI_VERSION */ 170 uint8_t machine_root; /* RXC_HOST_ROOT_* */ 171 uint8_t machine_id[32]; /* AienMachineId.id: identical across restarts */ 172 uint32_t machine_id_was_stored; /* 1: dir already held machine.id (and it matched) */ 173 uint32_t tail_torn; /* 1: cortex.cx ended inside a record at open */ 174 uint32_t opened; /* 1: the composition is open (first run/recall/info) */ 175 int32_t open_rc; /* rx_compose_open return (0 = RX_OK) */ 176 uint64_t records; /* Cortex records now */ 177 uint64_t recovered_record; /* Cortex id naming the recovered state (0 = genesis) */ 178 uint32_t rolled_back; /* newer records refused at open (rollback admissions) */ 179 uint32_t recovered_completed; /* composition records completed at open */ 180 uint32_t anchor_unknown; /* 1: no Cortex anchor in the checkpoint (audit only) */ 181 uint32_t n_skills; 182 } RxcHostInfo; 183 184 typedef struct { 185 int32_t run_rc; /* rx_compose_run return (0 = RX_OK) */ 186 int32_t outcome; /* RXC_HOST_OUT_* */ 187 uint32_t committed; /* 1 iff outcome == COMMITTED (NEW committed, durable) */ 188 uint32_t n_branches; /* staged J-Space branches forked (= routed alternatives) */ 189 uint32_t branches_reclaimed; /* staged branches reclaimed at settle */ 190 uint32_t winner; /* index of the winning alternative, RXC_HOST_NONE = none */ 191 uint32_t winner_skill; /* host Skill index of the winner, RXC_HOST_NONE = none */ 192 uint32_t aegis_pass_mask; /* bit k: alternative k met the contract (AEGIS verdict) */ 193 uint64_t task; 194 uint64_t result; /* the committed result (winner's), 0 if none */ 195 uint64_t cx_goal; /* Cortex id of the goal record (0 if none) */ 196 uint64_t cx_candidate[2]; /* Cortex ids, 0 = none */ 197 uint64_t cx_evidence; /* AEGIS verification evidence */ 198 uint64_t cx_promotion; 199 uint64_t cx_admission[2]; 200 uint8_t winner_digest[32]; /* J-Space content digest of the committed branch */ 201 uint8_t record_digest[32]; /* rx_compose_record_digest after the run */ 202 } RxcHostResult; 203 204 typedef struct { 205 uint64_t id; 206 uint32_t cls, kind; /* CxClass, CX_K_* */ 207 uint64_t subject, t, generation, tag; 208 uint64_t links[4]; 209 uint32_t n_payload; /* payload words (read with rxc_host_payload) */ 210 uint32_t verified; /* 1: digest recomputed and matched */ 211 uint8_t digest[32]; 212 } RxcHostRecord; 213 214 /* What rxc_host_recover found and did. */ 215 typedef struct { 216 uint32_t repaired; /* 1: journal cut and/or anchor reset, repair record written */ 217 uint32_t tail_torn; /* 1: journal ended inside a record */ 218 uint32_t anchor_present; /* 1: the checkpoint held a Cortex anchor */ 219 int32_t cause; /* CX_ERR_TORN (-8), RX_ERR_REPLAY (-21), 0 = nothing to do */ 220 uint32_t opens; /* 1: a trial open of the composition succeeded after */ 221 int32_t open_rc; /* that trial open's rx_compose_open return */ 222 uint32_t rolled_back; /* trial open: newer state records answered with rollback */ 223 uint32_t recovered_completed; /* trial open: interrupted composition records completed */ 224 uint64_t cut_lo, cut_hi; /* journal bytes cut: [cut_lo, cut_hi) */ 225 uint64_t partial_records; /* incomplete trailing records truncated */ 226 uint64_t anchor_records; /* records the anchor named before the repair */ 227 uint64_t records_kept; /* complete records kept (an unchanged prefix) */ 228 uint64_t dropped_records; /* records lost to the cut */ 229 uint64_t event_id; /* Cortex id of the repair record (0 = none) */ 230 uint64_t cut_bytes_kept; /* cut bytes stored in the repair record */ 231 uint8_t cut_sha256[32]; 232 uint8_t anchor_head[32]; /* the old anchor's head digest */ 233 } RxcHostRepair; 234 235 /* Open (or create) the composition home `dir` (made 0700 if absent) for 236 * the machine derived from (root_kind, root[0..root_len)). Identity: a dir 237 * that already holds machine.id must hold this machine (RXC_HOST_E_IDENTITY 238 * otherwise). `info` (may be NULL) is filled on success and on 239 * RXC_HOST_E_TORN / RXC_HOST_E_IDENTITY. `flags` must be 0. `dir` must 240 * pass src/omega_path_check.h (omega_path_copy) and be under 184 bytes; 241 * otherwise RXC_HOST_E_ARG and nothing is created. */ 242 int rxc_host_open(const char *dir, uint32_t root_kind, const uint8_t *root, size_t root_len, 243 uint64_t session, uint32_t flags, RxcHost **out, RxcHostInfo *info); 244 245 /* Register a Skill (before the first run/recall/info). `name` is 1..63 246 * bytes; `digest32` pins the procedure (NULL = sha256(name)); `cost` ranks 247 * it (lower first). Returns the Skill index (0..) or RXC_HOST_E_*. */ 248 int rxc_host_register_skill(RxcHost *h, const char *name, const uint8_t *digest32, uint64_t cost, 249 RxcHostSkillFn fn, void *ctx); 250 251 /* Set the AEGIS contract callback (before the first run; NULL = result != 0). */ 252 int rxc_host_set_verify(RxcHost *h, RxcHostVerifyFn fn, void *ctx); 253 254 /* Set how long one run waits for its steps to settle, 1..600000 ms (default 30000); RX_ERR_ARG otherwise. */ 255 int rxc_host_set_wait_ms(RxcHost *h, uint32_t wait_ms); 256 257 /* One goal through the whole COMPOSITION-2 path. `task` must be nonzero. 258 * `now_us` is the run's clock (route liveness). RXC_HOST_OK with out filled 259 * (check out->outcome), or RXC_HOST_E_* (out->run_rc holds the cause). */ 260 int rxc_host_run(RxcHost *h, uint64_t task, uint64_t now_us, RxcHostResult *out); 261 262 /* Records of `subject`, oldest first, each digest checked: fills up to 263 * `max`, *n_total = how many exist (may exceed max). */ 264 int rxc_host_recall(RxcHost *h, uint64_t subject, RxcHostRecord *out, uint32_t max, 265 uint32_t *n_filled, uint64_t *n_total); 266 267 /* One record by Cortex id (RXC_HOST_E_NOT_FOUND / RXC_HOST_E_DIGEST). */ 268 int rxc_host_record(RxcHost *h, uint64_t id, RxcHostRecord *out); 269 270 /* Payload words of record `id`: copies up to `max`, returns the count or <0. */ 271 int rxc_host_payload(RxcHost *h, uint64_t id, uint64_t *out, uint32_t max); 272 273 /* Current state (opens the composition if not yet open). */ 274 int rxc_host_info(RxcHost *h, RxcHostInfo *info); 275 276 /* Append one host record (RXC_HOST_NOTE_*) through the composition's Cortex 277 * writer, between runs. `bytes` (1..RXC_HOST_NOTE_MAX) is the record's text 278 * or receipt; `links` (may be NULL) names up to 4 related Cortex ids (0 = 279 * none). *out_id = the new record's id. Opens the composition if needed. */ 280 int rxc_host_note(RxcHost *h, uint32_t note, const uint64_t links[4], const uint8_t *bytes, 281 size_t len, uint64_t *out_id); 282 283 /* Operator repair of a home that rxc_host_open refused (RXC_HOST_E_TORN) or 284 * whose composition refused to open (RXC_HOST_E_REPLAY). No handle may be 285 * open on `dir` (the journal writer lock; RXC_HOST_E_OPEN otherwise). 286 * Identity is checked as at open. Idempotent: a home whose journal is 287 * whole and agrees with its anchor is left untouched (out->repaired = 0). 288 * A journal whose record at the anchored count differs from the anchor is 289 * not a tail cut: refused (RXC_HOST_E_REPLAY), nothing written. 290 * After a repair, recover opens the composition once (a trial open, as 291 * rxc_host_open + info would) and reports it: out->opens = 1, or 292 * RXC_HOST_E_REPLAY with out->open_rc when the cut removed a committed 293 * state record (a whole run lost at a record boundary: J-Space holds a 294 * state no surviving record names, which rx_compose refuses to adopt or to 295 * overwrite). The repair record is kept either way. */ 296 int rxc_host_recover(const char *dir, uint32_t root_kind, const uint8_t *root, size_t root_len, 297 RxcHostRepair *out); 298 299 /* Layout check for bindings: out[0..4) = sizeof RxcHostInfo, RxcHostResult, 300 * RxcHostRecord, RxcHostRepair; returns RXC_HOST_ABI_VERSION. */ 301 uint32_t rxc_host_abi_layout(uint32_t out[4]); 302 303 /* Close the composition and its authority; frees the handle. NULL is a no-op. */ 304 void rxc_host_close(RxcHost *h); 305 306 #ifdef __cplusplus 307 } 308 #endif 309 #endif /* RXC_HOST_ABI_H */