interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / docs / COMPOSE_PROPOSER_HOOK.md

232 lines · 15888 bytes Raw Blame History Rendered
1# Compose proposer hook (design note)
2
3Scope: how an approved proposal from an upstream approval desk (INTERPLANE
4`ComposeLedgerAuthority`, interplane#77) enters the production compose path.
5Line numbers are for the commit that adds this note. Since 2026-10-15 the
6compose code cited as spine.rs lives in crates/aien-runtime/src/compose/bridge.rs
7(same function names).
8
9## Entry point
10`ProposerHook::submit` (crates/aien-runtime/src/approved.rs:152) checks the
11proposal (`verify`, approved.rs:109), refuses duplicates, then calls
12`ComposeBridge::run_approved_task` (crates/aien-runtime/src/spine.rs:1362),
13which is `run_task_inner` (spine.rs:1371), the body `RunComposeTask` runs
14(server.rs:593 -> spine.rs:1351). The approved text is staged per task and
15the registered model Skill (spine.rs:1224) returns it instead of calling the
16`ComposeProposer` (spine.rs:1232); one attempt, the same template check, and edit
17= None (spine.rs:1245): an approved proposal never goes through
18`merge_edit_reply`, so an existing file is replaced byte-exact.
19
20## Path to J-Space and World commit
21`home.compose.run` (spine.rs:1412) -> `Compose::run`
22(crates/aien-omega-compose/src/lib.rs:302) -> `rxc_host_run` in omega
23`librx_compose.a` (omega.lock c0369e67, archive sha256 dfe0ffb8...): the Skill
24result is staged on a J-Space branch, AEGIS calls the bridge's verify callback
25(spine.rs:1273: result handle equals the Skill's text and it parses as one
26file change), the winner commits through the World, Cortex records goal,
27candidates, evidence and promotion (`cx_*` in `ComposeTaskReport`). The hook
28returns Ok only if the run committed exactly the approved text.
29
30## What the ledger hands over (`ApprovedProposal`)
31request_id, trace_id, approval_id, approver, path, content,
32approved_proposal_sha256, content_sha256, approval_mac, requirements, requirements_mac. `requirements` is the original goal text whose measurable
33requirements the approved bytes must meet; `requirements_mac` is the desk key's HMAC over the approval binding and that text (tag `aien.requirements.v1`), so
34a caller cannot swap or drop it. `Some("")` is a signed "no requirements"; a missing
35`requirements` is refused (`RequirementsUnbound`), a goal with an unreadable requirement
36is refused (`RequirementsUncertain`), and bytes that miss a requirement are refused
37(`RequirementsUnmet`), all before any claim or compose run. A count such as "add 2 lines to NOTES.md" is judged on the diff between the existing workspace file (empty when absent) and the approved bytes. Existing lines must all survive, so such an approval can only add. Such a goal also needs `requirements_base`: the sha256 (hex) of the existing file as the desk saw it, or `absent`, covered by `requirements_mac` (tag `aien.requirements.v2`; v1 when no requirement depends on the file). It is refused when missing (`RequirementsUnbound`) or when the file differs (`BaseChanged`), and it is checked again under the compose-home lock when the grant is written, so a file that changed after the check gets no grant. Limit: a file over 8192 bytes (or not UTF-8) cannot be measured and is refused. The hook returns
38`ApprovedComposeReport`: state (COMMITTED | ALREADY_COMMITTED), the same
39ids, compose_proposal_sha256, grant_links, desk_key_id, approval_key,
40replay_claim and the compose `task` report (None for ALREADY_COMMITTED); or
41`ApprovedRefusal` {refused_by, name, detail, request_id, trace_id,
42approval_id, replay_claim}.
43
44## Daemon command (#249 C)
45`ControlCommand::ComposeApprovedProposal { proposal, workspace }` on the
46daemon socket (same-user peer check, 0600 socket, like every compose
47command). Answered `ComposeApprovedResult(report)` or
48`ComposeApprovedRefused(refusal)`. It runs `ProposerHook::submit`; there is
49no unauthenticated variant. It writes nothing to the workspace. After the
50replay commit the daemon itself writes the one grant for the approval
51(`approved_grant` below) and returns its id (`approved_grant`) and target;
52the caller then needs only `ComposeEffectIntent` and `ComposeEffectAck`,
53both naming compose_proposal_sha256. A caller never writes its own grant
54for an approved write.
55
56## Daemon-written grant and workspace confinement (476ca4 A1/A1b)
57- **Approved grant.** Kind `authorization`, field `approved_grant: 1`,
58 keyed on `proposal_sha256 = compose_proposal_sha256`, naming `workspace`
59 (canonical), `target = workspace/path`, `prior_sha256`, `approval_key`,
60 `replay_claim`, `cx_promotion`, `cx_evidence`, `request_id`, `trace_id`,
61 `approval_id`, `desk_key_id`, `approved_proposal_sha256`; Cortex links
62 [cx_promotion, cx_evidence, replay_claim]. Reserved: `ComposeNote` refuses
63 any authorization carrying `approved_grant`. At the intent the daemon
64 requires the replay claim to be COMMITTED with the same approval key and
65 commit evidence naming the same proposal, promotion and evidence, and the
66 record to link all three. A crash between the replay commit and the grant
67 leaves the approval spent with no grant: no effect, a new approval is
68 needed (`approved_crash_test` boundary 3).
69- **Confinement, every grant.** `effects::confine_target`: the workspace is
70 an absolute canonical directory other than `/`; `path` has plain
71 components only; `target == workspace/path`; the target's directory
72 resolves (symlinks followed) to itself inside the workspace; an existing
73 target is a regular file, never a symlink. Checked when a grant is written
74 through `ComposeNote` and again at every `ComposeEffectIntent`. A grant
75 with no `workspace` opens no intent. `aien compose authorize` now writes
76 `workspace`; older unspent grants without it are refused (fail closed).
77- **Closed (sc#261): only daemon-minted grants are honoured.** `ComposeNote`
78 refuses every `authorization` record, whatever it says (also inside
79 `ComposeBridge::note`, so no in-process path writes one). Two grant kinds
80 exist, both written by the daemon:
81 - `approved_grant`, from `ComposeApprovedProposal`, backed by a COMMITTED
82 replay claim and the desk-key MAC (above);
83 - `minted_grant`, from the new `ComposeAuthorize` command that
84 `aien compose authorize` now sends. When the daemon's own compose run
85 commits a one-file proposal on the ordinary path it writes a reserved
86 `compose_commit` record (promotion, evidence, proposal digest, path,
87 content digest, canonical workspace). `ComposeAuthorize` names only the
88 promotion, the proposal digest, the workspace the operator expects and
89 the approver; path, content and target come from the commit record, so
90 the caller never supplies them. It is refused when no commit record
91 matches, when the workspace differs from the one the compose ran for,
92 when `confine_target` fails, or when an earlier grant for the same commit
93 is still live or has an unsettled intent. Revoked, stale and settled
94 (NOT_DONE) grants do not block a new one; each grant is spent once. After a
95 grant for a commit settled DONE, no new grant is minted for that commit:
96 one committed proposal gives at most one DONE effect (new content needs a
97 new compose).
98 At `ComposeEffectIntent` the grant is checked against its commit record.
99 - Old records: an `authorization` record with neither marker (written by a
100 client before this change) is read but never honoured. It opens no intent;
101 an intent it opened earlier is settled UNRESOLVED with `disk_error`
102 `NotDaemonMinted` (the world check never yields DONE or NOT_DONE for it),
103 and an operator cannot declare it DONE (an operator `--declare not_done` is
104 still accepted). An old committed proposal has no commit record, so it must be
105 proposed again before it can be authorized.
106 - The approval in the ordinary flow carries the desk-key MAC by default
107 (sovereign-core #297, required by default since #328, Drake decision b,
108 2026-10-08): `aien compose authorize ... --desk 1` signs it, and an
109 authorize without it is refused (`DeskMacRequired`). The daemon refuses to
110 start when the desk key is missing (`aien compose desk-key --create 1`
111 makes it). The only way back to the OS-user-only authorize is the dev
112 opt-out `AIEN_COMPOSE_AUTHORIZE_REQUIRES_DESK=0`, accepted only in a dev
113 run (`AIEN_DEV_FALLBACK=1`), refused in a strict run (which release
114 qualification is), and announced at startup as
115 `Authorize MAC: OFF, DEV OPT-OUT`. Code that embeds the runtime and builds
116 a bridge with `with_authorize_requires_desk(false)` is held to the same
117 rule: the server refuses to start with it in a strict run (the `aien
118 daemon` program never builds one). Bridge-level tests of the legacy path
119 call the bridge directly, without a server. Also, a
120 grant can exist only for content the daemon itself committed, at the
121 workspace and path the daemon recorded, and only the daemon writes it.
122 The approved-proposal path keeps its MAC.
123 `aien compose desk-key [--create 1]` prints the
124desk key id and path (never the key) and creates the key if none exists.
125
126## Authentication design (#249 A)
127Reused primitive: none of the existing grant records can carry it. A
128`ComposeNote` `authorization` grant is written by any same-user socket
129caller, so binding the approval to one would be caller text in two steps;
130the aien-mcp `ApprovalGrant` lives in the INTERPLANE process memory and the
131daemon cannot check it. So the smallest verifiable evidence is used:
132`approval_mac` = HMAC-SHA256 (RFC 2104 over the existing sha2 crate, no new
133dependency) keyed by the approval desk key, over the canonical binding
134(`approved_auth::binding_bytes`): compact JSON, keys sorted, of
135approval_id, approved_proposal_sha256, approver, content_sha256,
136desk_key_id, path, request_id, trace_id, workspace and
137`"v":"aien.approval.v2"`. `workspace` is the canonical absolute path
138(symlinks resolved): the daemon canonicalises the command's `workspace`
139and binds that, so a valid approval presented with another workspace fails
140the MAC (`Unauthenticated`, nothing consumed; 476ca4 c17), and the daemon's
141grant target is derived only from the bound workspace plus path. v2 because
142the binding gained a field (nothing was released under v1).
143The daemon recomputes it with its copy of the key and compares in constant
144time; anything else is `PROPOSAL_REFUSED Unauthenticated`.
145- Key: 32 bytes from /dev/urandom, `<compose dir>/approval-desk.key`,
146 64 lowercase hex, created 0600 with O_EXCL|O_NOFOLLOW. Every submission
147 re-loads it: a symlink, a non-regular file, another owner, any group or
148 other permission bit, or a malformed key is `NoDesk`. Only desk_key_id
149 (first 16 hex of sha256 of the key) is ever printed or recorded.
150- Confinement: the compose home and the submission's workspace must not
151 overlap (either inside the other), else `Confinement`: the model-facing
152 tools read inside the workspace, never the key or the journal.
153- What it proves: the holder of the desk key approved exactly these fields.
154 Not which human pressed approve: the desk (INTERPLANE host-only approval
155 continuation) names the approver, and the MAC stops anyone without the key
156 from changing it. Caller text can never carry a valid MAC.
157- Rotation / loss: replacing the key refuses every MAC made with the old
158 one (approvals issued and not yet submitted must be approved again);
159 claims already recorded keep their keys. Without a key every submission
160 is `NoDesk`.
161- Limit: the OS user is still the outer boundary; a process of the
162 daemon's user that can read the compose home can read the key.
163
164## Replay (#249 B, crate::approved_replay, session 476ca4)
165`approval_key` = sha256 of the binding above; the claim keys are the
166approval key, the request id and the approval id, each on its own. Order in
167`ProposerHook::submit`: verify -> reconcile gate -> desk key -> confinement
168-> MAC -> `claim` (durable `accepted`) -> `mark_in_flight` -> one
169`run_approved_task` -> `commit` | `fail` (ran, not committed) | `uncertain`
170(run error, or committed but not the approved text). A refused claim is
171returned with its state; a retry of the very same approval (all keys equal)
172whose claim committed gets the original result back as ALREADY_COMMITTED,
173never a second run. Daemon start runs `approved_replay::reconcile_at_start`
174after the effect reconcile (accepted -> not_executed, in_flight ->
175uncertain); a failure gates effect commands and approved proposals.
176
177## Hash semantics (fix)
178- approved_proposal_sha256 = sha256 of compact JSON {"content","path"} with
179 sorted keys (interplane#77). Checked, then carried for provenance.
180- compose_proposal_sha256 = sha256 of the committed text
181 `filename: <path>\n<content>`. The authorization grant and the
182 `ComposeEffectIntent` must name this value: `aien compose authorize` does
183 (crates/aien-cli/src/compose.rs:252) and `Ledger::check_intent` compares it
184 (crates/aien-runtime/src/effects.rs:341). Grant links = [cx_promotion,
185 cx_evidence], as compose.rs:271.
186- Content the template parser would normalise (no final newline, leading
187 blank line, code fence) is refused, so content_sha256 is the committed one.
188
189## Refusals (never silent)
190`PROPOSAL_REFUSED` `Unverified` (hash, ids, path, template round trip),
191`ReconcileFailed`, `NoDesk`, `Confinement`, `Unauthenticated` (nothing
192appended for any of these); `REPLAY_REFUSED <Name>` from the claim
193(AlreadyCommitted, AlreadyFailed, AlreadyConsumed, Uncertain, InFlight, ...);
194after a claim: `ComposeError` and `Mismatch` (claim UNCERTAIN),
195`NotCommitted` (claim FAILED); after the replay commit: `GrantNotWritten`
196(the approval is spent, no grant, no effect). At the intent:
197`EFFECT_REFUSED OutsideWorkspace`, and `NotAuthorized` for a grant with no
198workspace or an approved grant without its committed backing. At ack and
199reconcile the confinement runs again (476ca4 c28/c28b: a parent directory
200swapped for a symlink after the intent): if it refuses, the state recorded is
201UNRESOLVED with `disk_error` `OutsideWorkspace: ...`, never DONE, and an
202operator declaration of DONE is refused.
203
204## Deferred
205- The effect receipt (`record_effect_receipt`) still has no request_id or
206 trace_id (#76; see below). The replay `accepted` record carries
207 `request_id` and `trace_id` (and `approval_id`, `approval_key`).
208- Real model leg NOT_RUN; no GPU.
209
210## Correlation for retained records (#76, design note only)
211Today trace_id and request_id survive in: the command's report and refusal
212(`request_id`, `trace_id`), the replay `accepted` record (Cortex host
213record, kind effect, fields `request_id`, `trace_id`, `approval_id`,
214`approval_key`), and the compose goal text (request only). Since the A1 fix the
215daemon's approved grant carries `request_id`, `trace_id` and `approval_id`
216and links the replay claim; the intent and ack records and
217`record_effect_receipt` still carry neither.
218Recommended: option B, bind rather than re-version: a verifier walks
219ack -> intent (`authorization`) -> approved grant (`replay_claim`, Cortex
220link) -> claim and reads trace_id/request_id from the immutable claim
221record (and the grant text). Receipt files stay version 1. Done by the A1
222fix: the grant links the claim; a grant whose claim is not COMMITTED with
223matching evidence is refused at intent; the approved grant cannot be
224forged. Tests still to add: walk from an ack recovers trace_id and
225request_id; `record_effect_receipt` for approved writes names the grant.
226
227## Native vs stub in the recall reply (VAC M3a)
228`ComposeRecallReport` (reply to `ComposeRecall`) carries `compose_native: bool` (the native Omega
229composition library is linked, not the stub) and `omega_sha: String` (the pinned omega commit, 40 hex;
230empty for the stub). Both are `#[serde(default)]`, so older replies still read as stub. The daemon also
231prints `Compose: native (omega <sha>)` or `Compose: STUB (...)` at startup. An offline verifier uses
232these to refuse a "native" claim from a stub daemon.