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/model/world_model.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 / tests / model / world_model.h` 112 lines ยท 4491 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 * world_model.h -- small explicit state machine of the rx_world activation 19 * lifecycle (hardening lane LG). 20 * 21 * wake -> admit (charge budget) -> run -> commit | invalidate | fail 22 * -> reclaim (uncharge) -> idle, plus cancel of a parent and its 23 * children. 24 * 25 * Four reactions in a fixed tree, written by the outside world into E: 26 * 27 * E --> P --> X --> C1 --> Y --> G 28 * \-> C2 --> Z 29 * 30 * The model has two roles: 31 * - SPEC: what the lifecycle should guarantee (cancel reaches every child, 32 * a deadline overrun is surfaced while the activation is still running). 33 * - AS_BUILT: what src/runtime/rx_world.c does today, step for step 34 * (admission order, re-arm, invalidation back-off, parking). This is the 35 * profile the differential harness compares against the real runtime. 36 * Mutants are SPEC with one realistic fault switched on; each must make the 37 * invariant it targets fail. 38 */ 39 #ifndef WORLD_MODEL_H 40 #define WORLD_MODEL_H 41 42 #include 43 44 #define WM_N 4u /* reactions: P, C1, C2, G */ 45 #define WM_P 0u 46 #define WM_C1 1u 47 #define WM_C2 2u 48 #define WM_G 3u 49 #define WM_SLOTS 2u /* admission slots in the budget */ 50 #define WM_MEM 8u /* memory budget */ 51 #define WM_EXT_MAX 3u /* outside publications per explored run */ 52 #define WM_TICK_MAX 3u /* logical clock bound */ 53 54 /* Topology and needs (shared with the differential harness). */ 55 extern const int wm_parent[WM_N]; 56 extern const uint32_t wm_mem[WM_N]; 57 extern const uint32_t wm_deadline[WM_N]; /* 0 = none */ 58 extern const char *wm_name[WM_N]; 59 60 enum { WM_IDLE = 0, WM_WAITING, WM_RUN, WM_ENDING }; 61 62 enum { OP_EXT = 0, OP_FIN, OP_FAIL, OP_TICK, OP_CANCEL, OP_KINDS }; 63 typedef struct { uint8_t kind, r; } WmOp; 64 65 /* Invariant violation bits. */ 66 #define V_LEAK 0x01u /* I1 budget held != budget of running work */ 67 #define V_CANCEL_CHILD 0x02u /* I2 cancel left a descendant in flight */ 68 #define V_DOUBLE 0x04u /* I3 one activation committed twice */ 69 #define V_DEADLINE 0x08u /* I4 running past its deadline, not surfaced */ 70 #define V_CANCEL_SELF 0x10u /* I2b cancel left the target itself in flight */ 71 72 enum { CANCEL_NONE = 0, CANCEL_TRANSITIVE, CANCEL_TARGET_ONLY }; 73 74 typedef struct { 75 const char *name; 76 int cancel_mode; 77 int deadline_on_tick; /* surface overrun when the clock passes it */ 78 int mut_leak_on_fail; /* failure path forgets to reclaim the budget */ 79 int mut_commit_keeps_act; /* commit path forgets to end the activation */ 80 } WmProfile; 81 82 extern const WmProfile wm_spec, wm_as_built; 83 extern const WmProfile wm_mut_leak, wm_mut_noprop, wm_mut_double, wm_mut_deadline; 84 85 /* Behaviour-relevant state (the dedup key is derived from it). */ 86 typedef struct { 87 uint8_t st[WM_N]; 88 uint8_t rearm[WM_N], stale[WM_N], parked[WM_N], yield[WM_N]; 89 uint8_t surfaced[WM_N], act_committed[WM_N]; 90 uint32_t wait_seq[WM_N]; 91 uint32_t seq; 92 uint8_t ext, tick; 93 uint8_t used_slots; 94 uint32_t used_mem; 95 uint8_t in_flight; 96 /* Observables, not part of the key. */ 97 uint32_t commits[WM_N], invalidations, failures, overdue, cancels; 98 uint32_t viol; /* violations raised by the last step */ 99 } WmState; 100 101 void wm_init(WmState *s); 102 int wm_enabled(const WmProfile *p, const WmState *s, WmOp op); 103 /* Applies op, then checks every invariant; returns s->viol. */ 104 uint32_t wm_step(const WmProfile *p, WmState *s, WmOp op); 105 /* Canonical key bytes (wait order normalised); returns length. */ 106 int wm_key(const WmState *s, uint8_t *out); 107 int wm_is_descendant(uint32_t d, uint32_t r); 108 void wm_op_str(WmOp op, char *buf, int n); 109 /* All candidate ops in a fixed order; returns count. */ 110 int wm_all_ops(WmOp *out); 111 112 #endif