nx_competitive_state.nx source
↩ module page · 279 lines · 11334 B
1// nx_competitive_state.nx -- bits-up competitive-state classifier
2// for substrate primitives. Orthogonal axis to nx_trust_state.
3//
4// Operationalizes the cardinal:
5//
6// "how competitive is it and thats a thing that entropy hits
7// you cant just benchmark hit competitive and then rest but
8// thats what the industry does"
9//
10// Per [[feedback-entropy-hits-competitive-never-rest]] cardinal:
11// every benchmarked primitive declares its competitive state +
12// timestamp + entropy_window in header. Stale benchmarks auto-
13// degrade to STALE until re-measurement. Continuous re-benchmark,
14// not one-shot.
15//
16// Composes:
17// nx_etg.nx (NxEtgEntry attestation; competitive-state classifi-
18// cations emit ETG entries so the substrate's audit chain
19// carries competitive-state context)
20// nx_trust_state.nx (sibling primitive; this is the ORTHOGONAL
21// axis; a primitive's full health = (trust_state,
22// competitive_state))
23// [[feedback-bits-up-exceed-never-match]] (the substrate's
24// structural advantage is EXCEEDING; this cardinal says stay
25// exceeded, not just exceed once)
26// [[feedback-no-strawman-perf-comparisons]] (parent cardinal;
27// competitive state operationalizes honesty in comparisons)
28//
29// **Trust State:** WRITTEN_UNTESTED (per nx_trust_state taxonomy;
30// brand-new in current session; not yet KAT-passed)
31// **Competitive State:** UNCLASSIFIED (no benchmark against
32// incumbent classifiers yet)
33
34// nx_safety_envelope:
35// intended_use: "competitive-state classifier + entropy
36// decay model for substrate primitives"
37// sil_target: SIL2
38// evidence: [kat_taxonomy_complete,
39// kat_entropy_decay_rules,
40// kat_stale_detection,
41// kat_etg_attestation]
42// hazard_register: [bug-tape-competitive-overstated,
43// bug-tape-stale-not-detected,
44// bug-tape-incumbent-version-not-tracked]
45// verdict: NOT_YET_EVALUATED
46
47import "nx_syscalls.nx"
48import "nx_etg.nx"
49const NX_MAGIC_8192: i64 = 8192
50const NX_MAGIC_15564: i64 = 15564
51const NX_MAGIC_17204: i64 = 17204
52const NX_MAGIC_24576: i64 = 24576
53
54// ===== Competitive state sealed enum ==============================
55//
56// Numbers reserved (no renumbering); historical attestations replay.
57
58const NX_COMP_UNCLASSIFIED: i64 = 0 // no benchmark yet
59const NX_COMP_UNCOMPETITIVE: i64 = 1 // ≥2x worse than incumbent
60const NX_COMP_LAGGING: i64 = 2 // within 50-100% (still behind)
61const NX_COMP_PARITY: i64 = 3 // matches incumbent within ±5%
62const NX_COMP_LEADING: i64 = 4 // exceeds 5-50%
63const NX_COMP_DOMINATING: i64 = 5 // exceeds ≥50%
64const NX_COMP_STALE: i64 = 6 // benchmark older than entropy window
65const NX_COMP_REGRESSED_FROM_LEADING: i64 = 7 // was LEADING; incumbent caught up
66const NX_COMP_N: i64 = 8
67
68func nx_comp_is_valid(c: i64) -> i64 {
69 if c < 0 { return 0 }
70 if c >= NX_COMP_N { return 0 }
71 return 1
72}
73
74func nx_comp_name(c: i64) -> *u8 {
75 if c == NX_COMP_UNCLASSIFIED { return "UNCLASSIFIED" }
76 if c == NX_COMP_UNCOMPETITIVE { return "UNCOMPETITIVE" }
77 if c == NX_COMP_LAGGING { return "LAGGING" }
78 if c == NX_COMP_PARITY { return "PARITY" }
79 if c == NX_COMP_LEADING { return "LEADING" }
80 if c == NX_COMP_DOMINATING { return "DOMINATING" }
81 if c == NX_COMP_STALE { return "STALE" }
82 if c == NX_COMP_REGRESSED_FROM_LEADING { return "REGRESSED_FROM_LEADING" }
83 return "UNKNOWN"
84}
85
86// Returns 1 if competitive state implies the primitive is
87// production-quality on the COMPETITIVE axis (PARITY or better,
88// and NOT stale + NOT regressed). STALE / REGRESSED / UNCLASSIFIED
89// / UNCOMPETITIVE / LAGGING all return 0 -- substrate-honest:
90// production-quality requires CURRENT measurement showing parity-
91// or-better.
92func nx_comp_is_production_capable(c: i64) -> i64 {
93 if c == NX_COMP_PARITY { return 1 }
94 if c == NX_COMP_LEADING { return 1 }
95 if c == NX_COMP_DOMINATING { return 1 }
96 return 0
97}
98
99// ===== Entropy window sealed enum =================================
100//
101// How fast does competitive position decay in this field? Substrate-
102// honest defaults per the cardinal.
103
104const NX_ENTROPY_WINDOW_NONE: i64 = 0 // no decay (standards-locked)
105const NX_ENTROPY_WINDOW_FAST: i64 = 1 // 30 days (LLM inference, GPU compute)
106const NX_ENTROPY_WINDOW_MID: i64 = 2 // 90 days (compiler perf, runtime)
107const NX_ENTROPY_WINDOW_SLOW: i64 = 3 // 365 days (numeric primitives)
108const NX_ENTROPY_WINDOW_N: i64 = 4
109
110func nx_entropy_window_is_valid(w: i64) -> i64 {
111 if w < 0 { return 0 }
112 if w >= NX_ENTROPY_WINDOW_N { return 0 }
113 return 1
114}
115
116// Returns the entropy-window threshold in DAYS for staleness check.
117// NONE returns -1 (no decay; benchmark never stales).
118func nx_entropy_window_days(w: i64) -> i64 {
119 if w == NX_ENTROPY_WINDOW_NONE { return -1 }
120 if w == NX_ENTROPY_WINDOW_FAST { return 30 }
121 if w == NX_ENTROPY_WINDOW_MID { return 90 }
122 if w == NX_ENTROPY_WINDOW_SLOW { return 365 }
123 return 0
124}
125
126// ===== NxCompetitiveRecord ========================================
127//
128// Caller-allocated; tracks a primitive's current competitive state
129// + the incumbent it was measured against + the measurement timestamp
130// + the entropy window for the field.
131
132struct NxCompetitiveRecord {
133 primitive_id_hash: i64, // content-hash of primitive name + version
134 incumbent_id_hash: i64, // content-hash of incumbent name + version
135 competitive_state: i64, // NX_COMP_*
136 entropy_window: i64, // NX_ENTROPY_WINDOW_*
137 measured_at_day: i64, // day-of-epoch when last benchmarked
138 perf_ratio_q14: i64, // primitive / incumbent ratio, Q14 fixed-point;
139 // 1.0 = 16384; 0.5 (2x worse) = 8192;
140 // 2.0 (2x better) = 32768
141 attestation_hash: i64,
142}
143
144func nx_comp_record_init(
145 r: *NxCompetitiveRecord,
146 primitive_id_hash: i64
147) {
148 r.primitive_id_hash = primitive_id_hash
149 r.incumbent_id_hash = 0
150 r.competitive_state = NX_COMP_UNCLASSIFIED
151 r.entropy_window = NX_ENTROPY_WINDOW_MID // substrate-honest default
152 r.measured_at_day = 0
153 r.perf_ratio_q14 = 0
154 r.attestation_hash = 0
155}
156
157// Classify perf_ratio (Q14) into competitive state.
158// ratio < 0.5 (8192) -> UNCOMPETITIVE
159// 0.5 <= ratio < 0.95 (15564) -> LAGGING
160// 0.95 <= ratio < 1.05 (17204) -> PARITY (within +/-5%)
161// 1.05 <= ratio < 1.50 (24576) -> LEADING
162// ratio >= 1.5 -> DOMINATING
163func nx_comp_classify_ratio(perf_ratio_q14: i64) -> i64 {
164 if perf_ratio_q14 < NX_MAGIC_8192 { return NX_COMP_UNCOMPETITIVE }
165 if perf_ratio_q14 < NX_MAGIC_15564 { return NX_COMP_LAGGING }
166 if perf_ratio_q14 < NX_MAGIC_17204 { return NX_COMP_PARITY }
167 if perf_ratio_q14 < NX_MAGIC_24576 { return NX_COMP_LEADING }
168 return NX_COMP_DOMINATING
169}
170
171// Record a new benchmark measurement. Updates state + timestamp
172// + ratio; checks for REGRESSED_FROM_LEADING transition.
173func nx_comp_record_measurement(
174 r: *NxCompetitiveRecord,
175 incumbent_id_hash: i64,
176 perf_ratio_q14: i64,
177 measured_at_day: i64
178) -> i64 {
179 let prior_state: i64 = r.competitive_state
180 let new_state: i64 = nx_comp_classify_ratio(perf_ratio_q14)
181 r.incumbent_id_hash = incumbent_id_hash
182 r.perf_ratio_q14 = perf_ratio_q14
183 r.measured_at_day = measured_at_day
184
185 // Detect REGRESSED_FROM_LEADING: was LEADING or DOMINATING; now
186 // PARITY or below. Substrate-honest about the loss.
187 var was_high: i64 = 0
188 if prior_state == NX_COMP_LEADING { was_high = 1 }
189 if prior_state == NX_COMP_DOMINATING { was_high = 1 }
190 var is_now_low: i64 = 0
191 if new_state == NX_COMP_PARITY { is_now_low = 1 }
192 if new_state == NX_COMP_LAGGING { is_now_low = 1 }
193 if new_state == NX_COMP_UNCOMPETITIVE { is_now_low = 1 }
194 if was_high == 1 {
195 if is_now_low == 1 {
196 r.competitive_state = NX_COMP_REGRESSED_FROM_LEADING
197 return 0
198 }
199 }
200 r.competitive_state = new_state
201 return 0
202}
203
204// Check staleness: if (current_day - measured_at_day) > entropy_window_days,
205// the recorded competitive state is STALE. Returns 1 if stale; 0 otherwise.
206// Substrate-honest: callers MUST call this before trusting recorded state.
207func nx_comp_record_is_stale(
208 r: *NxCompetitiveRecord,
209 current_day: i64
210) -> i64 {
211 let win_days: i64 = nx_entropy_window_days(r.entropy_window)
212 if win_days < 0 { return 0 } // NONE: never stale
213 let measured: i64 = r.measured_at_day
214 if measured <= 0 { return 1 } // never measured = stale
215 let elapsed: i64 = current_day - measured
216 let stale_threshold: i64 = win_days + 1
217 if elapsed >= stale_threshold { return 1 }
218 return 0
219}
220
221// Effective competitive state including staleness check. If stale,
222// returns NX_COMP_STALE regardless of recorded state -- the substrate-
223// honest answer to "what's our competitive position?" is "we don't
224// know; the benchmark is older than the entropy window."
225func nx_comp_record_effective_state(
226 r: *NxCompetitiveRecord,
227 current_day: i64
228) -> i64 {
229 if nx_comp_record_is_stale(r, current_day) == 1 {
230 return NX_COMP_STALE
231 }
232 return r.competitive_state
233}
234
235// ===== ETG attestation ============================================
236//
237// Maps effective competitive state to ETG outcome:
238// LEADING / DOMINATING (parity-or-better current) -> CONFIRMED
239// PARITY -> CONFIRMED
240// LAGGING (still in pursuit) -> INCONCLUSIVE
241// UNCOMPETITIVE / REGRESSED / STALE / UNCLASSIFIED -> FALSIFIED
242
243func nx_comp_to_etg_outcome(
244 r: *NxCompetitiveRecord,
245 current_day: i64
246) -> i64 {
247 let eff: i64 = nx_comp_record_effective_state(r, current_day)
248 if eff == NX_COMP_DOMINATING { return NX_ETG_OUTCOME_CONFIRMED }
249 if eff == NX_COMP_LEADING { return NX_ETG_OUTCOME_CONFIRMED }
250 if eff == NX_COMP_PARITY { return NX_ETG_OUTCOME_CONFIRMED }
251 if eff == NX_COMP_LAGGING { return NX_ETG_OUTCOME_INCONCLUSIVE }
252 return NX_ETG_OUTCOME_FALSIFIED
253}
254
255func nx_comp_attest(
256 r: *NxCompetitiveRecord,
257 entry: *NxEtgEntry,
258 silicon_serial: i64,
259 selector_version: i64,
260 current_day: i64,
261 timestamp_q14: i64
262) -> i64 {
263 let outcome: i64 = nx_comp_to_etg_outcome(r, current_day)
264 let eff: i64 = nx_comp_record_effective_state(r, current_day)
265 let rc: i64 = nx_etg_entry_init(
266 entry,
267 silicon_serial,
268 NX_ETG_PROBE_AUDIT_TOOL_GENEALOGY, // reusing audit family
269 NX_ETG_CLAIM_PRIOR_CALIBRATION,
270 r.perf_ratio_q14, // claim: measured perf ratio
271 eff, // measurement: effective state
272 outcome,
273 selector_version,
274 timestamp_q14
275 )
276 if rc != 0 { return rc }
277 r.attestation_hash = entry.attestation_hash
278 return 0
279}