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 / plans / tracing / DESIGN-398.md
| 1 | # Unified execution tracing (aien-sovereign-core#398): design and limits |
| 2 | |
| 3 | Owner: campaign session 1ea888, 2026-10-10. Branch `feat/unified-execution-tracing-398`. Inventory of the |
| 4 | identifiers this joins on: `INVENTORY-398.md` (same folder). Crate: `crates/aien-trace` (serde and serde_json only). |
| 5 | |
| 6 | ## What a trace is, and is not |
| 7 | |
| 8 | A trace is a correlation record: one event per boundary crossing of one run, each with a parent, joined by |
| 9 | stable ids that already exist in the runtime. It is observational. It never authorizes anything (the |
| 10 | `AuthorizedEffect` mint and the compose grant stay where they are), and it is never proof: proof is the |
| 11 | compose ledger with its record marks, the effect receipts, the generation record and the independent |
| 12 | verifier (`tools/aien-verify`). Every event points at proof by digest or relative path and carries no |
| 13 | prompt, tool argument, model output, file path or memory item; the type system enforces that (the only free |
| 14 | text is a 64 byte note with `<`, `>` and control characters removed, and the runtime writes only fixed labels |
| 15 | and refusal names into it). |
| 16 | |
| 17 | ## Field mapping (contracts C1 and C2 in `~/workspace/six-issues/COORDINATION.md`) |
| 18 | |
| 19 | | Event field | Source | Note | |
| 20 | |---|---|---| |
| 21 | | `trace_id` | swarm: `TraceId::derive(root_world_id, swarm_id, 0)` per swarm; compose daemon: one per `ComposeBridge` (derived from start time and pid); when a request came through Interplane the Interplane `trace_id` (32 lowercase hex) is copied into `ids.interplane_trace_id` | C1: Interplane's id is the cross-boundary join key; AIEN never re-mints it | |
| 22 | | `ids.interplane_message_id`, `ids.interplane_request_id` | Interplane envelope and CapabilityRequest ids | C1, bounded to 64 chars | |
| 23 | | `status` | one to one with the AEGIS `FailureClass` plus `ok` | C2: `rejected` also covers Interplane denied, not_found, invalid; `approval_pending` is terminal for the attempt and not a failure | |
| 24 | | `effect_certainty` | `no_effect`, `uncertain`, `effect_occurred` | C2 `EffectCertainty`; `uncertain` is aien-mcp `CallOutcome::Uncertain` or a compose intent settled UNRESOLVED, and is never retried by anything that reads a trace | |
| 25 | | `refs.intent_digest` | `aien_mcp::authority::intent_digest` | names the intent, never its arguments | |
| 26 | | `refs.effect_receipt_digest` | `aien_mcp::receipt_digest` (canonical encoding with sorted keys, sha256) | the receipt itself stays in the ledger | |
| 27 | | `ids.generation_record` | compose ledger record id from `write_task_generation` | evidence pointer | |
| 28 | | `ids.decision_id` | compose: the cx promotion (authorize) or the commit record id (model turn) | what was decided about | |
| 29 | | `ids.grant_id` | compose grant record id, or the broker approval id hex | authorization pointer, not authority | |
| 30 | | `ids.tool_request_id` | compose effect intent record id, or the broker tool request id | one effect attempt | |
| 31 | |
| 32 | ## Where events are emitted |
| 33 | |
| 34 | | Stage | Site | Event, status | |
| 35 | |---|---|---| |
| 36 | | swarm launch | `SwarmManager::launch_swarm` | `swarm_launched` ok (root event of the swarm trace) | |
| 37 | | branch fork | `SwarmManager` where branch worlds and sequences are created | `branch_forked` ok, parent root | |
| 38 | | admission, preemption | `TraceDecisionObserver` (aien-runtime `trace_observer.rs`) on the scheduler's existing `DecisionObserver` tap; admitted from `admission_examined` verdicts `AdmittedPrefill`/`AdmittedDecode`, preempted from `choice.preempted` | `sequence_admitted`, `sequence_preempted` | |
| 39 | | branch finished | `note_sequence_finished` | `sequence_finished` ok | |
| 40 | | cancel | `cancel_swarm` | `swarm_cancelled` cancelled | |
| 41 | | broker authority | `EffectLane::authorize` (aien-mcp) | `authority_decided` ok / approval_pending / rejected, note = reason label (`provider_not_admitted`, `refused`, ...) | |
| 42 | | broker effect | `EffectLane::execute` (Finished, Rejected, Uncertain, ledger replay, in-flight duplicate) | `effect_executed` ok+effect_occurred / rejected+no_effect / uncertain / `in_flight`; child of the lane's parent event (an `AuthorizedEffect` carries no event id) | |
| 43 | | compose model turn | `ComposeBridge::run_task_inner` after the commit record is written | `model_turn` ok with `generation_record` and `decision_id` = commit id, note `compose_commit` or `uncommitted`; proposer error: `model_turn` failed, note `proposer_error` | |
| 44 | | compose authority | `effects::authorize` | `authority_decided` ok (`grant_id` = grant record) / rejected+no_effect (note = refusal name) / failed | |
| 45 | | compose intent | `effects::open_intent` | `tool_requested` ok (`tool_request_id` = intent record, `grant_id`) / rejected (refusal name) / failed | |
| 46 | | compose ack | `effects::ack` | `effect_executed` ok+effect_occurred (DONE) / rejected+no_effect (NOT_DONE: the world check says the effect did not happen, a definite no-effect outcome, not "ran and errored") / uncertain+uncertain (UNRESOLVED) / rejected (refusal name) / failed (other error) | |
| 47 | | compose reconcile | `effects::reconcile` (also `reconcile_at_start`) | `result_received` ok (note = caller label) or failed (`reconcile_failed`), one per call, `tool_request_id` when one intent was declared | |
| 48 | |
| 49 | The compose bridge's first event is the root of its trace and every later event is its child (the bridge |
| 50 | has no per-task context today; the ids join the rows). The scheduler crate is not modified. No event is |
| 51 | emitted from inside a kernel launch, a KV block operation or a decode step. |
| 52 | |
| 53 | ## Exporter, cardinality, buffering, retention |
| 54 | |
| 55 | - Default sink is `NullSink` (disabled): `enabled()` is false; every compose emit site checks |
| 56 | `trace_enabled()` before building ids, so no event is built, no clock is read and no id string is allocated |
| 57 | (the swarm and broker sites pass ids that already exist). The daemon installs `BoundedJsonlSink` only when |
| 58 | `AIEN_TRACE_JSONL` names a file (`server.rs: trace_sink_from_env`; append only, one JSON object per line); a |
| 59 | flusher thread writes every 250 ms and once more when the handle drops at the end of `run`, after the compose |
| 60 | home closed. The path must be a regular file or absent: a symbolic link is refused on every flush (the batch is |
| 61 | counted as dropped, nothing is written through the link), the file is created 0o600 and set back to 0o600 on |
| 62 | every flush, so a mode widened between flushes does not persist. |
| 63 | - Cardinality: at most one event per boundary crossing, so per run about `2 + 2 x branches + 3 x tool |
| 64 | calls + reconcile rows`. There is no per-token or per-step event. |
| 65 | - Buffering and backpressure: a bounded in-memory queue (default 4096 events) under a mutex held only for |
| 66 | the push; `emit` never blocks and never does I/O. When the queue is full the event is dropped and counted; |
| 67 | the next flush appends one `trace_dropped` event with the count. `dropped_total()` is the lifetime count. |
| 68 | - Retention: the file is append only; the crate never deletes or rotates; the operator rotates by moving the |
| 69 | file between daemon runs. |
| 70 | - Failure independence: if the sink is disabled, full, or the file is unwritable, inference and the compose |
| 71 | path are unaffected; security-critical evidence is written by the ledger, not by the trace. |
| 72 | |
| 73 | ## Tamper statement |
| 74 | |
| 75 | Editing, deleting or forging exported events changes nothing the runtime decides: `execute` needs an |
| 76 | `AuthorizedEffect`, which only `EffectLane::authorize` mints; the compose daemon executes only against a |
| 77 | grant in its ledger under a record mark; `tools/aien-verify` reads the ledger and receipts, not traces. A |
| 78 | forged `authority_decided ok` event is just a line in a file. The provenance guard test |
| 79 | (`provenance_is_read_by_no_decision_code`) still holds: the trace wrappers read the response, never the |
| 80 | provenance fields. |
| 81 | |
| 82 | ## Overhead (measured; numbers in the PR body) |
| 83 | |
| 84 | `crates/aien-runtime/tests/trace_overhead_benchmark.rs` runs the same 64-branch swarm workload on the |
| 85 | reference CPU backend with `NullSink` and with `MemorySink` and prints elapsed milliseconds |
| 86 | (`TRACE_OVERHEAD kind=... elapsed_ms=...`). The PR body records release-build numbers with host, commit and |
| 87 | load at the time. The LINEAR and BRANCH model-serving cases of the issue are not measured here: the swarm |
| 88 | workload has no model forward pass, so the measured overhead is that of the scheduling and event path only. |
| 89 | |
| 90 | ## Limits |
| 91 | |
| 92 | - Interplane ids arrive only when interplane#97 lands its adapter; until then `interplane_*` are empty. |
| 93 | - The scheduler observer emits only what `AdmitPreemptRecord` carries. |
| 94 | - Trace ids are correlation keys derived from counters and start times, not secrets and not unique across |
| 95 | machines. |
| 96 | - The compose bridge has one root per daemon start, not one per task; join tasks by `generation_record`, |
| 97 | `decision_id`, `grant_id` and `tool_request_id`. |
| 98 | - Broker `effect_executed` events are children of the lane's parent, not of the matching |
| 99 | `authority_decided` (the `AuthorizedEffect` type is frozen and carries no event id). |
| 100 | - Tie order of events in the same millisecond is by `event_id`; not stressed with many concurrent emitters. |
| 101 | - OTEL export is out of scope (a separate concern per the issue). |
| 102 | |
| 103 | ### Recorded from the independent review of PR #400 (2026-10-10, 0 blocking, 9 minor) |
| 104 | |
| 105 | Fixed before merge: NOT_DONE is `rejected` + `no_effect` (was `failed`); the exporter refuses a symbolic link at |
| 106 | the path and resets the mode to 0o600 on every flush; the compose emit sites check `trace_enabled()` before |
| 107 | building ids. Kept as limits of this version: |
| 108 | |
| 109 | - `timed_out`, `unavailable` and the `Cancelled`/`TimedOut` kinds exist in the type and are emitted by no site |
| 110 | yet (the broker has no timeout path of its own today; the Interplane adapter will carry them). |
| 111 | - The `trace_dropped` marker has no parent and no `last_trace` field; it is a per-file loss count, not a tree node. |
| 112 | - Swarm trace ids derive from counters and start time, so one appended file across daemon restarts can repeat an |
| 113 | id; join on `event_id` order within a restart, or rotate the file between runs (retention note above). |
| 114 | - Digests are unsalted sha256 of canonical encodings: they name content, they do not hide it from someone who |
| 115 | already holds the content. |
| 116 | - The overhead benchmark compares `NullSink` with `MemorySink` on the scheduling path only. The reviewer's own |
| 117 | release-build run (64 branches, load about 3.5) measured off 8.44/6.68/6.48 ms against on 9.66/7.36/7.04 ms: |
| 118 | a small overhead within a few milliseconds, not proven to be noise. |
| 119 | - `TraceContext::child` is not synchronised across threads; one context per thread is the intended use. |