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 / src / runtime / rx_cortex_record.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_cortex_record.h -- World execution recorded into canonical Cortex (M20). |
| 19 | * |
| 20 | * The one Cortex writer for World. Attached to a world, it turns every |
| 21 | * causal crumb, as the World commits it, into one Cortex object: |
| 22 | * |
| 23 | * EXTERNAL -> OBSERVATION / CX_K_WORK_ACCEPTED |
| 24 | * CREATE, RETIRE -> ENTITY / CX_K_ENTITY_CREATED, _RETIRED |
| 25 | * COMMIT -> EXECUTION / CX_K_EXEC_COMMIT (the result) |
| 26 | * NOOP -> EXECUTION / CX_K_EXEC_NOOP |
| 27 | * FAILED, REJECTED, BLOCKED_AUTHORITY, |
| 28 | * INVALIDATED, QUARANTINE -> FAILURE / CX_K_EXEC_FAILED |
| 29 | * |
| 30 | * Payload layout CX_WREC_* (rx_cortex.h): session, crumb id and digest |
| 31 | * (World evidence reference), reaction, faculty, episode, the object and |
| 32 | * its field values after the crumb (execution observation / result). |
| 33 | * Provenance: links[0] is the record of the crumb that woke this work, |
| 34 | * links[1..3] records of its parent crumbs (writers of what it read). |
| 35 | * |
| 36 | * Subject = World object slot + 1 (0 = no object). Slots are runtime |
| 37 | * indices, not identity. Logical time t = the store's next id, so it keeps |
| 38 | * increasing across sessions on one journal. |
| 39 | * |
| 40 | * Each attached store has one writer (its link): no other code may append |
| 41 | * to it while attached (cx_append returns CX_ERR_WRITER), and a store held by |
| 42 | * another writer cannot be attached. |
| 43 | */ |
| 44 | #ifndef RX_CORTEX_RECORD_H |
| 45 | #define RX_CORTEX_RECORD_H |
| 46 | |
| 47 | #include "rx_cortex.h" |
| 48 | #include "rx_world.h" |
| 49 | |
| 50 | #define RX_CORTEX_SUBJECTS ((uint64_t)RX_MAX_OBJECTS + 1u) |
| 51 | |
| 52 | /* Attach `s` (n_subjects >= RX_CORTEX_SUBJECTS) to `w` under `session`. |
| 53 | * Crumbs already in the log are recorded first (their field values are the |
| 54 | * objects' values at attach time, their digests the crumbs'). Returns RX_OK, |
| 55 | * RX_ERR_EXISTS (world already has a whole-World Cortex link, or a recorder |
| 56 | * that is not Cortex; scoped links may coexist), RX_ERR_IDENTITY (store held |
| 57 | * by another writer), RX_ERR_ARG or RX_ERR_FULL (no memory). */ |
| 58 | int rx_cortex_attach(RxWorld *w, CxStore *s, uint64_t session); |
| 59 | |
| 60 | /* Detach the default link (whole-World, else the only one) and release its |
| 61 | * store's writer claim. Every link is released by |
| 62 | * rx_world_destroy. */ |
| 63 | int rx_cortex_detach(RxWorld *w); |
| 64 | |
| 65 | /* COMPOSITION-2 attach: a scoped link. Records only crumbs whose object |
| 66 | * (first output, else first input) is one of `objs` (live ref, generation |
| 67 | * included), under the matching `subjects` (stable across Worlds, unlike |
| 68 | * slots), into its own store `s`. It shares the World's recorder slot with |
| 69 | * the whole-World link and other scoped links (scopes must be disjoint): |
| 70 | * nobody loses their journal. Crumbs already in the log about `objs` are |
| 71 | * recorded first. RX_ERR_EXISTS (overlapping scope or a non-Cortex |
| 72 | * recorder), RX_ERR_IDENTITY (store held by another writer), RX_ERR_FULL. */ |
| 73 | #define RXCX_SCOPE_MAX 8u |
| 74 | int rx_cortex_attach_scoped(RxWorld *w, CxStore *s, uint64_t session, const RxObjRef *objs, |
| 75 | const uint64_t *subjects, uint32_t n); |
| 76 | /* Detach the link writing `s` (whole-World or scoped). */ |
| 77 | int rx_cortex_detach_store(RxWorld *w, const CxStore *s); |
| 78 | |
| 79 | /* Records written and append failures (a failure never fails the commit; |
| 80 | * it is counted here and the crumb stays in the World log). */ |
| 81 | int rx_cortex_status(RxWorld *w, uint64_t *records, uint64_t *errors); |
| 82 | |
| 83 | /* Cortex id of the record for crumb `crumb` of the attached session, 0 if none. */ |
| 84 | uint64_t rx_cortex_record_of(RxWorld *w, uint64_t crumb); |
| 85 | |
| 86 | /* Newest committed result for an object slot: Cortex id (0 = none). */ |
| 87 | uint64_t rx_cortex_recall_result(CxStore *s, uint32_t obj_slot, CxWorldRecord *out); |
| 88 | |
| 89 | /* COMPOSITION-2: append a composition record (candidate, evidence, |
| 90 | * admission) through the attached single writer, under the world mutex. |
| 91 | * RX_ERR_NOT_FOUND when no store is attached; RX_ERR_FULL when Cortex |
| 92 | * refused it (counted in errors). */ |
| 93 | int rx_cortex_append(RxWorld *w, const CxHeader *h, const uint64_t *payload, uint32_t n, |
| 94 | uint64_t *out_id); |
| 95 | /* COMPOSITION-2: cx_promote through the attached writer (RX_ERR_ARG when |
| 96 | * Cortex refuses the pair). The only way a candidate becomes fact. */ |
| 97 | int rx_cortex_promote(RxWorld *w, uint64_t candidate, uint64_t evidence, uint64_t *out_id); |
| 98 | /* Logical time the next attached append gets (0 = not attached). */ |
| 99 | uint64_t rx_cortex_next_t(RxWorld *w); |
| 100 | |
| 101 | /* The same, addressed to the link writing `s` (NULL = the default link: the |
| 102 | * whole-World link, else the only link). The plain forms above use the |
| 103 | * default link. */ |
| 104 | uint64_t rx_cortex_record_in(RxWorld *w, const CxStore *s, uint64_t crumb); |
| 105 | int rx_cortex_append_in(RxWorld *w, CxStore *s, const CxHeader *h, const uint64_t *payload, |
| 106 | uint32_t n, uint64_t *out_id); |
| 107 | int rx_cortex_promote_in(RxWorld *w, CxStore *s, uint64_t candidate, uint64_t evidence, |
| 108 | uint64_t *out_id); |
| 109 | uint64_t rx_cortex_next_t_in(RxWorld *w, const CxStore *s); |
| 110 | /* The store a link writes (NULL = default link; NULL result = none attached). */ |
| 111 | CxStore *rx_cortex_store_in(RxWorld *w, const CxStore *s); |
| 112 | /* cx_promote preceded by `gate(store, evidence, arg)` under one hold of the |
| 113 | * world mutex; the gate's nonzero result is returned and nothing is written. */ |
| 114 | int rx_cortex_promote_checked_in(RxWorld *w, CxStore *s, uint64_t candidate, uint64_t evidence, |
| 115 | int (*gate)(const CxStore *, uint64_t, const void *), |
| 116 | const void *arg, uint64_t *out_id); |
| 117 | |
| 118 | #endif /* RX_CORTEX_RECORD_H */ |