spark-rsi-mv
Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger
Brought by drakestapleton
spark-rsi-mv / docs / plans / 2026-10-12-evidence-driven-rsi-cut.md
| 1 | # Evidence-Driven RSI: the M1 + M2 cut |
| 2 | |
| 3 | Status: approved plan, no code yet. Decided by Drake in a three-round design grilling on 2026-10-12. |
| 4 | Supersedes, for implementation purposes, the broader brief "AIEN Development Brief: Evidence-Driven Autonomous Engineering". |
| 5 | |
| 6 | ## The one rule above everything |
| 7 | |
| 8 | **No candidate-controlled statement can independently establish that a canary passed.** |
| 9 | |
| 10 | A candidate may answer a challenge. The supervisor must have sent that challenge, must measure the elapsed time |
| 11 | itself, must compare the answer against independently defined expectations, and must durably commit the verified |
| 12 | observation. Only the existing admission and promotion authorities act on that evidence. Tests that let a worker |
| 13 | self-report success into production admission are defects and must be rewritten. |
| 14 | |
| 15 | **Every accepted canary observation must be demonstrably tied to the exact executable that was built, |
| 16 | independently checked by the supervisor, and admitted through one authoritative promotion path.** |
| 17 | |
| 18 | Fixture qualification and production safety qualification are different things. Ten verified fixture requests |
| 19 | prove the canary mechanism works. They do not establish that every existing safety evaluator is ready to authorize |
| 20 | production changes; see the safety-envelope defect below. |
| 21 | |
| 22 | ## Scope |
| 23 | |
| 24 | In scope, this cut only: |
| 25 | |
| 26 | - **M1 Measurement.** Replace the hardcoded capability-graph numbers in `src/daemon.rs` with measured RSI stage |
| 27 | timings from completed prior cycles. |
| 28 | - **M2 Execution and admission.** Make `admit_production_quota` receive real, authenticated, supervisor-driven |
| 29 | observations instead of an empty slice. |
| 30 | |
| 31 | Deferred, not authorized here: objective discharge (M3), residual-unknown registry (M4), RSI and explanation |
| 32 | interoperability (M5), REA investigation adapter (M6, filed as a mind-map idea). |
| 33 | |
| 34 | ## Pinned baseline |
| 35 | |
| 36 | | Repository | Commit | |
| 37 | |---|---| |
| 38 | | spark-rsi | `f74a7dbdcd06` | |
| 39 | | aien-sovereign-core | `b323258396a9` | |
| 40 | | aien-protocols | `5c2316954e16` | |
| 41 | | aienos | `5cfba1bba3f8` | |
| 42 | |
| 43 | ## Verified defects at the baseline |
| 44 | |
| 45 | - `src/daemon.rs` builds the capability graph with constant latency and memory values per node. |
| 46 | - `src/daemon.rs` calls `admit_production_quota(&[], ...)`; the quota can never be met. |
| 47 | - `src/supervisor/daemon.rs` discards `transaction_id` on `CanaryReport`, so replays count. |
| 48 | - The `CanaryReport` branch checks only the generation name, not whether that connection completed the handshake. |
| 49 | - `CanaryReport` carries worker-supplied success and latency, which go straight into `record_canary_transaction`. |
| 50 | - `run_cycle` stages a generation but never calls `spawn_worker` and never runs a canary workload. |
| 51 | - `HostSupervisor::record_canary_transaction` and `process_worker_message` both grant `Durable` on a counter. |
| 52 | - Handling `Ready` switches `active.sock` to the candidate before any admission decision. |
| 53 | - `rank_bottlenecks` sorts by score with no tie-break; non-finite scores compare as equal. |
| 54 | - `wait_for_readiness` returns success on any socket connection, even with no PONG or READY reply at all. |
| 55 | - `record_canary_transaction` treats a failed memory-budget read as within budget (`unwrap_or(true)`). |
| 56 | - `stage_canary` only copies the candidate directory; nothing compiles, launches or drives an executable. |
| 57 | - The candidate digest passed to the quota validator is the hash of `proposal.proposed_patch`, not of the |
| 58 | evaluated tree or the executable launched. |
| 59 | - `admit_production_quota` checks only non-empty id and status, candidate digest match, the `Measured` label and |
| 60 | duplicate consistency. It does not check that the status is a verified success. |
| 61 | - `CanarySafetyEnvelope` runs its probes through `DeterministicReferenceBackend` on the production call path, so its |
| 62 | signed result is a reference evaluation, not independently established production safety. |
| 63 | - The hypothesis contract is built from the graph's `latency_p95_us`, so a cold-start cycle can claim a measured |
| 64 | latency target from invented numbers. |
| 65 | - Every winning proposal, whatever its kind, is sent into the canary path. |
| 66 | |
| 67 | ## Decisions |
| 68 | |
| 69 | ### Terminology |
| 70 | |
| 71 | - **Closure** keeps its existing meaning: the `aien-closure` / `verify-closure` dependency-graph proof check. |
| 72 | - **Discharge** is the new word for "an objective's required outcomes all have qualifying evidence". Deferred. |
| 73 | - An **obligation**, when it arrives, is an `aien-proof` Gate `Requirement` extended with an obligation id, an |
| 74 | objective id and an out-of-scope disposition. No new evaluator. |
| 75 | |
| 76 | ### M1 Measurement |
| 77 | |
| 78 | - Measure RSI's own pipeline stages (Observe, Propose, BuildJail, JudgeEvaluation, SupervisorCanary, CortexCommit), |
| 79 | not the inference runtime. |
| 80 | - Ranking in a cycle uses samples from **completed prior cycles**, never the current one. |
| 81 | - Samples persist in an append-only stage-sample log under the RSI state directory, one record per cycle: |
| 82 | cycle id, workload key, execution-profile fingerprint, per-stage duration and outcome, source commit, schema |
| 83 | version. Failed and partial cycles are recorded in a separate partial-cycle set, never mixed into eligible samples. |
| 84 | - **Workload key**: normalized target repository identity, effective execution configuration, model name. |
| 85 | The target commit is recorded for provenance but is not part of the key. |
| 86 | - **Execution-profile fingerprint**: model name, effective execution configuration, CPU count, memory capacity, |
| 87 | GPU identity (`none` when absent). Canary adapter protocol version is recorded on canary-stage samples only. |
| 88 | `require_latency_improvement` is an evaluation policy and is not an execution mode. |
| 89 | - **Sufficiency**: at least 3 compatible completed samples per stage from the most recent 20 compatible cycles. |
| 90 | Both numbers are configuration. |
| 91 | - **Statistics**: median is the ranking input and is reported under its own name. Empirical p95 is reported only |
| 92 | with at least 20 valid compatible samples; otherwise p95 is marked unavailable. One percentile algorithm, |
| 93 | golden-tested. Zero never means missing: unavailable is an explicit state, with backward-compatible graph output. |
| 94 | - **Cold start**: rank on graph topology (betweenness centrality) only; latency and error terms are marked |
| 95 | unavailable in the explanation. No "measured improvement" hypothesis may be generated from missing data: the |
| 96 | hypothesis contract carries a numeric latency target only when the stage's latency is measured, otherwise it is |
| 97 | an exploratory hypothesis with no performance claim. |
| 98 | - **Canary applicability** is policy-controlled by proposal kind and claim: executable production changes always |
| 99 | go through canary admission; documentation and other non-executable changes may be exempted by explicit policy, |
| 100 | never by default. Exemption never weakens the gates for anything that reaches production. |
| 101 | - **Claims**: a proposal of kind `Optimization`, or any proposal when `require_latency_improvement` is on, needs a |
| 102 | measured diagnosis before promotion. Other kinds proceed on structural ranking. |
| 103 | - **Ordering**: score descending, then stage id ascending. Non-finite measurements are rejected before scoring. |
| 104 | - Removing measurements can never restore the old constants. Those constants are deleted. |
| 105 | |
| 106 | ### M2 Execution |
| 107 | |
| 108 | - **Adapter manifest**: a target is eligible for canary only if it ships a declared canary adapter manifest naming |
| 109 | the approved executable, arguments, protocol version, request workload and expected-response format. Unsupported |
| 110 | targets fail closed. The supervisor verifies the executable is the exact built artifact under evaluation. |
| 111 | - **Wire protocol**: a small versioned supervisor-to-worker execute-request / result message pair added to the IPC |
| 112 | enum. Worker `CanaryReport` self-reports become diagnostics only. |
| 113 | - **Workload**: a digest-pinned canary manifest under the RSI state directory with requests, expected outcomes, |
| 114 | deadlines and permitted nondeterminism. The candidate cannot rewrite it or set its own passing criteria. |
| 115 | - **Candidate identity** is a bound chain: source patch digest, evaluated tree digest, built executable digest, |
| 116 | generation id. The supervisor launches only the executable whose digest is in that chain, and every observation |
| 117 | carries the executable digest. The quota validator compares against the executable digest, not the patch digest. |
| 118 | - **Readiness** means a valid versioned READY reply on the authenticated generation socket within the deadline. |
| 119 | A bare connection, silence or an unknown reply is not ready. |
| 120 | - **Observation** binds: generation id, issued request id, request digest, workload digest, candidate executable |
| 121 | digest, observed result digest, supervisor-measured elapsed time, supervisor timestamp, verified status, |
| 122 | provenance. |
| 123 | - **Observation id**: domain-separated hash of (generation id, request id, request digest). Duplicates collide by |
| 124 | construction; the store refuses known ids; conflicting records for one id are a verification failure. |
| 125 | The supervisor tracks issued requests; an unsolicited response creates nothing. Incomplete requests after a |
| 126 | restart are never counted as successes. |
| 127 | - **Authentication**: per-connection state `Unauthenticated -> Authenticated(generation_id)` set only by a |
| 128 | successful HMAC handshake. Messages on unauthenticated connections or for another generation are rejected and |
| 129 | the connection closed, logged as rejected, with no rollback. A worker timeout still fails the canary. |
| 130 | - **Storage**: per-generation append-only observation log, sealed with a final digest record. Partial trailing |
| 131 | records are detected and excluded. The sealed log digest is committed to the RSI ledger before admission. |
| 132 | - `active.sock` is **not** switched on `Ready`. The candidate is exercised through its generation socket. |
| 133 | |
| 134 | ### M2 Admission |
| 135 | |
| 136 | - The quota validator (`admit_production_quota`) is the single authority on evidence sufficiency. |
| 137 | `record_canary_transaction` and `process_worker_message` stop granting `Durable`. |
| 138 | - Sequence: Collect -> Seal -> Verify -> Quota admission -> Safety envelope -> Judge / promotion gate -> Durable. |
| 139 | - The quota validator additionally requires each observation's verified status to be a supervisor-confirmed success |
| 140 | with a result digest matching the workload's expected outcome. Only observations from the new execution protocol |
| 141 | are eligible; the old `CanaryReport` path cannot produce one. |
| 142 | - Early safety reverts on a failed or slow request remain in the supervisor. |
| 143 | - A failed resource read is not proof that memory is within budget: a memory-budget read error reverts, it never |
| 144 | passes. |
| 145 | - The safety envelope stays in the sequence, but its reference-backend evaluation is recorded as such. The |
| 146 | qualification report must state plainly that production safety evaluation is not yet independently established. |
| 147 | Replacing or qualifying that evaluator is a separate follow-on cut, not part of M2. |
| 148 | |
| 149 | ### Narrow contract freeze |
| 150 | |
| 151 | - This file pins the four commits above. |
| 152 | - Golden tests, written before implementation, fix: (1) canonical canary-observation encoding and digest for the |
| 153 | new versioned record, (2) existing signed evaluation receipt bytes, digest and verification, (3) existing ledger |
| 154 | record encoding, hash and validation. Historical formats are untouched; new records carry their own version. |
| 155 | |
| 156 | ## Implementation sequence and ownership |
| 157 | |
| 158 | 1. **Contract foundation** (orchestrator, before any worker starts): adapter manifest format, wire protocol, |
| 159 | observation schema and canonical encoding, durable log format, sealed-log hand-off interface to the quota |
| 160 | validator, golden tests. |
| 161 | 2. **M1 Measurement** (worker A): stage instrumentation, sample log, compatibility filtering, cold start, |
| 162 | deterministic ranking, explanation marks unavailable values via the existing `MissingDoc` reason field. |
| 163 | 3. **Harden the supervisor** (worker B, first half): strict readiness, generation binding, per-connection session |
| 164 | authentication, no `active.sock` switch on Ready, memory-read failure reverts. |
| 165 | 4. **M2 Execution** (worker B, second half): fixture crate implementing the adapter, supervisor-driven timed |
| 166 | requests, independent result checking, replay protection, observation storage and sealing. |
| 167 | 5. **M2 Admission** (worker C, the only worker that edits `src/daemon.rs`): build-artifact identity chain, wire |
| 168 | `spawn_worker` and the request loop into `run_cycle`, remove premature durability, ledger commitment, quota |
| 169 | integration with verified-success checks, canary applicability policy, rewrite self-report tests. |
| 170 | 6. **Qualification**: adversarial CI plus one real DGX Spark run against the fixture crate, with the evidence |
| 171 | package attached to the pull request and remaining production limitations stated in the report. |
| 172 | |
| 173 | Workers run on Sonnet. Daemon changes land serially: A, then C. |
| 174 | |
| 175 | ## Qualification fixture |
| 176 | |
| 177 | A dedicated Rust fixture crate inside this repository implementing the adapter protocol. It must be able to: |
| 178 | answer correctly, answer wrongly, fabricate self-reported success, send duplicate responses, replay after restart, |
| 179 | time out, return a wrong digest, and attempt premature promotion. Defaults for the fixture run: 10 supervisor-issued |
| 180 | requests, 2-second deadline each, both configurable. The real run must include at least one failing request. |
| 181 | |
| 182 | A passing fixture run qualifies the canary execution pipeline. It does not qualify RSI's ability to improve |
| 183 | itself, and it does not qualify the safety envelope as a production evaluator. Both are later targets, with |
| 184 | spark-rsi as the first real adapter. |
| 185 | |
| 186 | ## Evidence package for the qualification pull request |
| 187 | |
| 188 | Pinned workload manifest and digest, complete sealed observation log and its digest, matching ledger commitment, |
| 189 | candidate artifact identity, quota decision, safety-envelope and promotion decisions, the CI run showing the |
| 190 | exact revision and tests executed. |
| 191 | |
| 192 | ## Acceptance |
| 193 | |
| 194 | - M1: different valid sample sets change the ranking deterministically; removing samples yields the cold-start |
| 195 | structural ranking with unavailable markers, never the old constants; explanation output distinguishes measured |
| 196 | from unavailable. |
| 197 | - M2: an authorized fixture with enough genuine supervisor-driven observations passes the quota and reaches the |
| 198 | later gates. Zero observations, self-reports only, duplicates, replays, wrong outputs, mismatched candidate |
| 199 | digests, corrupted logs, timeouts and unauthenticated connections cannot qualify. Fail-closed behaviour is never |
| 200 | weakened. |
| 201 | |
| 202 | ## Delivery status (2026-10-12) |
| 203 | |
| 204 | All six steps are implemented on the integration branch `feat/evidence-driven-rsi-cut` |
| 205 | (pull request #44, stacked on the plan pull request #38): |
| 206 | |
| 207 | | Step | Delivery | Ticket | |
| 208 | |---|---|---| |
| 209 | | 1 Contract foundation | `src/canary/`, `docs/CANARY-CONTRACT.md`, golden tests (b13ea46) | #39 | |
| 210 | | 2 M1 Measurement | `src/measure/`, measured graph, exploratory hypotheses (PR #45) | #40 | |
| 211 | | 3 and 4 Supervisor hardening, M2 execution | `src/supervisor/canary_exec.rs`, `fixtures/canary-target` (PR #46) | #41 | |
| 212 | | 5 M2 Admission | identity chain, executor and quota wired into `run_cycle` (PR #47) | #42 | |
| 213 | | 6 Qualification | `examples/canary_qualification.rs`, `evidence/rsi-cut-2026-10-12/REPORT.md` | #43 | |
| 214 | |
| 215 | The qualification report states what the fixture run qualifies and the remaining production |
| 216 | limitations. The one that matters most: the promotion gate refuses every candidate until the |
| 217 | separate judge is wired in (#35), so nothing becomes durable in this cut. That is fail closed by |
| 218 | design. |