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/aienux/blob/main/native/kernel/svc/continuity_subject.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / svc / continuity_subject.h` 183 lines ยท 8956 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 /* continuity_subject.h -- ALLEN subject state: continuity object kind 24. 18 * 19 * ARCH-0035 (PROPOSED) / OS-0018 (PROPOSED). ALLEN is the durable subject the 20 * AIEN organism sustains: one chain of content-addressed Store v1 objects 21 * bound to the AgentRoot (kind 16, OS-0016) of this Store. Each object says 22 * what the subject currently intends (standing intents), which Cortex 23 * promotions it holds as its own (knowledge references, by digest only), and 24 * which Cortex journal lineage is its memory. It holds no capability, weight, 25 * model, machine, process or queue reference: the model is not the subject. 26 * 27 * This file is a codec plus a resolver. It has no thread, no wait, no clock, 28 * no scheduling and no authority: nothing here can mint, grant or dispatch. 29 * The kernel resolves subject state like any continuity object (OS-0016 30 * step 3 discipline: fork, gap, foreign root or undecodable object stop with 31 * CORRUPT; a Store with a root but no subject object is ABSENT, never minted). 32 * 33 * Encoding (little-endian, fixed layout, no_std style; header as 34 * continuity_codec.c): 16-byte header {magic "AIENSUBJ", format_version u16 35 * = 0, reserved u16 = 0, body length u32}, then 36 * root 32 logical ObjectId of the AgentRoot this subject belongs to 37 * agent 32 LogicalAgentId (must equal that AgentRoot's) 38 * previous 32 ObjectId of the prior subject object; zero for sequence 1 39 * sequence 8 previous.sequence + 1; 1 for the genesis subject object 40 * cortex 32 lineage reference: digest of the Cortex journal's genesis 41 * record (rx_cortex record id 1); zero = unbound 42 * provenance 32 who/what established this object (operator key id or a 43 * receipt digest); nonzero required 44 * origin 1 CS_ORIGIN_OPERATOR or CS_ORIGIN_PROMOTED 45 * reserved 7 zero 46 * n_intents 2 0..CS_MAX_INTENTS 47 * n_knowledge 2 0..CS_MAX_KNOWLEDGE 48 * reserved 4 zero 49 * intents n_intents * 96, strictly ascending by id 50 * knowledge n_knowledge * 48, strictly ascending by digest 51 * Largest object: 16 + 184 + 64*96 + 64*48 = 9416 bytes, under the K-1 cap. 52 * 53 * Intent (96 bytes): id 32, supersedes 32 (zero = none), kind u32, state u8, 54 * reserved 3, since u64 (sequence of the subject object that created it), 55 * payload 2 x u64. id = SHA-256("AIENOS_INTENT_v0:" || agent || kind LE32 || 56 * since LE64 || payload[0] LE64 || payload[1] LE64), checked on decode. 57 * Rules: at most one ACTIVE intent per (kind, payload[0]) slot; a SUPERSEDED 58 * intent is named by exactly one newer intent's `supersedes`; `supersedes` 59 * must name an intent in the same table whose state is SUPERSEDED; 60 * since <= sequence. 61 * 62 * Knowledge (48 bytes): digest 32 (cx_digest of a CX_K_PROMOTION record), 63 * record u64 (its id in that journal, informative), since u64. 64 * 65 * Kinds of standing intent in v0: CS_INTENT_GOAL_LATENCY, the one goal shape 66 * the resident AIEN faculty reads today (omega rx_aien.h: regime, target ns 67 * per call). payload[0] = regime, payload[1] = target ns. */ 68 #ifndef CK_CONTINUITY_SUBJECT_H 69 #define CK_CONTINUITY_SUBJECT_H 70 71 #include 72 #include 73 74 #include "continuity_codec.h" 75 #include "continuity_commit.h" 76 #include "continuity_resolve.h" 77 78 #if defined(CK_HARDWARE_STAGING) && \ 79 (defined(CS_MUTANT_ACCEPT_FOREIGN) || defined(CS_MUTANT_ACCEPT_TWO_ACTIVE) || \ 80 defined(CS_MUTANT_SKIP_INTENT_ID) || defined(CS_MUTANT_ACCEPT_FORK)) 81 #error "continuity subject mutants are TEST-only and refused under CK_HARDWARE_STAGING" 82 #endif 83 84 #define CC_KIND_SUBJECT 24u 85 86 #define CS_MAX_INTENTS 64u 87 #define CS_MAX_KNOWLEDGE 64u 88 #define CS_INTENT_BYTES 96u 89 #define CS_KNOWLEDGE_BYTES 48u 90 #define CS_FIXED_BODY 184u 91 #define CS_MAX_BYTES (CC_HEADER_BYTES + CS_FIXED_BODY + CS_MAX_INTENTS * CS_INTENT_BYTES + \ 92 CS_MAX_KNOWLEDGE * CS_KNOWLEDGE_BYTES) 93 94 #define CS_ORIGIN_OPERATOR 1u 95 #define CS_ORIGIN_PROMOTED 2u 96 97 #define CS_INTENT_GOAL_LATENCY 1u 98 99 #define CS_ACTIVE 1u 100 #define CS_INACTIVE 2u 101 #define CS_SUPERSEDED 3u 102 103 struct cs_intent { 104 uint8_t id[32]; 105 uint8_t supersedes[32]; /* zero = none */ 106 uint32_t kind; 107 uint8_t state; /* CS_ACTIVE / CS_INACTIVE / CS_SUPERSEDED */ 108 uint64_t since; 109 uint64_t payload[2]; 110 }; 111 112 struct cs_knowledge { 113 uint8_t digest[32]; 114 uint64_t record; 115 uint64_t since; 116 }; 117 118 struct cs_subject { 119 uint8_t root[32]; 120 uint8_t agent[32]; 121 uint8_t previous[32]; 122 uint64_t sequence; 123 uint8_t cortex[32]; 124 uint8_t provenance[32]; 125 uint8_t origin; 126 uint32_t n_intents; 127 uint32_t n_knowledge; 128 struct cs_intent in[CS_MAX_INTENTS]; 129 struct cs_knowledge kn[CS_MAX_KNOWLEDGE]; 130 }; 131 132 /* ---- codec (CC_OK / CC_E_CORRUPT / CC_E_LIMIT / CC_E_ARG, as continuity_codec.h) ---- */ 133 void cs_intent_id(const uint8_t agent[32], uint32_t kind, uint64_t since, const uint64_t payload[2], 134 uint8_t out[32]); 135 int cs_subject_validate(const struct cs_subject *s, const char **why); 136 int cs_subject_encode(const struct cs_subject *s, uint8_t *out, size_t cap, size_t *len, 137 const char **why); 138 int cs_subject_decode(const uint8_t *in, size_t len, struct cs_subject *s, const char **why); 139 /* Logical ObjectId of the encoded object (kind 24, claim version 1): the 140 * subject digest. Content only; the same bytes give the same id on any 141 * machine, under any model, in any process. */ 142 int cs_subject_id(const uint8_t *bytes, size_t len, uint8_t out[32]); 143 144 /* ---- editing (in memory; nothing here touches storage) ---- */ 145 /* First subject object for a resolved continuity view: sequence 1, no 146 * previous, no intents, no knowledge, Cortex unbound. */ 147 void cs_subject_genesis(struct cs_subject *s, const struct cr_view *v, const uint8_t provenance[32], 148 uint8_t origin); 149 /* Prepare the successor of a persisted object: previous = prev_id, 150 * sequence + 1, new provenance/origin; intents and knowledge are kept. */ 151 void cs_subject_advance(struct cs_subject *s, const uint8_t prev_id[32], 152 const uint8_t provenance[32], uint8_t origin); 153 /* Add an ACTIVE standing intent created at this object's sequence. If another 154 * ACTIVE intent holds the same (kind, payload[0]) slot it becomes SUPERSEDED 155 * and the new intent names it; the table stays sorted. CC_E_LIMIT when full. */ 156 int cs_subject_intend(struct cs_subject *s, uint32_t kind, const uint64_t payload[2], 157 uint8_t id_out[32], const char **why); 158 /* Retire an ACTIVE intent (state INACTIVE). CC_E_ARG if absent or not active. */ 159 int cs_subject_retire(struct cs_subject *s, const uint8_t id[32], const char **why); 160 /* Hold a Cortex promotion as subject knowledge; duplicates are refused. */ 161 int cs_subject_hold(struct cs_subject *s, const uint8_t digest[32], uint64_t record, 162 const char **why); 163 /* Bind (or re-bind) the Cortex lineage reference. */ 164 void cs_subject_bind_cortex(struct cs_subject *s, const uint8_t lineage[32]); 165 /* The ACTIVE intent in slot (kind, payload[0]); NULL if none. */ 166 const struct cs_intent *cs_subject_active(const struct cs_subject *s, uint32_t kind, uint64_t slot); 167 168 /* ---- resolver / committer over the continuity source and sink ---- */ 169 #define CS_RESOLVED 0 /* out holds the head of the chain; out_id its ObjectId */ 170 #define CS_ABSENT 1 /* the Store has a root but no subject object: not minted */ 171 /* Other returns are CR_CORRUPT, CR_LIMIT, CR_STORE, CR_E_ARG (continuity_resolve.h). */ 172 int cs_resolve(const struct cr_source *src, struct cr_work *w, const struct cr_view *v, 173 struct cs_subject *out, uint8_t out_id[32], const char **why, int *store_rc); 174 /* Encode and commit one subject object in its own Store transaction. The 175 * object must validate and must continue the chain the caller resolved: 176 * cs_resolve is run first; its head id must equal s->previous (or the Store 177 * must be ABSENT and s->sequence 1). Returns CS_RESOLVED with out_id, or 178 * CR_CORRUPT / CR_LIMIT / CR_STORE / CR_E_ARG; nothing is written on refusal. */ 179 int cs_commit(const struct cr_source *src, const struct cr_sink *snk, struct cr_work *w, 180 const struct cr_view *v, const struct cs_subject *s, uint8_t out_id[32], 181 const char **why, int *store_rc); 182 183 #endif