aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / docs / plans / dual / DUAL_CURRENT_STATE.md
| 1 | # DUAL Constraint Pricing - Current State and Slices |
| 2 | |
| 3 | **NOT A MASTER PLAN.** This is a finite workstream document for ADR 0031 (ARCH-0031), DUAL constraint pricing. `CURRENT_EXECUTION_PLAN.md` owns sequencing (Lane 8) and `doctrine/ROADMAP.md` owns milestone status. Nothing in this document is a milestone. |
| 4 | |
| 5 | **Written:** 2026-10-03, before any DUAL code existed. Facts come from read-only audits of the commits below; code was read, README and spec claims were not taken as evidence, and every claim used by ADR 0031 was re-checked by hand against the cited lines. |
| 6 | |
| 7 | **Updated:** 2026-10-04. Sections 1 to 5 describe the state before any DUAL code existed and are kept as the audit record. Section 6 records what has since landed on `main` and supersedes section 1 where they differ. |
| 8 | |
| 9 | | Repository | Commit (GitHub `main`) | |
| 10 | |---|---| |
| 11 | | aien-spark/aien-architecture | `b31d6f7` | |
| 12 | | aien-spark/omega | `6d85a16` | |
| 13 | | aien-spark/aien-sovereign-core | `5fdab70` | |
| 14 | | aien-spark/spark-rsi | `f5f1ca2` | |
| 15 | |
| 16 | Status words: IMPLEMENTED, PARTIAL, PLANNED, MISSING. |
| 17 | |
| 18 | ## 1. Headline |
| 19 | |
| 20 | - No shadow price, dual variable or scarcity estimate exists in any of the four repositories (case-insensitive grep for `shadow price`, `lagrang`, `scarcity`, `budget pressure`: zero hits). In omega, `lambda` appears only as the cost model's ridge prior precision (`RxCostModel.lambda`). |
| 21 | - Every place that encodes scarcity today encodes it as a constant: J-Space residency pressure, scheduler limits, RSI bottleneck weights. |
| 22 | - The hard-before-soft and Pareto-before-ranking discipline DUAL needs already exists in omega's capability query and in the Arena spec. DUAL must reuse it, not shadow it. |
| 23 | - ESTIMATION is not ready to feed production prices: EST-3 is FAILED on `main` (v1 `aien-spark/omega#105`, v2 `#118`, v3 `#129`); v4 INCONCLUSIVE (`#153`); v5 `#170` was CLOSED unmerged on 2026-10-04T00:38:42Z (interim only, no calibration verdict; branch kept as a record; estimation program parked; checked with `gh pr view 170 -R aien-spark/omega`). EST-4 onward is blocked. |
| 24 | |
| 25 | ## 2. Concept inventory |
| 26 | |
| 27 | | Concept | Status | Where | Note | |
| 28 | |---|---|---|---| |
| 29 | | Pareto filtering before ordering | IMPLEMENTED (one site) | omega `src/runtime/rx_capq.c` `cq_rank`, `dominates()`; spec `spec/capability-query-ir.md` | hard admit chain in `cq_query_admit` (filter loop at `rx_capq.c:625-645`: liveness, types, effects, authority ceiling, latency, energy, reliability, evidence, max cost, min confidence) runs first; then the front; then a lexicographic caller order with `CqTradeoffs.tolerance_ppm` bands. No weighted sum. Natural DUAL hook: after the front, before the order loop | |
| 30 | | Ranked alternatives for routing | IMPLEMENTED | omega `rx_skillroute.h` `sr_route_alternatives` | reuses the `rx_capq` order | |
| 31 | | Cognitive routing | IMPLEMENTED, not Pareto | omega `spec/cognitive-routing.md` | feasibility, then least expected energy (time if energy unmetered); unsatisfiable requirement refused | |
| 32 | | Empirical optimizer | IMPLEMENTED, scalar | omega `rx_costmodel.c` `rx_cm_decide` | best `mean_log2_ps` among arms whose upper bound meets the budgets; if none, best overall flagged `RX_CM_WHY_OVER_BUDGET` (budgets act soft here, hard in `cq_query_admit`) | |
| 33 | | Cost model fields | IMPLEMENTED | omega `src/runtime/rx_costmodel.h` | `RxCmPrediction` (`mean_log2_ps`, `sd_log2`, `dof`, `energy_pj`, `fail_p`); `RxCostModel` (`power_mw`, `verify_ns`, `synth_ns`, `code_bytes`, `sd_scale` from `rx_cm_calibrate`); `RxCmFeatures` (`latency_budget_ps`, `energy_budget_pj`, `pressure` bucket) | |
| 34 | | Capability-query cost fields | IMPLEMENTED (advertised or estimated) | omega `rx_capq.h` `CqEntry` / `CqCandidate` | cost (abstract units), latency (us), energy (uJ), confidence and reliability (ppm), evidence level | |
| 35 | | KV capacity or bandwidth budget fields | MISSING | omega | `JS_REAL_KV_STATE` is a realization type only | |
| 36 | | Price-like quantity | PARTIAL (hand-set) | omega `rx_jspace.c` `choose()` and `enforce_u` | keeps bytes resident if best action cost `>= pressure * retain_ns_per_byte`; pressure is `1e9` when total residency is over budget (a CAPACITY case, stays hard) and `1e3` when only the hot arena is over half the budget (soft). The `1e3` case is the first candidate for a DUAL-supplied price | |
| 37 | | J-Space hard limits | IMPLEMENTED | omega `rx_jspace.h` `JsLimits` | `max_resident_bytes`, `max_spill_bytes`, etc. return `JS_ERR_FULL`: `CAPACITY` class | |
| 38 | | Typed result contracts | IMPLEMENTED, orthogonal to cost | omega `src/runtime/rx_contract.h` (`rc_*`, `RC_E_BUDGET`) | hard gates; `INVARIANT` class | |
| 39 | | Estimation records | IMPLEMENTED (standalone), not qualified | omega `src/estimation/est_types.h` (`est_observation`, `est_belief` with `evidence_root`, `est_prediction`, `est_innovation`) | DUAL inputs must reference these records | |
| 40 | | Serving scheduler | IMPLEMENTED (legacy scaffolding, class E) | aien-sovereign-core `crates/aien-scheduler/src/lib.rs` `AienScheduler`, `SchedulerConfig` | defaults `max_batch_size` 64, `max_batch_tokens` 4096, `max_prefill_tokens` 2048, `prefill_chunk_size` 512, `watermark_blocks` 4 (daemon overrides 256 / 16384 / 8192 / 128 / 64); watermark preemption evicts the lowest `Priority`, recompute not swap; admission FIFO, preempted queue first | |
| 41 | | Scheduler metrics | PARTIAL | `SchedulerMetrics` (`lib.rs:55`), `StepMetrics` (aien-abi-core) | running-mean step latency only; no p50/p95/p99; no energy in the scheduler (bench reads power separately) | |
| 42 | | Scheduler observer hook | MISSING | | the considered alternatives (preemption candidates, admission shortfall, budget clamps) are locals inside `build_scheduled_batch`; a read-only tap must expose them | |
| 43 | | RSI hard / soft split | IMPLEMENTED | spark-rsi `src/evaluator/layers/mod.rs` `LayerResult.is_hard_invariant`; `src/evaluator/mod.rs` | hard: correctness, security, style, longitudinal replay; soft: performance, resource efficiency; `admitted = hard && statistical` | |
| 44 | | RSI soft budgets | IMPLEMENTED, fixed thresholds | spark-rsi `src/isolation/manifest.rs` `regression_budgets` | p95/p99 degradation 1.0%, RSS growth 2.0% | |
| 45 | | RSI bottleneck ranking | PARTIAL (placeholder inputs) | spark-rsi `src/graph/mod.rs` `rank_bottlenecks` (0.4 centrality + 0.4 latency ratio + 0.2 error) | graph nodes fed literal constants in `src/daemon.rs`; ranking targets hypotheses only, never admission | |
| 46 | | RSI promotion authority | IMPLEMENTED as proposer-only | spark-rsi `src/ratify.rs` (human merges), `src/actor/judge.rs` `BlindJudge` | | |
| 47 | | Arena allocation rule | PLANNED (spec only) | `docs/specs/EVOLUTION_ARENA_SPEC_V1.md` §4.2, §1, §2.3 | Pareto before ranking; scalar fitness for search allocation only; J-Space search policy outside the V1 mutation surface; every automatic decision accountable | |
| 48 | |
| 49 | ## 3. Discrepancies with the brief |
| 50 | |
| 51 | 1. **The scheduler the brief describes is legacy.** Fixed batch budgets, KV watermark and preemption live in aien-sovereign-core, which its README calls legacy Linux-hosted scaffolding and `doctrine/ARCHITECTURE.md` §2.8 classes as a physical scheduler (class E), not on the reaction path. The semantic scheduler recorded as authoritative in §2.8 is omega `rx_world.c`, which orders reactions; no batch or KV policy was found there (UNVERIFIED beyond a grep). ADR 0031 therefore targets registered decision sites, not a repository. |
| 52 | 2. **Budgets are both hard and soft today.** `cq_query_admit` rejects over-budget latency and energy; `rx_cm_decide` runs them flagged; RSI thresholds reject. ADR 0031 §3 rule 4 treats an existing hard reject as `CAPACITY` until the owning contract declares a class. |
| 53 | 3. **Serial placement is not required.** EST-8 to EST-10 do not depend on DUAL (ADR 0031 §9.2). |
| 54 | 4. **Name collision.** omega already has a `Shadow` structure (`rx_graph.c`) with an ARGUS collision recorded in omega `docs/turing/TURING_CURRENT_STATE.md:107-113`; the brief's "Shadow Scheduler" is named the advisory scheduler (`DUAL_ADVISORY_SCHEDULER`). |
| 55 | 5. **Arena spec header is stale** (still PROPOSED, still calls omega #68 a draft), as already recorded in the belief-estimation current-state document. Not changed here. |
| 56 | |
| 57 | ## 4. Decision sites for DUAL-3 (initial list) |
| 58 | |
| 59 | | Site id | Decision | Alternatives | Production owner | |
| 60 | |---|---|---|---| |
| 61 | | `jspace.residency` | keep, move, compress, spill or evict a branch realization | `choose()` actions | omega `rx_jspace.c` | |
| 62 | | `capq.front_order` | order inside the capability-query Pareto front | front members | omega `rx_capq.c` (advisory only: its latency and energy budgets are hard rejects today, so they are CAPACITY and unpriced until a need contract declares a SOFT budget; ADR 0031 §3 rule 4) | |
| 63 | | `costmodel.arm` | realization arm per call | eligible arms | omega `rx_costmodel.c` | |
| 64 | | `serve.admit_preempt` | admission, preemption victim, prefill chunk allocation | waiting/preempted queue heads, running sequences | aien-sovereign-core `aien-scheduler` (scaffolding; moves with its Omega replacement under ARCH-0024) | |
| 65 | |
| 66 | ## 5. Implementation slices, in dependency order |
| 67 | |
| 68 | Each slice is one small pull request with its own receipt. None touches `omega/src/runtime/` until slice 5. |
| 69 | |
| 70 | 1. **DUAL-0a, records and registry (omega, standalone).** (IMPLEMENTED, see section 6.) `src/dual/` and `tests/dual/`, own `mk/dual.mk` targets, not in `all` or `test`, not included by `src/runtime/`. Section 4 records, kind bytes, digest domains, unit registry, class rules, canonical encoding round trip, `nm -u` refusal check. Hostile tests for `INVARIANT` construction, NaN/negative/unit mismatch, kind confusion. |
| 71 | 2. **DUAL-0b, staleness and evidence binding.** Generation and maximum-age checks; evidence-root verification reusing `est_evidence_root_extend`; references to `est_*` records, never copies of raw observations. Exit `DUAL_CONSTRAINT_CONTRACT = PASS`. |
| 72 | 3. **DUAL-1a, reference update.** Section 5.1 update as a pure function of (state, input, controller parameters); `controller_id` digest; analytic cases plus an independent reference written without reading the implementation. |
| 73 | 4. **DUAL-1b, replay on recorded traces.** Digest-bound traces already on disk (for example the R15 machine-state series used by EST-2) plus synthetic step-change and square-wave loads; oscillation bound pre-registered; inputs labelled `UNCALIBRATED`. Exit `DUAL_PRICE_REFERENCE = PASS`. |
| 74 | 5. **DUAL-3a, read-only tap at one site.** Start with `jspace.residency` (omega, smallest blast radius, already has a price-shaped input) or `serve.admit_preempt` (real batch decisions). Tap records alternatives and the actual choice; a with/without comparison proves identical decisions. This is the first change under `src/runtime/` and must stay clean of the R16 loop-inventory patterns. |
| 75 | 6. **DUAL-3b, advisory campaign.** Pre-registered workloads, `DualRecommendation` for every decision, prediction-error report. Exit `DUAL_ADVISORY_SCHEDULER = PASS`. |
| 76 | 7. **DUAL-2, Pareto integration (test builds).** Waits on EST-5 and EST-7. Exit `DUAL_PARETO_INTEGRATION = PASS`. |
| 77 | 8. **DUAL-4, Arena allocation.** Waits on DUAL-2, DUAL-3, the Arena V1 activation hold and a DUAL allocation policy frozen in the Arena Evaluation contract; observe-and-record Arena runs only until DUAL-5. Exit `DUAL_ARENA_ALLOCATION = PASS`. |
| 78 | 9. **DUAL-5, closed-loop qualification.** Waits on DUAL-2, DUAL-3, DUAL-4 and on EST-3, EST-4, EST-5, EST-7 for every consumed signal. Exit `DUAL_CLOSED_LOOP_QUALIFICATION = PASS`. |
| 79 | |
| 80 | Slices 1 to 4 are permitted now by the same rule that let EST-0 to EST-3 run as a standalone module. Slices 5 and 6 need no ESTIMATION gate because they have no production authority. Slices 7 to 9 wait as stated. |
| 81 | |
| 82 | ## 6. Implementation status, 2026-10-04 (updated after the first DUAL code landed) |
| 83 | |
| 84 | Written by the orchestrator after read-only audits of the merged commits below. Status words as above plus EXPERIMENTAL (code and evidence exist, no gate claimed, nothing wired into production) and BLOCKED (gate prerequisite failed or missing). |
| 85 | |
| 86 | | Repository | Commit (GitHub `main`, after the merges) | |
| 87 | |---|---| |
| 88 | | aien-spark/omega | `55d05d6` | |
| 89 | | aien-spark/aien-sovereign-core | `7580039` | |
| 90 | | aien-spark/spark-rsi | `e5aab9a` | |
| 91 | |
| 92 | Baseline before this work: omega `cb7cc21`, aien-sovereign-core `91fba8f`, spark-rsi `f5f1ca2`, aien-architecture `35dd324`. Grep for `rx_dual`, `RxDual`, `src/dual` at those commits: zero hits (DUAL was MISSING everywhere, consistent with section 1). |
| 93 | |
| 94 | | Slice | Status | Where | Evidence | |
| 95 | |---|---|---|---| |
| 96 | | DUAL-0a records and registry | IMPLEMENTED | omega `src/dual/rx_dual.{h,c}`, `tests/dual/test_dual_types.c`, `mk/dual.mk` (`make test-dual`), `docs/dual/DUAL_RECORDS.md` | omega #266 (`109cadc`); `evidence/DUAL/0a-records/receipt.md`; 14107 checks plain, 1667 ASan/UBSan, 4 mutants killed; `nm -u` purity clean | |
| 97 | | DUAL-0b evidence and staleness binding | IMPLEMENTED | omega `src/dual/rx_dual_bind.{h,c}`, `tests/dual/test_dual_bind.c` | omega #267 (`3bebcc6, reopened as #272 after GitHub closed #267 with its base branch`); binds to `est_belief`, `est_prediction`, `est_observation` digests, verifies `evidence_root` via `est_evidence_root_extend`; states FRESH / STALE / FROZEN / UNCALIBRATED / REFUSED; `DUAL_CONSTRAINT_CONTRACT = PASS` (host) | |
| 98 | | DUAL-1a reference update | IMPLEMENTED | omega `src/dual/rx_dual_update.{h,c}`, `tests/dual/test_dual_update.c`, independent closed form `tests/dual/dual_ref.c` | omega #267; analytic cases 1-8, 3000-round property suite (355348 checks plain, 35837 ASan), 5 mutants killed | |
| 99 | | DUAL-1b replay | IMPLEMENTED | omega `src/dual/rx_dual_replay.{h,c}`, `tests/dual/test_dual_replay.c`, `tests/dual/dual_traces.{h,c}` | omega #271 (`55d05d6`); 12 synthetic scenarios + 6 recorded R15 perf-counter traces (digest-bound), thresholds pre-registered in a commit before the code; 456 checks plain and ASan; hostile controller (eta 5, rho 0) fails the amplitude bound as declared; `DUAL_PRICE_REFERENCE = PASS` (host); every replayed input UNCALIBRATED | |
| 100 | | DUAL-3a read-only tap at `jspace.residency` | IMPLEMENTED | omega `src/runtime/rx_jspace.{h,c}` (`js_dual_set_observer`, default NULL), `mk/dual_jspace_tap.mk` (`make test-dual-3a`) | omega #270 (`3a3144d`); on/off parity byte-identical (rc, `JsPolicyReport`, `JsStats`, space digest), hostile observer killed 2035 times, bench: tap-off within -0.42 % of base, +2.06 us per record with tap on; receipt `evidence/DUAL/3a-jspace-tap/receipt.md` (thresholds declared before the run, committed after it, stated there) | |
| 101 | | DUAL-3a observer at `serve.admit_preempt` | IMPLEMENTED | aien-sovereign-core `crates/aien-scheduler/src/dual_observer.rs` (`DecisionObserver`, default None), `build_scheduled_batch` wrapper | aien-sovereign-core #198 (`2f9570a`); per-scenario decision digests over 13 scripted scenarios identical to the base commit; observer on/off byte-identical; compile_fail doctests prove the observer cannot mutate or return a choice; feature-gated mutant that changes a decision fails 4/13 scenarios; bench B1 (counting/absent <= 1.25) measured 1.337 and recorded FAIL, threshold untouched (noise reference 0.594); receipt `docs/campaigns/dual/2026-10-04-serve-observer-receipt.md` | |
| 102 | | Macroscopic snapshot adapter | IMPLEMENTED | aien-sovereign-core `crates/aien-dual-observation` (new read-only crate) | aien-sovereign-core #199 (`7580039`); conservation tests (8) pass; zero-denominator ratio yields None, never zero; no scheduler decision read or written; receipt `docs/campaigns/dual/2026-10-04-macro-snapshot-receipt.md` | |
| 103 | | Applicability (continuum vs discrete) experiment | EXPERIMENTAL | omega `src/dual_experiment/`, `tools/dual_experiment/applic_run.c`, `mk/dual_applicability.mk`, `docs/dual/APPLICABILITY_EXPERIMENT.md` | omega #268 (`00f54b6`); 8 synthetic workloads x 24 seeds, bit-reproducible (results digest pinned in the test); aggregate throughput prediction usable when demand spread is low, degrades monotonically with heterogeneity; shuffled-window control worse in 192/192 runs; proposes a regime rule only, nothing inserted | |
| 104 | | DUAL-3b advisory recommendation campaign | MISSING | | needs the tap (#270) and the records (#266, #267) on the same build; not started | |
| 105 | | RSI diagnostic price consumer | IMPLEMENTED (diagnostic only) | spark-rsi `src/dual/{records,diagnostic}.rs`, knob `RsiConfig.dual_price_vector_dir` (default None), report field `RsiCycleResult.scarcity` | spark-rsi #33 (`e5aab9a`); byte-exact re-encode of omega golden vectors (generated at omega #266), 32 hostile cases refused with the same status codes as the C decoder; flipped-bit digest mismatch reported as unavailable, never as zero scarcity; names only the highest FRESH calibrated price; weighted sum, hard invariants, admission, ratification and promotion untouched (source-level test guards them); 198 tests pass; receipt `evidence/dual/receipt.md` | |
| 106 | | DUAL-2 Pareto integration | BLOCKED | | waits on EST-5 and EST-7 (not reached) | |
| 107 | | DUAL-4 Arena allocation | BLOCKED | | waits on DUAL-2, DUAL-3, Arena V1 activation hold | |
| 108 | | DUAL-5 closed-loop qualification | BLOCKED | | waits on EST-3 (FAILED on `main`), EST-4, EST-5, EST-7 | |
| 109 | |
| 110 | **DUAL production influence: DISABLED BY GATE.** No price reaches any production decision. The only `src/runtime/` change is the `jspace.residency` tap, which is read-only with a NULL default and a proven on/off parity. ESTIMATION gates EST-3, EST-4, EST-5 and EST-7 are not passed, so DUAL-5 cannot start. |
| 111 | |
| 112 | Known limits of the merged work: host-only (no GB10 chip time was used or needed); the `lambda_max` and controller constants are placeholders bound into `controller_id`, not tuned; FRESH inputs require a calibration reference that nothing on `main` yet produces, so every real input today classifies as UNCALIBRATED or STALE by construction; ADR 0033 verification manifests do not yet exist for omega, so these slices are gated by the existing make targets and GitHub CI. |