aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / docs / DAEMON_GENERATION_RECORD.md
| 1 | # Daemon generation record |
| 2 | |
| 3 | Evidence that this daemon generated a piece of text from the model files it |
| 4 | loaded. It exists so a provenance chain (INTERPLANE, interplane#76) does not |
| 5 | have to take the run driver's word for "this text came from this model". |
| 6 | |
| 7 | ## What the daemon does |
| 8 | |
| 9 | 1. At start, after the model loads, the CLI holds the digest of the model |
| 10 | weights (below: `model_sha256`, files streamed in 1 MiB chunks, hashed once) |
| 11 | and the sha256 of the tokenizer file, with the path each came from. The |
| 12 | daemon passes both to the server (`set_model_identity`). The same digests are |
| 13 | in the "checkpoint loaded" log line; a sharded checkpoint also logs a |
| 14 | `CHECKPOINT_SHARDS` line (below). |
| 15 | 2. On every `StreamTurn` Finished event, and when the compose ledger is open, |
| 16 | the daemon appends one record **before classifying completion**. Only |
| 17 | `StopToken` sends `TurnFinished`, whose optional `generation_record` id is |
| 18 | absent when no record was written. `LengthLimit`, `Aborted` and `Preempted` |
| 19 | send the existing `Error` response with `max_tokens`, `aborted` or `preempted` |
| 20 | in its text. Their records remain in the ledger and can be retrieved with |
| 21 | `ComposeRecall`; the Error response does not contain a structured record id. |
| 22 | No wire field was added: older clients already treat Error as failure. |
| 23 | An unchanged older daemon can still misclassify these reasons; this source |
| 24 | change is not a deployment claim. |
| 25 | |
| 26 | ## The record |
| 27 | |
| 28 | An `effect`-class host note whose JSON has the marker field `generation`: |
| 29 | |
| 30 | | field | meaning | |
| 31 | |---|---| |
| 32 | | `generation`, `v` | marker (1) and record version (1) | |
| 33 | | `model_sha256`, `model_path` | the digest of the loaded weights (form below) and the canonical path the daemon was given | |
| 34 | | `model_digest_kind` | which form `model_sha256` has: `file` or `index+shards` (below) | |
| 35 | | `tokenizer_sha256`, `tokenizer_path` | the loaded tokenizer file's digest and path | |
| 36 | | `prompt_ids_sha256` | `token_ids_sha256` of the submitted prompt token ids | |
| 37 | | `output_token_ids_sha256` | same hash over the generated token ids | |
| 38 | | `output_text_sha256` | sha256 of the exact accumulated text (returned in `TurnFinished` for a normal stop, or emitted as deltas before an incomplete-turn Error) | |
| 39 | | `total_tokens`, `output_tokens` | token count the engine reported; generated tokens | |
| 40 | | `finish_reason` | `eos`, `max_tokens`, `aborted` or `preempted` | |
| 41 | | `decoding` | how the backend chose the output tokens (below); ABSENT when the backend did not report it | |
| 42 | | `ops` | the tensor backend that ran the call and its op counters (below); ABSENT when the backend did not report them | |
| 43 | | `daemon` | `pid`, `start_ticks` (process start, clock ticks) and `started_unix_ms` | |
| 44 | | `request_id`, `operation_id` | CALLER-ASSERTED: the request envelope's ids, exactly as the client sent them | |
| 45 | |
| 46 | The envelope ids are chosen by the client. They are recorded, not trusted (names kept to match the envelope fields). |
| 47 | |
| 48 | ### `model_sha256`: the digest of what was loaded (sc#338) |
| 49 | |
| 50 | The daemon digests exactly the files the weights loader reads (the same |
| 51 | resolution: a `.safetensors` file, a `model.safetensors.index.json`, a model |
| 52 | directory holding either, or a shard file whose directory has an index, which |
| 53 | loads the whole sharded set). |
| 54 | |
| 55 | - `model_digest_kind` = `file`: one safetensors file. `model_sha256` is that |
| 56 | file's sha256 (`sha256sum model.safetensors`). |
| 57 | - `model_digest_kind` = `index+shards`: a sharded checkpoint. `model_sha256` is |
| 58 | the sha256 of this UTF-8 manifest text, with `\n` line ends and a final `\n`: |
| 59 | |
| 60 | ``` |
| 61 | aien-checkpoint-digest v1 |
| 62 | index <sha256 of model.safetensors.index.json> |
| 63 | <shard sha256> <shard name> |
| 64 | ... |
| 65 | ``` |
| 66 | |
| 67 | one shard line per file the index's `weight_map` names, de-duplicated and |
| 68 | sorted by name (byte order), the name exactly as the index writes it. The |
| 69 | shard lines are `sha256sum` lines, so a verifier can rebuild the manifest from |
| 70 | `sha256sum` output in the model directory and hash it. A changed shard, a |
| 71 | changed index, or a renamed shard changes `model_sha256`; the index alone does |
| 72 | not determine it. |
| 73 | The names are written raw: for a shard name holding a backslash or a line |
| 74 | break, `sha256sum` escapes the line (leading `\`), so rebuild that line by |
| 75 | hand. An index that names no shard is refused, and so is a directory given |
| 76 | as the checkpoint path (as it was before sc#338). |
| 77 | |
| 78 | The daemon also logs, on stdout after the "checkpoint loaded" line (which keeps |
| 79 | its pinned form, parsed by interplane#76), for a sharded checkpoint only: |
| 80 | |
| 81 | ``` |
| 82 | CHECKPOINT_SHARDS model_sha256=<digest> model_digest_kind=index+shards index_sha256=<sha256> shards=[<name>:<sha256>,...] |
| 83 | ``` |
| 84 | |
| 85 | Records written before sc#338 have no `model_digest_kind`; their |
| 86 | `model_sha256` is the sha256 of the file the daemon was given, which for a |
| 87 | sharded checkpoint was the index only. |
| 88 | |
| 89 | ### `decoding`: the decoding actually taken (sc#294) |
| 90 | |
| 91 | The Qwen3 v4 review found greedy decoding documented but not observed: no |
| 92 | record said which decoding a run used. `decoding` is that observation. The |
| 93 | native backend (`NativeTransformerBackend`) counts every token it chooses |
| 94 | inside the branch that chose it (`sample_with_params_observed` for decode, the |
| 95 | prefill pick in `execute_step`), and the scheduler takes the count when the |
| 96 | sequence finishes (`take_decode_observation`) and puts it in |
| 97 | `CompletionEvent::Finished.decoding`. The daemon copies it into the record. It |
| 98 | is never derived from the request's `temperature` or from any config file. |
| 99 | |
| 100 | | field | meaning | |
| 101 | |---|---| |
| 102 | | `mode` | `greedy` (every chosen token was the argmax), `sampled` (every one was a random draw), `mixed`, or `none` | |
| 103 | | `greedy_tokens`, `sampled_tokens` | how many chosen tokens took each branch | |
| 104 | | `temperature` | temperature of the sampled draws; only when a draw sampled | |
| 105 | | `top_p` | nucleus mass of the sampled decode draws; only when filtering ran (`0 < top_p < 1`) | |
| 106 | | `seed_request_id` | the backend request id the draws were seeded from; only when a draw sampled | |
| 107 | |
| 108 | There is no top-k: `SamplingParams` has none. Counted tokens are the pick |
| 109 | after the final prefill chunk (a mid-prompt pick that is discarded is not |
| 110 | counted) and every decode pick, the stop token included, so the count can be |
| 111 | one more than `output_tokens`. A swarm branch counts only its own decode picks. |
| 112 | A preempted request finishes once at the preemption (the scheduler takes its |
| 113 | count then); after it resumes, counting starts again, so a later record covers |
| 114 | only the tokens chosen after the resume. |
| 115 | |
| 116 | `decoding` is ABSENT, not `greedy`, when the backend does not observe its |
| 117 | decoding (the mock backend, a backend without the hook): an absent field is an |
| 118 | absent claim. A verifier that needs greedy decoding requires `decoding.mode == |
| 119 | "greedy"` and `decoding.sampled_tokens == 0` on every record. |
| 120 | |
| 121 | What it does not prove: like the rest of the record, it is the daemon's own |
| 122 | report, not signed. It covers the native backend's scheduler path |
| 123 | (`execute_step`); the standalone generation helpers (`generate_tokens*`) and |
| 124 | example binaries are not observed. |
| 125 | |
| 126 | ### `ops`: the backend and its fallbacks (sc#337) |
| 127 | |
| 128 | "No silent fallback" used to be shown only by the absence of a crash. `ops` |
| 129 | is positive evidence. The native backend reads its tensor backend's op |
| 130 | counters (`TensorBackend::op_report`) when a sequence finishes |
| 131 | (`AienInferenceBackend::op_evidence`), the scheduler puts them in |
| 132 | `CompletionEvent::Finished.ops`, and the daemon copies them into the record. |
| 133 | |
| 134 | | field | meaning | |
| 135 | |---|---| |
| 136 | | `backend` | the tensor backend's name (`TensorBackend::name`, e.g. the Omega GB10 engine or `ReferenceCpuBackend`) | |
| 137 | | `native_fallbacks` | runs of ops the backend claims native that ran on the reference CPU path | |
| 138 | | `reference_runs` | runs of ops on the reference CPU path by design (outside the backend's native mask) | |
| 139 | | `scope` | always `process`: the counts are totals since the daemon built the backend, NOT per call | |
| 140 | | `report` | the full `OP_REPORT native=[..] reference=[..] native_fallbacks=[..] reference_runs=[..]` line | |
| 141 | | `gpu_executions` | sc#402: operations the backend ran on its chip (the Omega GB10 engine's `chip_calls`), process total like the rest; ABSENT, not zero, for a backend with no chip (the CPU reference backend, the Omega stub). The `OP_REPORT` log line then carries ` gpu_executions=<n>` before ` backend=` | |
| 142 | |
| 143 | Because the counts are process totals, a later record's counts include every |
| 144 | earlier call's; a per-call figure is the difference between two records of the |
| 145 | same daemon (`daemon.pid` and `daemon.start_ticks` equal), and only when no |
| 146 | other call ran in between. A production build panics on the first |
| 147 | claimed-native fallback (`STRICT_REAL_MODEL_VIOLATION`), so a record written by |
| 148 | a production daemon always has `native_fallbacks == 0`; a verifier that needs |
| 149 | a strict run requires `ops` to be present with `native_fallbacks == 0` and the |
| 150 | daemon's `STRICT strict=true dev_fallback_build=false ...` start line. `ops` is |
| 151 | ABSENT, not zero, when the backend does not account its ops (the mock backend |
| 152 | and the other `AienInferenceBackend` implementations; only |
| 153 | `NativeTransformerBackend`, the backend the daemon builds, reports them). |
| 154 | |
| 155 | The daemon also logs, at the end of every model call (turn and compose), the |
| 156 | `report` line with ` backend=<name>` appended, on stderr. At start it prints |
| 157 | `STRICT strict=<bool> dev_fallback_build=<bool> require_checkpoint=<bool> |
| 158 | backend=<name>` on stdout with its other start lines: `strict` is the |
| 159 | effective value (false with `dev_fallback_build=false` means the |
| 160 | `AIEN_DEV_FALLBACK=1` opt-in), `dev_fallback_build` is the compile-time |
| 161 | `dev-fallback` feature, `require_checkpoint` is the effective checkpoint |
| 162 | policy. |
| 163 | |
| 164 | ## What it proves |
| 165 | |
| 166 | The daemon process with that pid and start time generated text with that |
| 167 | digest, from prompt ids and output ids with those digests, while it held model |
| 168 | and tokenizer files with those digests. The record sits in the compose ledger, whose records carry digests the engine |
| 169 | re-checks on every read (`verified`), so an edited record is detected rather than |
| 170 | silently accepted. |
| 171 | |
| 172 | ## What it does not prove |
| 173 | |
| 174 | - No capability, permission or authority. Nothing reads this record: no grant, |
| 175 | intent, replay, commit or effect decision depends on it |
| 176 | (`effects::generation_records_change_no_decision`). |
| 177 | - Not that the digest is of the very bytes the loader parsed. The CLI hashes the |
| 178 | model files (for a sharded checkpoint, the index and every shard) and the |
| 179 | tokenizer file at load, and the loaders then open the same paths again (the |
| 180 | weights loader and tokenizer loader take paths, not bytes). The digest is of |
| 181 | the files read at load time; a swap between the hash and the load is not |
| 182 | detected. |
| 183 | - Not that the file on disk still has that digest later, only what was loaded. |
| 184 | - Not signed. The ledger's per-record digest detects edits to a record, not a |
| 185 | forged append: a process of the same user that can append to the compose |
| 186 | ledger could append a record that passes the digest check. Only the daemon |
| 187 | writes one through the socket (ComposeNote refuses it), but the file is not |
| 188 | protected against that user. |
| 189 | - Not that the text is correct, safe or what an operator approved. |
| 190 | - A caller cannot write one: `ComposeNote` refuses kind `generation` and any |
| 191 | `effect` note carrying the `generation` field. |
| 192 | |
| 193 | ## Verifier guidance |
| 194 | |
| 195 | Parse the note text strictly as one JSON object, require the top-level |
| 196 | `generation` marker (value 1) and `v` 1, require the record's links to be empty, |
| 197 | and compare the digests to the files and text you hold. Treat request_id and |
| 198 | operation_id as the client's claims. |
| 199 | |
| 200 | ## Timing |
| 201 | |
| 202 | The record is written before either terminal response (`TurnFinished` or an |
| 203 | incomplete-turn `Error`), and the write waits for the compose home lock. A |
| 204 | running compose task holds that lock, so either response can be delayed until |
| 205 | the task releases it. There is no deadlock: the compose task's own model calls |
| 206 | (`generate_text`) write no record and take no home lock. |
| 207 | |
| 208 | ## No record means no claim |
| 209 | |
| 210 | A normally stopped turn still succeeds, with `generation_record` absent, when: |
| 211 | |
| 212 | - there is no compose ledger; |
| 213 | - the daemon has no model identity (a stub run, or the reference-weights |
| 214 | fallback, or a tokenizer that did not load); |
| 215 | - the ledger append failed. The failure is logged |
| 216 | (`generation record not written`); an id is never returned for a record that |
| 217 | was not written. |
| 218 | |
| 219 | A verifier must treat an absent record as an absent claim, not as a pass. |
| 220 | |
| 221 | ## Provenance link: which generation made a commit, and which ALLEN asked |
| 222 | |
| 223 | The `StreamTurn` record above says what the daemon generated. It did not say |
| 224 | which commit that text became. The compose path (`aien compose propose`, the |
| 225 | model Skill) now closes that gap (arch#162, ALLEN end-to-end demo v1 steps S4 |
| 226 | and S8). |
| 227 | |
| 228 | ### What the daemon does |
| 229 | |
| 230 | 1. When a compose task commits a model proposal, the daemon writes one |
| 231 | generation record for the proposal attempt the commit came from (the |
| 232 | `parsed` attempt), in the same format and with the same writer as above. |
| 233 | It is written under the compose home lock the task already holds (the |
| 234 | model call itself cannot take it). Extra fields on this record: |
| 235 | `origin` = `compose_proposal`, `task` (the compose task id) and `attempt` |
| 236 | (1-based). `request_id` is 0 and `operation_id` is `"0"`: the task makes |
| 237 | this model call itself, there is no client envelope. `prompt_ids_sha256` |
| 238 | and `output_token_ids_sha256` are the hashes of the ids the inference path |
| 239 | returned for that attempt. `output_text_sha256` is the digest of the reply |
| 240 | handed to the template parser (the assistant prefix plus the decoded |
| 241 | tokens), the same digest the attempt records as `text_sha256`. In edit |
| 242 | mode the committed proposal is that reply merged into the prior file, so |
| 243 | the proposal digest is not this one; the link is by record id, below. |
| 244 | 2. The id is returned in `ComposeTaskReport.generation_record` (optional |
| 245 | field, absent in old reports) and written into the daemon's |
| 246 | `compose_commit` record. |
| 247 | 3. Every record of the commit chain carries one evidence object, |
| 248 | `"provenance": {"generation_record": <id or null>, "allen_agent": "<64 hex or none>"}`: |
| 249 | the `compose_commit` record, the minted grant (`ComposeAuthorize`), the |
| 250 | intent, and the ack. Each is copied by the daemon from the record before it |
| 251 | (grant from commit, intent from grant, ack from intent), never from the |
| 252 | request. An approved grant (`ComposeApprovedProposal`) carries |
| 253 | `generation_record` null (no model ran) and the ALLEN agent. A reconcile |
| 254 | record is not stamped; its intent is. |
| 255 | 4. `allen_agent` is the ALLEN LogicalAgentId (`aien_allen::Resolved::agent`, |
| 256 | the 64 hex shown in the `ALLEN: engaged agent=...` line) of the daemon that |
| 257 | ran the task, or the explicit string `none` when no ALLEN is attached. No |
| 258 | second identity system. |
| 259 | |
| 260 | A verifier follows the commit's records (`aien compose recall --ids ...`) to |
| 261 | `provenance.generation_record`, reads that record, and compares its |
| 262 | `model_sha256` with the weights it holds. `aien compose effects` does not |
| 263 | print provenance: the effect ledger deliberately does not parse it. |
| 264 | |
| 265 | ### What it does not change (separation from authorization) |
| 266 | |
| 267 | Provenance is evidence, never an input. `Ledger`, `check_intent`, |
| 268 | `check_minted_backing`, `check_approved_backing`, the world checks and |
| 269 | reconcile never read it: their row types have no provenance field. The only |
| 270 | reader is `generation::Provenance::from_text`, called from one writer helper |
| 271 | (`effects::stamp`) after the writer's decisions are made. A damaged, |
| 272 | absent or wrong-typed field reads as `generation_record` null and |
| 273 | `allen_agent` `none`; it can never refuse or allow anything. Tests: |
| 274 | `effects::provenance_changes_no_decision` (ledgers with absent, valid, bogus |
| 275 | and hostile provenance give identical state and identical refusals), |
| 276 | `effects::provenance_is_read_by_no_decision_code` (a source scan: which |
| 277 | functions may mention provenance, and that no ledger type has the field). |
| 278 | |
| 279 | ### Not forgeable by a client |
| 280 | |
| 281 | `ComposeNote` refuses any note, of any kind, whose JSON has a top-level |
| 282 | `provenance` field, and still refuses kind `generation` and any `effect` note |
| 283 | with the `generation` field. The grant, intent and ack requests carry only |
| 284 | ids and digests, so there is no field a client can fill. A record the daemon |
| 285 | writes that names a generation id is refused at write time unless that id is a |
| 286 | verified generation record of the same ledger (`write_compose_commit`: |
| 287 | `compose-commit not written: provenance names generation record #N ...`). |
| 288 | When the daemon copies provenance along the chain (grant, intent, ack), an id |
| 289 | that no longer names a verified generation record is copied as null instead of |
| 290 | refused, so copying can never change an authorization outcome. |
| 291 | |
| 292 | ### Old ledgers |
| 293 | |
| 294 | Records written before this change have no `provenance` field. They open and |
| 295 | verify as before, and a grant, intent or ack the daemon writes from them |
| 296 | carries the explicit default (`generation_record` null, `allen_agent` `none`). |
| 297 | `ComposeTaskReport.generation_record` defaults to absent on old reports. |
| 298 | Test: `an_old_ledger_without_provenance_still_opens_and_runs`. |
| 299 | |
| 300 | ### No generation record means no claim |
| 301 | |
| 302 | `generation_record` is null when the daemon has no model identity (stub run, |
| 303 | reference weights), the attempt did not expose its token ids, the proposal is |
| 304 | an approved one, or the ledger append failed (logged as |
| 305 | `generation record not written`). The commit still stands; a verifier treats |
| 306 | null as an absent claim, not a pass. The same limits as above apply: the |
| 307 | digest is of the file read at load time, the ledger is not signed, and the |
| 308 | record proves nothing about capability or authority. |
| 309 | |
| 310 | ### Tests |
| 311 | |
| 312 | - `crates/aien-runtime/tests/provenance_link_test.rs`: the real compose |
| 313 | library and the real daemon server, ordinary flow through the socket; |
| 314 | asserts the commit's records give a generation id whose `model_sha256` is the |
| 315 | loaded model's digest and the expected agent (an engaged ALLEN, and `none`). |
| 316 | - `crates/aien-cli/tests/provenance_link_live_test.rs`: the same with the real |
| 317 | `aien daemon` process, SmolLM2-1.7B on CPU, the real CLI. Ignored (needs a |
| 318 | prebuilt binary and the model). |