aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
GitHub aien-dev/aienux#282 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/c2b05b665f345e6f.bundle -o c2b05b665f345e6f.bundle git fetch c2b05b665f345e6f.bundle refs/pull/282/head
Provenance
github-import 1
aien-dev/aienux
282
43412a78b2d6b023dcb0b81d335eb65906fc017c
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":282,"url":"https://github.com/aien-dev/aienux/pull/282","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:07Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 64bacc4a..20b67c13 100644 --- a/.crumb +++ b/.crumb @@ -27,33 +27,33 @@ "purpose": "Directory crates. Purpose not yet described by a human." }, { - "digest": "3337a47e3776a3c4a11e1b1d54403261f7fd4bccbdd70a4b61528b8a9e389a43", - "last_commit": "827e20f", + "digest": "a252348440fc99cd39be36019cb30bf8a01b6e2a0b6dcce89828ebde5e18d367", + "last_commit": "c410191", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { "digest": "6ec8efdee4ce06964bc8260d9199d85baccf82526ea453cd0f945638c3aa8002", - "last_commit": "d4cbc58", + "last_commit": "fa209e4", "name": "native", "purpose": "Directory native. Purpose not yet described by a human." }, { "digest": "7d70831f94533a1e6384ecc1b1ea8a2bf7bed6944aed041203cf0e0e844c0a5c", - "last_commit": "a4d6244", + "last_commit": "fa209e4", "name": "scripts", "purpose": "Directory scripts. Purpose not yet described by a human." } ], - "children_root": "sha256:94195cffe609c59a4895231f1afa128a9416268b37515c180facdf28a17c55f8", - "compiled_at": "2026-10-08T13:56:48Z", + "children_root": "sha256:743a43d04dca2217a0cdfcf9e8c47d3efd080f99daa101fc25fb84804a02dcc5", + "compiled_at": "2026-10-08T14:56:09Z", "compiler": "crumb-compile/1", - "digest": "sha256:9d3b84e59ac7e27ebd14fd18fe252056b9f97bd437f1227f1227eaf7a927a987", + "digest": "sha256:4d25e8d0a047d5df87a5d25ad55cc6606be3e6c8289c6951ff440269e0ab630b", "evidence_files": 153, "evidence_root": "sha256:29aa8775feb12d9e0e64b41fc1fc48b97e32dc16bf9176562cbe9fe1ea934f00", - "files": 2970, - "generated_at_commit": "d4cbc5836faa71ab3d6e35de2d060e8af3351c4c", - "source_tree": "sha256:f157220af64ea91cb18f4470ab1601977c4c3b3030af22c891287317c3ed0854" + "files": 2971, + "generated_at_commit": "c4101915eb9f0babc01b25f62a86c5a2f00708e5", + "source_tree": "sha256:18e60c745e05f634896ed18132a71c74a49ff234f7781400d2e1f5ad69b82ca3" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index c9e1521f..0a1fd987 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -17,8 +17,8 @@ "generated": { "children": [ { - "digest": "97b2985e62f1f3cd6977c23c0c924cd7ce02c2aa635a06eb424c6b1fe9ebd3f0", - "last_commit": "fef6fe4", + "digest": "3de6d16c0e46eb82e0eeb6de63973cc3ab3d995f18d9ad30eceac263d0209fa6", + "last_commit": "c410191", "name": "adr", "purpose": "Directory docs/adr. Purpose not yet described by a human." }, @@ -29,15 +29,15 @@ "purpose": "Directory docs/crumbs. Purpose not yet described by a human." } ], - "children_root": "sha256:b45190ec82f8e2a2101aed670d7e48b08c2e55d9674785ff0c784dff76ab2468", - "compiled_at": "2026-10-08T11:41:36Z", + "children_root": "sha256:55bcc89f5282eb2e3f4e86d882abdfb5f4ea39e427ef97ef620b2267e5701eb1", + "compiled_at": "2026-10-08T14:56:09Z", "compiler": "crumb-compile/1", - "digest": "sha256:3337a47e3776a3c4a11e1b1d54403261f7fd4bccbdd70a4b61528b8a9e389a43", + "digest": "sha256:a252348440fc99cd39be36019cb30bf8a01b6e2a0b6dcce89828ebde5e18d367", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 62, - "generated_at_commit": "f4c8d8dc15d73c80929fd3128caaa01d96ce3fb5", - "source_tree": "sha256:67c9b4f88ce6396ca42e9d45548682bfd35b287e1b49150d69d0c21ea7e04916" + "files": 63, + "generated_at_commit": "c4101915eb9f0babc01b25f62a86c5a2f00708e5", + "source_tree": "sha256:10655481a16e29bbb4777f76efa19998f19063876fcd6e7561a5ef5252193d36" }, "owner_lane": "", "provenance": { diff --git a/docs/adr/.crumb b/docs/adr/.crumb index 9535ae00..42a058cb 100644 --- a/docs/adr/.crumb +++ b/docs/adr/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-08T10:54:55Z", + "compiled_at": "2026-10-08T14:56:09Z", "compiler": "crumb-compile/1", - "digest": "sha256:97b2985e62f1f3cd6977c23c0c924cd7ce02c2aa635a06eb424c6b1fe9ebd3f0", + "digest": "sha256:3de6d16c0e46eb82e0eeb6de63973cc3ab3d995f18d9ad30eceac263d0209fa6", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 21, - "generated_at_commit": "94e8d58c6598d71f67ecf7b94ab65cb369a63bf6", - "source_tree": "sha256:0e4bd7a7252bee29ed148d7bfce8c8088df964f49dda98865db53a2e774a9ce2" + "files": 22, + "generated_at_commit": "c4101915eb9f0babc01b25f62a86c5a2f00708e5", + "source_tree": "sha256:b0a6020e0f462cce3b3deeba994e2184a1def7e0c9608233312c5763c49920fe" }, "owner_lane": "", "provenance": { diff --git a/docs/adr/0014-binary-artifact-v0-and-native-admission.md b/docs/adr/0014-binary-artifact-v0-and-native-admission.md index 3b18764e..9b538fdc 100644 --- a/docs/adr/0014-binary-artifact-v0-and-native-admission.md +++ b/docs/adr/0014-binary-artifact-v0-and-native-admission.md @@ -476,6 +476,6 @@ Decision record: the operator was offered three choices on aienos#277 (record th 2. **Separate parsers and admission paths.** Each container has its own parser and admission path. Neither path calls the other's parser, and section 5 of this ADR still has no OSC unit responsibilities. Bytes reach both paths the same way (section 1: firmware or the Store is a byte provider only; the kernel copies to protected staging before parsing). 3. **Limits (spec conflict C3).** The limits of section 4 ("Maximum section count: 2", 16 MiB per artifact, 8 MiB payload, 16 capabilities) apply to Binary Artifact v0 only. An OSC unit is held to the limits of its own spec (section 7 there: 4 sections, 2 MiB, 16 capabilities), plus any stricter limit compiled into the kernel, which is part of the kernel's identity and cannot be relaxed by the unit. Today that is the native staging limit of 160 pages (655,360 bytes) per artifact. 4. **Trust anchors (spec conflict C2).** Unchanged from the amendment note above: each path trusts only its own anchors, a qualification build may hold the spec's TEST key for the OSC unit path, and a release image holds no test key for either path. OSC unit OWNER anchors stay empty until TRUST-1 (ADR 0017) provisions them. -5. **Pinned generations (spec conflict C1, AIENOS position).** No AIENOS ADR yet defines a per-resource generation that an OSC unit capability request could pin. Until one does, the OSC unit admission path refuses every request that pins a nonzero `required_generation`, because the kernel has no generation to compare it with. The refusal code follows the spec's fixed check order (its section 8.2): a request on an unsupported domain is refused `CAP_DOMAIN_UNSUPPORTED` (27) first, a domain-1 value wider than 32 bits `CAP_GEN_NOT_REPRESENTABLE` (28) next, and any remaining nonzero pin `CAP_GENERATION_STALE` (29). AIENOS supports domain 1 only. That direction only ever refuses more, never admits more. Defining a per-resource generation is a later AIENOS amendment; it needs no byte change in the container. +5. **Pinned generations (spec conflict C1, AIENOS position).** No AIENOS ADR yet defines a per-resource generation that an OSC unit capability request could pin. Until one does, the OSC unit admission path refuses every request that pins a nonzero `required_generation`, because the kernel has no generation to compare it with. The refusal code follows the spec's fixed check order (its section 8.2): a request on an unsupported domain is refused `CAP_DOMAIN_UNSUPPORTED` (27) first, a domain-1 value wider than 32 bits `CAP_GEN_NOT_REPRESENTABLE` (28) next, and any remaining nonzero pin `CAP_GENERATION_STALE` (29). AIENOS supports domain 1 only. That direction only ever refuses more, never admits more. Defining a per-resource generation is a later AIENOS amendment; it needs no byte change in the container. Update 2026-10-08: [ADR 0019](0019-per-resource-capability-generation.md) (Option 3, accepted) defines it as a per-resource incarnation counter, to be built in the first change that lets a resource number be reused or persisted (aienos#285); until then this refusal stands unchanged. 6. **Admitted is not Admitted.** Section 5 of this ADR reaches `Admitted` only after a canary run. The OSC unit path defines no canary, so an accepted OSC unit is reported as accepted by its own path, never as `Admitted` in the sense of section 5, and no Admission Receipt v0 (section 7) is issued for it. A canary and a receipt for OSC units are later work. 7. **Evidence boundary.** The OSC unit path in aienos#277 is qualified in QEMU only. A QEMU pass is not a result on the physical Spark. diff --git a/docs/adr/0019-per-resource-capability-generation.md b/docs/adr/0019-per-resource-capability-generation.md new file mode 100644 index 00000000..78ea69a7 --- /dev/null +++ b/docs/adr/0019-per-resource-capability-generation.md @@ -0,0 +1,97 @@ +# ADR 0019: Per-resource capability generation (OSC unit `required_generation`, domain 1) + +Status: Accepted, Option 3 (operator, 2026-10-08). The counter is not built yet; its trigger is tracked in aienos#285. +Date: 2026-10-08 +Amends: [ADR 0013](0013-aienos-abi-v1.md) (adds a resource generation beside the handle generation), [ADR 0014](0014-binary-artifact-v0-and-native-admission.md) (replaces amendment "the OSC unit is a second container type", point 5). +Governing: [ADR 0012](0012-self-construction-capability-growth-and-generations.md) (rule 5: no native admission without enforcement), [aien-protocols](https://github.com/aien-dev/aien-protocols) `specs/osc-unit-artifact/OSC_UNIT_ARTIFACT.md` (v1 FROZEN, read at `666100969cedb97eded6533906c42307320ea61c`), sections 6.3, 8.2 step 15 and 15.3 C1. + +## Context + +An OSC unit capability request (spec section 6.3, bytes 48 to 63) carries `domain` and `required_generation`. Zero means "no requirement". A nonzero value means "admit this request only if the resource is currently at exactly this generation". The spec says the loader supplies that counter per (`domain`, `resource_kind`, `resource_id`), and forbids filling it from a handle-slot generation or a system Generation "until an AIENOS ADR defines a per-resource generation" (section 6.3, last rule; section 15.3 C1). + +Before this ADR, no AIENOS ADR defined one. The position until then (ADR 0014 amendment point 5, aienos#277) is fail closed: AIENOS supports domain 1 only and refuses every nonzero pin, in the spec's fixed order: `CAP_DOMAIN_UNSUPPORTED` (27), then `CAP_GEN_NOT_REPRESENTABLE` (28) for a domain-1 value above `0xFFFFFFFF`, then `CAP_GENERATION_STALE` (29) for any remaining nonzero pin. The kernel does this with a lookup that always reports "no such resource" (`native/kernel/core/osc_admit.c`, `no_resource`, passed as `gen_lookup`; the check is `native/kernel/artifact/osc_unit.c`, spec step 15c). Host tests pin the check itself (`native/kernel/tests/test_osc_unit.c`): vector `r18` gives code 28 (`vectors/expected.txt`), and `vectors/state.txt` admits `a02` (domain 1, kind 3, id 1, pin 7) when the test lookup reports 7 and refuses it 29 when the lookup reports 8. The kernel's own always-refuse lookup is exercised by the QEMU gate since aienos#284 (`fa209e45`): `scripts/qemu_ck_osc_unit_test.sh` loads `a02` and requires `REFUSED code=29 name=CAP_GENERATION_STALE` in the qualification build (and `24`, `TEST_SIGNER_IN_RELEASE`, in the release build, where the class check comes first). + +### What AIENOS already counts (none is a per-resource generation) + +| Counter | Where | Width | What it counts | +|---|---|---|---| +| Handle generation | ADR 0013 "Handles"; `crates/aienos-kernel/src/caps.rs`, `native/kernel/core/ipc.c` | u32 | Reuse of one slot in one task's capability table. Starts at 1, never wraps, slot retired at `u32::MAX`. | +| Authority reference generation | `crates/aienos-capability/src/lib.rs` (`CapRef`, `Entry.generation`) | u32 | Reuse of one slot in the native authority table, same rules. | +| Authority epoch | same crate, `bump_epoch` | u64 | Whole-authority invalidation: an entry from an older epoch is refused. | +| Boot generation | same crate, `take_boot_gen` | u32 | Each authority instance starts higher than the last. | +| System Generation | ADR 0012; ADR 0014 receipt `generation_context_id` | u64 | Which system image is running. | + +None of these belongs to a resource. A handle or reference generation belongs to a table slot, which does not exist when a unit is admitted (spec section 15.1 row 55). The epoch and the system Generation change for reasons unrelated to any one resource, and the 64-bit ones cannot be represented in domain 1 anyway. + +### What the kernel's resources look like today + +Domain-1 resources are kernel channels and objects (ADR 0013 `ResourceKind` 2 and 3). Two numberings exist today, and both are fixed by the kernel image. The C kernel names its IPC channel and object with the constants `CK_IPC_CHANNEL_RESOURCE` (`0x49504348`) and `CK_IPC_OBJECT_RESOURCE` (`0x49504f42`) in `native/kernel/core/ipc.h`. The Rust kernel's Binary Artifact v0 path names its seed object `SEED_OBJECT_ID` (1) in `crates/aienos-kernel/src/task_runtime.rs`. The C kernel's OSC unit admission knows no resource at all (`no_resource`); vector `a02` pins object 1, which matches neither C constant. No code path in either kernel destroys a channel or object and hands its number to a different one (handle removal and revocation free table slots, not resources; artifact teardown frees tasks, frames and handles). So the problem a per-resource generation solves (a signed request naming resource number N meant the old N, and N now names something else) cannot happen on today's kernel. It becomes possible the first time the kernel creates and destroys channels or objects at run time, or persists resources across reboot or rollback. + +## Decision drivers + +1. A pin must never admit more than today without an explicit operator decision. Today every nonzero pin is refused; any option that starts admitting some pins widens behavior and must say so. +2. No counter may be filled from a handle-slot generation, an authority epoch, a boot generation or the system Generation (spec 6.3). +3. No byte change in the frozen container (spec C1 was settled as "Option A without a byte change"). +4. Rollback (ADR 0012) must never make a counter go backwards, or an old signed pin could match a new resource. + +## Options + +### Option 1: "Domain-1 resources have no generation", made permanent + +What it is: AIENOS declares that kernel resources carry no generation, now and for ABI v1. `required_generation` must be 0 for domain 1; any nonzero value stays refused exactly as today (28 or 29). ADR 0014 point 5 stops being "until an ADR defines one" and becomes the rule. + +- Upside: nothing to build, prove or persist. Matches the kernel exactly (fixed resource numbers, no reuse). Behavior is byte-for-byte today's. +- Downside: signers can never pin a resource version. When the kernel gains dynamic resources, number reuse protection has to come from somewhere else (for example never reusing numbers), or this ADR is reopened. The spec's domain-1 generation field becomes permanently dead weight, which argues for dropping it in a future container version (spec C1 Option B). +- What changes: one ADR paragraph. No code, no vectors. +- Undo: a later ADR can define a generation; that would widen admission and needs its own operator decision. + +### Option 2: Define a resource incarnation counter and build it now + +What it is: every domain-1 resource number gets an incarnation counter (u32) with the ADR 0013 handle rules: 0 is never issued, the first resource to hold a number is at 1, each time the number is given to a new resource the counter goes up by 1, it never wraps, and a number whose counter reaches `u32::MAX` is retired. The loader's `gen_lookup` returns the current counter; a pin equal to it is admitted, anything else is STALE. A persistent resource stores its counter with it, and rollback never lowers a stored counter. A resource whose counter cannot be shown to be monotonic across reboot and rollback answers "no such resource", so its pins stay refused. + +- Upside: completes what the spec intends; real protection against number reuse; one meaning shared by both container paths. +- Downside: new kernel state and, for persistent resources, a Store format change (ADR 0015 is frozen for P3-1; ADR 0016 says its format freeze needs operator approval). Kernel code, host tests, new vectors and a QEMU gate, for a counter that reads 1 for every resource on today's kernel. It widens admission: a unit pinning 1 on a fixed resource, refused today, would be admitted. +- What changes: kernel lookup, capability bookkeeping, possibly the Store format, vectors and gates. Roughly one campaign cut plus its reviews and QEMU runs. +- Undo: reverting the code returns to refusal; the persisted counters would remain as unused data. + +### Option 3: Define the counter now, build it when resources become reusable (recommended) + +What it is: this ADR adopts the incarnation counter of Option 2 as the contract (same rules, same rollback and fail-closed clauses), but the kernel keeps `no_resource` and keeps refusing every nonzero pin. Building the counter is tied to a named trigger: the first kernel change that lets a resource number be destroyed and reused at run time, or that persists a domain-1 resource across reboot or rollback. That change must implement the counter in the same cut, and its PR must state openly that pins which were refused become admissible (driver 1). + +- Upside: costs nothing now and changes no behavior (refusal stays exactly as today). Gives the signed field a fixed meaning, so spec C1 is closed and the frozen container never needs a byte change. The work lands exactly when it starts protecting something. +- Downside: a defined but unbuilt rule can drift from the code if the trigger is missed; the trigger cut carries extra work. Until then signers still cannot pin. +- What changes: this ADR, plus a one-line pointer in ADR 0014 point 5. No code, no vectors. +- Undo: Option 1 or Option 2 can still be chosen later; nothing is built that would need removing. + +### Rejected without an option + +- Fill the counter from the handle-slot generation, the authority epoch, the boot generation or the system Generation: forbidden by spec 6.3, and each counts something other than the resource (table above). The 64-bit counters also fail driver 3 for domain 1. +- Change the container to drop the field (spec C1 Option B): a byte change in a frozen spec, out of scope for an AIENOS ADR. + +## Recommendation + +Option 3. It keeps today's fail-closed behavior, writes down the one meaning that fits the spec's rules, and spends engineering effort only when the kernel can actually reuse a resource number. Option 1 is the right choice if the operator prefers to keep ABI v1 minimal and drop pinning in a later container version. + +## Decision + +Option 3, accepted by the operator on 2026-10-08. The operator handed over an outside review of this draft that recommended Option 3 and asked for two follow-ups; under the operator's standing rule, material he hands over is his approval. The follow-ups are done here: + +1. The evidence text now reflects aienos#284 (the QEMU gate runs the kernel's own lookup). +2. The implementation trigger is a tracked prerequisite: aienos#285. The first change that lets a domain-1 resource number be reused, or persists a domain-1 resource across reboot or rollback, must build the counter in the same cut, with tests for match, mismatch, reuse and reboot or rollback. + +Until aienos#285 is done, every nonzero pin stays refused (`CAP_GENERATION_STALE`), exactly as today. + +## Invariants (all options) + +1. A nonzero `required_generation` is admitted only if `gen_lookup` returns a counter equal to it; any lookup failure is STALE. +2. No counter is ever derived from a handle-slot generation, authority reference generation, authority epoch, boot generation or system Generation. +3. A counter never decreases, including across reboot and rollback; 0 is never issued. +4. Domain 2 (hosted, 64-bit) stays unsupported by AIENOS (`CAP_DOMAIN_UNSUPPORTED`); this ADR does not define it. +5. Any change that admits a pin refused before must say so in its PR and record the operator's approval. + +## Evidence and limits + +- Facts above were read on 2026-10-08 from aienos `origin/main` at `827e20f4` (rechecked at `fa209e45` for the gate) and the spec at aien-protocols `666100969ced`. No code was run by this ADR itself; the runs cited below are aienos#284's. +- This ADR changes no code, vector or gate. Kernel behavior stays: every nonzero pin refused. +- The kernel's refusal of a nonzero pin is run, not only read: aienos#284 (`fa209e45`) added `a02` to the QEMU gate. Red first: with the lookup made permissive (uncommitted), the gate failed on exactly the a02 line and the totals; with the real lookup it passed 34 of 34 checks (QEMU aarch64 virt, TEST signer, not physical). +- QEMU is the only place the OSC unit path has run; nothing here is a physical-Spark result. diff --git a/docs/adr/README.md b/docs/adr/README.md index 047f671d..b9d8b25b 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -23,6 +23,7 @@ This directory documents the key architectural decisions and formal technical sp | [ADR 0015](0015-system-store-v1-format.md) | AIENOS System Store v1 Format | Accepted for P3-1 format freeze | 2026-09-25 | [ADR 0003](0003-bootstrap-firmware-handoff-and-minimal-object-store.md); P3 Native Persistence & Continuity | | [ADR 0016](0016-continuity-objects-over-store-v1.md) | Continuity objects over System Store v1 | Proposed (format freeze needs operator approval) | 2026-09-25 | [ADR 0007](0007-continuous-existence-provisioning-once.md), [ADR 0015](0015-system-store-v1-format.md); M4 continuity | | [ADR 0018](0018-allen-subject-state-object.md) | ALLEN Subject State Object (continuity kind 24) | Proposed (companion to ARCH-0035; format freeze needs operator approval) | 2026-10-04 | [ADR 0016](0016-continuity-objects-over-store-v1.md); omega ARCH-0022 Cortex; R16 | +| [ADR 0019](0019-per-resource-capability-generation.md) | Per-resource capability generation (OSC unit `required_generation`, domain 1) | Accepted (Option 3; counter tracked in aienos#285) | 2026-10-08 | [ADR 0013](0013-aienos-abi-v1.md); [ADR 0014](0014-binary-artifact-v0-and-native-admission.md) amendment point 5; aien-protocols `specs/osc-unit-artifact` section 15.3 C1 | ---