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 / om / eval / canary.om

170 lines · 4393 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/rsi/om/eval/canary.om
3note Pure OM-2 conversion of spark-rsi-mv/src/canary/{admission,identity,observation,workload}.rs.
4note Canary identity binding (SHA-256), non-synthetic provenance enforcement,
5note observation window accumulation, and fail-closed canary admission gate.
6note Compose after om/tls/sha2.om.
7
8note Canary provenance
9const CNR_PROV_SYNTHETIC ulong 0
10const CNR_PROV_CANARY_HOST ulong 1
11const CNR_PROV_SILICON ulong 2
12
13note Canary verdicts
14const CNR_PASS ulong 0
15const CNR_HOLD_INSUFFICIENT_SAMPLES ulong 1
16const CNR_DENY_UNINIT ulong 10
17const CNR_DENY_UNBOUND_ID ulong 11
18const CNR_DENY_SYNTHETIC ulong 12
19const CNR_DENY_CRASH ulong 13
20const CNR_DENY_ERROR_RATE ulong 14
21const CNR_DENY_LATENCY ulong 15
22const CNR_DENY_ID_MISMATCH ulong 16
23
24text cnr_id_dom "RSI-CANARY-ID-V1"
25
26note Config: [0]=init, [1]=min_samples, [2]=max_err_bps, [3]=max_p99_reg_bps
27global cnr_cfg ulong 8
28
29note Active canary session state:
30note [0]=bound(0/1), [1]=cand_id, [2]=provenance, [3]=samples, [4]=errors, [5]=crashes, [6]=base_p99_ns, [7]=max_obs_p99_ns
31global cnr_state ulong 8
32global cnr_id_hash uchar 32
33
34fn cnr_init min_samples ulong max_err_bps ulong max_p99_reg_bps ulong to void
35put cnr_cfg 0 1
36put cnr_cfg 1 min_samples
37put cnr_cfg 2 max_err_bps
38put cnr_cfg 3 max_p99_reg_bps
39for i ulong 8
40put cnr_state i 0
41end
42for i ulong 32
43put cnr_id_hash i uchar 0
44end
45end
46
47fn cnr_is_zero_hash h view uchar 32 to bool
48acc = uchar 0
49for i ulong 32
50acc = or acc get h i
51end
52ret eq acc uchar 0
53end
54
55fn cnr_hash_eq a view uchar 32 b view uchar 32 to bool
56diff = uchar 0
57for i ulong 32
58diff = or diff xor get a i get b i
59end
60ret eq diff uchar 0
61end
62
63fn cnr_put_u64 buf edit uchar * off ulong v ulong to void
64for i ulong 8
65sh = mul i 8
66put buf add off i uchar and shr v sh ulong 255
67end
68end
69
70note Compute canonical SHA-256 canary identity binding from cand_id and artifact digest.
71fn cnr_compute_identity cand_id ulong art_digest view uchar 32 out_id edit uchar 32 to void
72ctx = new ulong 40 0
73sha256_init ctx
74sha256_update ctx cnr_id_dom
75hdr = new uchar 8 0
76cnr_put_u64 hdr 0 cand_id
77sha256_update ctx hdr
78sha256_update ctx art_digest
79sha256_final ctx out_id
80end
81
82note Admit a candidate into the canary observation window with cryptographic identity binding.
83fn cnr_begin cand_id ulong provenance ulong base_p99_ns ulong art_digest view uchar 32 to ulong
84if eq get cnr_cfg 0 0
85ret CNR_DENY_UNINIT
86end
87if or eq provenance CNR_PROV_SYNTHETIC gt provenance CNR_PROV_SILICON
88ret CNR_DENY_SYNTHETIC
89end
90if or eq base_p99_ns 0 cnr_is_zero_hash art_digest
91ret CNR_DENY_UNBOUND_ID
92end
93for i ulong 8
94put cnr_state i 0
95end
96id_h = new uchar 32 0
97cnr_compute_identity cand_id art_digest id_h
98for i ulong 32
99put cnr_id_hash i get id_h i
100end
101put cnr_state 0 1
102put cnr_state 1 cand_id
103put cnr_state 2 provenance
104put cnr_state 6 base_p99_ns
105ret CNR_PASS
106end
107
108note Record one canary workload observation batch.
109fn cnr_observe reqs ulong errs ulong crashes ulong obs_p99_ns ulong to ulong
110if eq get cnr_state 0 0
111ret CNR_DENY_UNBOUND_ID
112end
113put cnr_state 3 add get cnr_state 3 reqs
114put cnr_state 4 add get cnr_state 4 errs
115put cnr_state 5 add get cnr_state 5 crashes
116if gt obs_p99_ns get cnr_state 7
117put cnr_state 7 obs_p99_ns
118end
119ret CNR_PASS
120end
121
122note Verify canary identity binding and evaluate all canary admission criteria.
123fn cnr_evaluate cand_id ulong art_digest view uchar 32 to ulong
124if eq get cnr_cfg 0 0
125ret CNR_DENY_UNINIT
126end
127if eq get cnr_state 0 0
128ret CNR_DENY_UNBOUND_ID
129end
130if ne get cnr_state 1 cand_id
131ret CNR_DENY_ID_MISMATCH
132end
133exp_id = new uchar 32 0
134cnr_compute_identity cand_id art_digest exp_id
135cur_id = new uchar 32 0
136for i ulong 32
137put cur_id i get cnr_id_hash i
138end
139if not cnr_hash_eq exp_id cur_id
140ret CNR_DENY_ID_MISMATCH
141end
142prov = get cnr_state 2
143if or eq prov CNR_PROV_SYNTHETIC gt prov CNR_PROV_SILICON
144ret CNR_DENY_SYNTHETIC
145end
146if gt get cnr_state 5 0
147ret CNR_DENY_CRASH
148end
149samples = get cnr_state 3
150if lt samples get cnr_cfg 1
151ret CNR_HOLD_INSUFFICIENT_SAMPLES
152end
153errs = get cnr_state 4
154if gt errs samples
155ret CNR_DENY_ERROR_RATE
156end
157err_bps = div mul errs 10000 samples
158if gt err_bps get cnr_cfg 2
159ret CNR_DENY_ERROR_RATE
160end
161base_p99 = get cnr_state 6
162obs_p99 = get cnr_state 7
163if gt obs_p99 base_p99
164reg_bps = div mul sub obs_p99 base_p99 10000 base_p99
165if gt reg_bps get cnr_cfg 3
166ret CNR_DENY_LATENCY
167end
168end
169ret CNR_PASS
170end