interplane.Get Omega
Read in your language

spark-rsi-mv

Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger

Brought by drakestapleton

branch main Branches Tags History

spark-rsi-mv / docs / CANARY-CONTRACT.md

167 lines · 9819 bytes Raw Blame History Rendered
1# Canary contract: supervisor-driven observations
2
3Status: contract foundation (step 1 of docs/plans/2026-10-12-evidence-driven-rsi-cut.md).
4Code: `src/canary/` and the `ExecuteRequest` / `ExecuteResult` pair in `src/supervisor/ipc.rs`.
5Vocabulary: CONTEXT.md.
6
7The one rule above everything: no candidate-controlled statement can independently establish
8that a canary passed. Every accepted observation is tied to the exact executable that was built,
9checked by the supervisor, and admitted through one authoritative promotion path.
10
11## Digests
12
13Every digest is lowercase hex SHA-256. Structured digests are domain separated: the domain string
14and then each field are written length-prefixed (u64 little endian, then the bytes), the same
15scheme as the version 2 evaluation receipt. Canonical JSON is one object with keys in byte order
16at every level, no insignificant whitespace, serde_json string escaping, integers only.
17
18| Digest | Domain | Fields |
19|---|---|---|
20| request | `spark-rsi/canary-request/v1` | workload id, request id, input, expected output, deadline ms (u64 LE), nondeterminism |
21| workload | `spark-rsi/canary-workload/v1` | canonical bytes of the workload manifest |
22| observation id | `spark-rsi/canary-observation-id/v2` | generation id, request id, request digest |
23| observation | `spark-rsi/canary-observation/v2` | canonical bytes of the observation record |
24| candidate identity | `spark-rsi/candidate-identity/v1` | patch digest, tree digest, executable digest, generation id |
25| observation log | `spark-rsi/canary-observation-log/v1` | every byte of the log before the seal line |
26| result | none | SHA-256 of the exact result bytes received |
27| adapter manifest | none | SHA-256 of the exact manifest file bytes |
28
29## Adapter manifest: `canary-adapter.toml`
30
31Shipped at the root of the target repository. A target without one is not eligible for canary and
32fails closed. It names how the built artifact is exercised; it never names a passing criterion.
33
34```toml
35manifest_version = 1
36protocol_version = 1
37executable = "release/rsi-canary-fixture" # relative to the build output root, never climbing
38args = ["--adapter"]
39workload_id = "fixture-v1" # must equal the pinned workload's id
40response_format = "utf8-exact"
41```
42
43## Workload manifest (JSON, under the RSI state directory)
44
45Operator-owned. Its digest is pinned before the candidate starts and written on every observation.
46`CanaryWorkloadManifest::load_pinned` refuses a file whose digest differs from the pin.
47
48```json
49{
50 "workload_version": 1,
51 "workload_id": "fixture-v1",
52 "protocol_version": 1,
53 "requests": [
54 {"request_id": "req-001", "input": "ping", "expected_output": "pong",
55 "deadline_ms": 2000, "nondeterminism": "exact"}
56 ]
57}
58```
59
60Version 1 permits only `exact` nondeterminism: the result bytes must equal the expected output.
61
62## Wire protocol (version 1)
63
64JSON lines over the generation's Unix socket, the existing `IpcConnection` framing.
65
661. The supervisor binds the generation socket `<rsi_root>/workers/<generation_id>.sock` before
67 it spawns the worker, and passes `--socket /ipc/<generation_id>.sock` inside the worker jail.
682. The worker connects and sends `Ready { generation_id, pid, auth_token, protocol_version: 1 }`.
693. The supervisor sends `AuthChallenge { nonce }`; the worker answers
70 `AuthResponse { response: HMAC-SHA256(secret, "<generation_id>:<nonce>") }`.
714. On success the connection is `Authenticated(generation_id, pid, protocol_version)` and the
72 supervisor replies `Ping`. Readiness means exactly this, completed within the readiness
73 deadline. A bare connection, silence, an older `Ready` without a protocol version, or an
74 unknown reply is not ready.
755. For each request in the pinned workload, in order, the supervisor sends
76 `ExecuteRequest { protocol_version, generation_id, request_id, request_digest,
77 workload_digest, input, deadline_ms }`, starts its own clock, and waits up to `deadline_ms`
78 for `ExecuteResult { protocol_version, generation_id, request_id, output, worker_latency_us }`.
796. The supervisor hashes `output`, compares it with the expected output, and records one
80 observation per issued request. `worker_latency_us` and every `CanaryReport` are
81 diagnostics; they never become observations.
82
83Worker containment requires `/usr/bin/bwrap`, `/usr/bin/systemd-run`, a reachable systemd
84user manager, cgroup v2 memory/pids/CPU controllers, and unprivileged user namespaces. Missing
85support refuses the canary. A transient user scope enforces `MemoryMax` from
86`memory_limit_mb` (systemd `M` units), `MemorySwapMax=0`, `TasksMax=256`, and the default
87`SandboxLimits` CPU quota across the entire worker tree, including tmpfs and memfd pages.
88No persistent unit or service configuration is
89installed. Sampled descendant RSS remains an additional early-revert check, not a hard limit.
90
91The worker runs as uid/gid 65534 in a new user namespace, with no capabilities and separate
92mount, PID, IPC, UTS and network namespaces. Nested user namespaces are disabled and asserted
93disabled. It sees only the read-only executable at `/worker`, read-only system runtime
94directories, private `/tmp` and `/scratch`, and its single bound Unix socket. The root mount
95is read-only. The generation, workload expectations, logs, ledger and operator home are not
96mounted. Killing the tracked launcher tears down the namespace worker and descendants through
97bubblewrap's `--die-with-parent` chain.
98
99The launcher and worker environments are cleared. `PATH=/usr/bin:/bin`, `HOME=/tmp` and
100`TMPDIR=/tmp` are fixed jail values. Only locale/diagnostic variables, the `RSI_CANARY_*`
101namespace and explicitly supplied per-run values are restored. `SUPERVISOR_SECRET` is a fresh
102run secret, never the operator's long-lived supervisor secret. Namespace uid isolation is not
103a separate persistent host account, and this host sandbox is not hardware qualification.
104
105The exercised host dependencies for this containment change are bubblewrap 0.9.0 and systemd
106255 (255.4-1ubuntu8.17); the Rust/Cargo compiler is 1.98.1. These are explicit host dependencies,
107not an Omega implementation. Their Omega replacement must supply checked namespace/mount
108construction, cgroup limits and whole-tree teardown before this path can be replaced.
109
110Rejections (no observation is created, the event is logged as a rejection, no rollback):
111a message on an unauthenticated connection, a message naming another generation, an
112`ExecuteResult` for a request that was not issued or was already answered. A result for the
113issued request with the wrong protocol version or generation is an `InvalidResponse`
114observation. A missing result at the deadline is a `Timeout` observation. The connection closing
115first is a `ConnectionClosed` observation. Every non-success observation is an early safety
116revert in the supervisor and makes the generation unpromotable.
117
118## Observation record (version 2)
119
120```json
121{"record_version":2,"observation_id":"<hex>","generation_id":"gen-...","request_id":"req-001",
122 "request_digest":"<hex>","workload_digest":"<hex>","candidate_executable_digest":"<hex>",
123 "result_digest":"<hex or null>","elapsed_us":1234,"observed_at_ms":1700000000000,
124 "status":"verified_success","provenance":"measured"}
125```
126
127`status` is one of `verified_success`, `wrong_result`, `timeout`, `invalid_response`,
128`connection_closed`. `provenance` is `measured` or `synthetic`; synthetic never counts.
129
130## Observation log
131
132`<rsi_root>/canary/observations/<generation_id>.jsonl`, one canonical record per line, each
133`{"kind": ..., "record": {...}}` with kinds `header`, `observation`, `rejection`, `seal`. The
134header binds the generation id, workload digest and candidate executable digest; every
135observation must carry the same three. Each append is synced before it is acknowledged. The
136store refuses a known observation id unless the record is byte-identical (idempotent retry); a
137different record under a known id is a conflict. A partial trailing record is dropped on reopen.
138The seal commits the observation count, the qualifying count and the digest of every byte before
139it. Nothing may follow the seal. Only a sealed, verified log (`SealedObservationLog`) can be
140handed to the quota validator.
141
142## Candidate identity chain
143
144`CandidateIdentity { patch_digest, tree_digest, executable_digest, generation_id }`. The
145supervisor re-hashes the executable right before launching (`verify_executable`) and refuses
146anything else. The quota validator compares the executable digest, never the patch digest.
147
148## Hand-off to the quota validator
149
150`canary::admit_sealed_quota(sealed, identity, workload, target)` is the single authority on
151evidence sufficiency. It refuses: a target of zero; a log for another generation, executable or
152workload; zero observations; any synthetic observation; any non-success observation; a request
153not in the workload; a request digest that does not match the workload; a result digest that does
154not equal the expected outcome; an elapsed time over the request deadline; and fewer unique
155qualifying observations than the target. Version 1 observations
156(`crate::canary_observation`) are history: the version 2 path never reads them.
157
158Sequence in the engine (plan, M2 Admission): Collect -> Seal -> Verify -> Quota admission ->
159Safety envelope -> Judge / promotion gate -> Durable. The sealed log digest is committed to the
160RSI ledger before admission. The safety envelope's reference-backend evaluation is recorded as
161such; it does not establish production safety.
162
163## What this foundation does not do
164
165It defines and freezes formats. It does not launch workers, drive requests, enforce per-connection
166authentication, instrument stages, or wire anything into `run_cycle`. Those are steps 2 to 5 of
167the plan and must use these definitions unchanged.