code wiki / _hdl_build / nx_ecomat_evprobe.nx

nx_ecomat_evprobe.nx source

↩ module page · 211 lines · 11264 B

1// nx_ecomat_evprobe.nx -- DOES EACH DOMAIN'S EVIDENCE POINTER ACTUALLY MATCH ITS LOG? 2// 3// ★WHY (measured 2026-08-07). A domain's grade is live-derived by scanning its evidence log for its 4// declared pattern. em_derive_level matches those bytes EXACTLY. When the pattern's CASE is wrong the 5// scan finds nothing and the derive returns TOY(1) -- and TOY is indistinguishable, in every report 6// downstream, from a real measurement of a genuinely immature domain. 7// CAUGHT LIVE: lab-science declared "verdict=" while knowledge/status/labsci_gate.log emits 8// "VERDICT=GREEN checks=13 passed=13 permil=1000". A domain scoring 13/13 at permil=1000 was being 9// published as TOY, and the ecosystem headline carried that number. 10// ★A CONSTANT WEARING THE SHAPE OF A MEASUREMENT IS WORSE THAN A BLANK: a blank would have shown up 11// as DANGLING and been chased. This showed up as a grade. 12// 13// So: for EVERY domain and BOTH evidence slots, report whether the declared pattern is actually 14// PRESENT in the declared log -- and when it is absent, say whether a CASE-VARIANT of it is present, 15// which is the difference between "this gate has not run" and "your pattern is misspelled". 16// Full population, never a sample: every domain, every declared slot, counts printed. 17// nx_ecomat_evprobe [store_prefix] 18// exit: 0 all declared pointers MATCH | 1 at least one ABSENT | 2 store empty/missing 19// license_tier: ORIGINAL expect_exit: 0 20import "nx_ecomat_lib.nx" 21import "nx_syscalls.nx" 22import "nx_gate_verdict_lib.nx" 23 24// ★FRESHNESS IS PART OF "DOES THIS POINTER HOLD UP" (added 2026-08-08, measured). 25// This organ proved every declared pointer RESOLVES and never asked WHEN the evidence was written. 26// MEASURED that day over the FULL population: 21 of 29 declared slots were staler than the estate's 27// own ECOMAT_AUTO_STALE_S, 16 logs were >=19 days old, and 8 shared mtime 1784297176 TO THE SECOND 28// (a bulk sync on 2026-07-13 -- nothing has appended since). Only 5 of 26 domains had fully fresh 29// evidence. A pointer that resolves to a three-week-old log is not a live witness, and the rollup 30// was publishing 450 permil off exactly that. 31// ★COMPOSED, NOT RE-IMPLEMENTED: gv_age_days is the estate's ONE age primitive, and its own header 32// already named this case -- "counting its stale last line as a pass is exactly the stale-green lie 33// the ecomat DANGLING state exists to prevent". The predicate was banked in one organ and absent 34// from the next. A second age function here would be the duplicate-ruler defect. 35// ★STALE IS ITS OWN BUCKET, and it is ORTHOGONAL to the match partition: a stale pointer still 36// MATCHES, so it is NOT added to match/case/absent/unreadable -- that partition must keep summing. 37// Folding it into ABSENT would merge "the gate stopped running" with "the pattern never matched", 38// two findings with opposite remedies. 39// ★UNAGEABLE FAILS CLOSED: an unstattable log is never counted fresh. "I could not look" is not "fine". 40const EV_STALE_DAYS_DEFAULT: i64 = 7 // = evidence_policy.conf ttl_sec (604800s). argv[2] overrides. 41const EV_EXIT_ABSENT: i64 = 1 42const EV_EXIT_NOSTORE: i64 = 2 43const EV_LOWER_DELTA: i64 = 32 // 'a' - 'A' 44const EV_UPPER_A: i64 = 65 45const EV_UPPER_Z: i64 = 90 46 47func ev_tolower(c: i64) -> i64 { 48 if c >= EV_UPPER_A { if c <= EV_UPPER_Z { return c + EV_LOWER_DELTA } } 49 return c 50} 51 52// Decimal parse for the argv-supplied stale window. Defined locally under the ev_ prefix rather than 53// reaching for an assumed helper: nx_cc compiles an UNDEFINED IDENTIFIER silently (seq1012), so a 54// guessed function name is a runtime crash, not a build error. An unparseable arg returns the 55// documented default rather than 0 -- a 0-day window would call every slot stale and read as alarm. 56func ev_atoi(s: *u8) -> i64 { 57 var i: i64 = 0 58 var n: i64 = 0 59 var any: i64 = 0 60 while s[i] != (0 as u8) { 61 let c: i64 = s[i] as i64 62 if c >= 48 { if c <= 57 { n = n * 10 + (c - 48); any = 1 } } 63 i = i + 1 64 } 65 if any == 0 { return EV_STALE_DAYS_DEFAULT } 66 return n 67} 68 69// case-INSENSITIVE contains. Deliberately separate from el_contains rather than a flag on it: 70// the two answers mean different things here and merging them would hide the diagnosis. 71func ev_contains_ci(buf: *u8, n: i64, pat: *u8) -> i64 { 72 let pl: i64 = el_len(pat) 73 if pl == 0 { return 0 } 74 var i: i64 = 0 75 while i + pl <= n { 76 var k: i64 = 0 77 var ok: i64 = 1 78 while k < pl { 79 if ev_tolower(buf[i+k] as i64) != ev_tolower(pat[k] as i64) { ok = 0; k = pl } else { k = k + 1 } 80 } 81 if ok == 1 { return 1 } 82 i = i + 1 83 } 84 return 0 85} 86 87// Probe one declared slot. Returns 0 MATCH, 1 ABSENT-but-case-variant-present, 2 ABSENT entirely, 88// 3 log UNREADABLE. Prints one line per slot -- the values, not just a verdict, because the whole 89// point is that the verdict alone could not distinguish these. 90func ev_slot(dom: *u8, slot: i64, evkind: i64, evlog: *u8, evpat: *u8, cnt: *i64) -> i64 { 91 if evkind == 0 { return 0 - 1 } 92 let szp: *i64 = sys_mmap(16) as *i64 93 let eb: *u8 = ss_readall(evlog, szp) 94 let en: i64 = szp[0] 95 _p(" " as *u8); _p(dom); _p(" slot" as *u8); _fn(1, slot) 96 _p(" kind=" as *u8); _fn(1, evkind) 97 _p(" log=" as *u8); _p(evlog) 98 _p(" pat='" as *u8); _p(evpat); _p("' -> " as *u8) 99 if en < 0 { 100 _p("UNREADABLE (dangling pointer)\n" as *u8) 101 cnt[3] = cnt[3] + 1 102 return 3 103 } 104 if el_contains(eb, en, evpat) == 1 { 105 _p("MATCH (" as *u8); _fn(1, en); _p(" bytes)" as *u8) 106 // AGE THE WITNESS YOU ARE ABOUT TO CALL EVIDENCE. cnt[6] carries the caller's stale window in 107 // days -- slot-indexed policy rather than a 7th parameter, so new clauses stay additive. 108 let age: i64 = gv_age_days(evlog, sys_now_realtime_sec()) 109 _p(" age_days=" as *u8); _fn(1, age) 110 if age < 0 { _p(" UNAGEABLE (unstattable -- fail-closed, NOT counted fresh)" as *u8); cnt[5] = cnt[5] + 1 } 111 if age >= 0 { 112 if age > cnt[6] { 113 _p(" ★STALE -- the pointer resolves but nothing has re-measured it inside the declared" as *u8) 114 _p(" window; this grade rests on a measurement nobody has repeated" as *u8) 115 cnt[4] = cnt[4] + 1 116 } 117 } 118 _p("\n" as *u8) 119 cnt[0] = cnt[0] + 1 120 return 0 121 } 122 if ev_contains_ci(eb, en, evpat) == 1 { 123 // THE ACTIONABLE ONE. The evidence exists and the gate is reporting; only the case differs. 124 // Silent demotion to TOY, published as a grade. 125 _p("★CASE-MISMATCH -- the log DOES contain this pattern in a different case." as *u8) 126 _p(" The grade is being silently demoted to TOY. Fix the declared pattern's case.\n" as *u8) 127 cnt[1] = cnt[1] + 1 128 return 1 129 } 130 _p("ABSENT (pattern genuinely not in the log -- gate may not have run)\n" as *u8) 131 cnt[2] = cnt[2] + 1 132 return 2 133} 134 135func main(argc: i64, argv: *i64) -> i64 { 136 var store: *u8 = ECOMAT_STORE 137 if argc >= 2 { store = argv[1] as *u8 } 138 _p("=== nx_ecomat_evprobe -- does every declared evidence pointer match its log? ===\n" as *u8) 139 let h: *i64 = ss_open(store) 140 if (h as i64) == 0 { _p("store MISSING/EMPTY\n" as *u8); sys_exit(EV_EXIT_NOSTORE); return EV_EXIT_NOSTORE } 141 let pq: *i64 = sys_mmap(16) as *i64 142 let lq: *i64 = sys_mmap(16) as *i64 143 let dom: *u8 = sys_mmap(ECOMAT_DOM_CAP) 144 let elog: *u8 = sys_mmap(ECOMAT_EVLOG_CAP) 145 let epat: *u8 = sys_mmap(ECOMAT_EVPAT_CAP) 146 let elog2: *u8 = sys_mmap(ECOMAT_EVLOG_CAP) 147 let epat2: *u8 = sys_mmap(ECOMAT_EVPAT_CAP) 148 // cnt[0]=match cnt[1]=case-mismatch cnt[2]=absent cnt[3]=unreadable 149 // cnt[4]=STALE cnt[5]=UNAGEABLE cnt[6]=stale window in days (policy carried by slot, not a 7th param) 150 // ★cnt[4] IS ORTHOGONAL TO 0..3 -- a STALE slot is ALSO counted in cnt[0]. Never add it to the 151 // partition: the partition answers "does the pointer RESOLVE", staleness answers "WHEN was it last 152 // re-measured". Merging them would break the sum and hide one finding inside the other. 153 let cnt: *i64 = sys_mmap(128) as *i64 154 var stale_days: i64 = EV_STALE_DAYS_DEFAULT 155 if argc >= 3 { stale_days = ev_atoi(argv[2] as *u8) } 156 cnt[6] = stale_days 157 var domains: i64 = 0 158 var declared: i64 = 0 159 var undeclared: i64 = 0 160 var k: i64 = 0 161 var go: i64 = 1 162 while go == 1 { 163 let key: *u8 = sys_mmap(64); ec_key(k, key) 164 if ss_hget(h, key, pq, lq) == 1 { 165 let v: *u8 = pq[0] as *u8 166 domains = domains + 1 167 ec_str(v, 0, dom, ECOMAT_DOM_CAP) 168 ec_str(v, 3, elog, ECOMAT_EVLOG_CAP); ec_str(v, 4, epat, ECOMAT_EVPAT_CAP) 169 ec_str(v, 5, elog2, ECOMAT_EVLOG_CAP); ec_str(v, 6, epat2, ECOMAT_EVPAT_CAP) 170 let k1: i64 = ec_evkind(v) 171 let k2: i64 = ec_evkind2(v) 172 if k1 == 0 { if k2 == 0 { undeclared = undeclared + 1 } } 173 if k1 != 0 { declared = declared + 1; ev_slot(dom, 1, k1, elog, epat, cnt) } 174 if k2 != 0 { declared = declared + 1; ev_slot(dom, 2, k2, elog2, epat2, cnt) } 175 k = k + 1 176 } else { go = 0 } 177 } 178 // PARTITION MUST SUM -- print it and reconcile, or a leak hides in the residual. 179 _p("\n domains=" as *u8); _fn(1, domains) 180 _p(" declared_slots=" as *u8); _fn(1, declared) 181 _p(" (match=" as *u8); _fn(1, cnt[0]) 182 _p(" CASE-MISMATCH=" as *u8); _fn(1, cnt[1]) 183 _p(" absent=" as *u8); _fn(1, cnt[2]) 184 _p(" unreadable=" as *u8); _fn(1, cnt[3]) 185 _p(") no-pointer-domains=" as *u8); _fn(1, undeclared); _p("\n" as *u8) 186 _p(" LIVENESS: stale=" as *u8); _fn(1, cnt[4]) 187 _p(" unageable=" as *u8); _fn(1, cnt[5]) 188 _p(" of " as *u8); _fn(1, declared) 189 _p(" declared slots (window=" as *u8); _fn(1, cnt[6]) 190 _p("d, evidence_policy.conf ttl_sec; argv[2] overrides)\n" as *u8) 191 _p(" ★STALE IS ORTHOGONAL TO THE PARTITION ABOVE -- a stale slot still MATCHES. Do not add it in.\n" as *u8) 192 if cnt[4] > 0 { 193 _p(" ★" as *u8); _fn(1, cnt[4]) 194 _p(" declared slot(s) resolve to evidence nobody has re-measured inside the window.\n" as *u8) 195 _p(" Those grades are not REFUTED, they are UNSUPPORTED -- RED means a method ran and reported\n" as *u8) 196 _p(" failure; this means no method has run lately. They are different findings and demand\n" as *u8) 197 _p(" different work: re-run the gate, do not re-grade the domain.\n" as *u8) 198 } 199 let sum: i64 = cnt[0] + cnt[1] + cnt[2] + cnt[3] 200 _p(" partition: " as *u8); _fn(1, sum); _p(" of " as *u8); _fn(1, declared) 201 if sum == declared { _p(" -- SUMS\n" as *u8) } else { _p(" -- ⚠DOES NOT SUM (a slot went uncounted)\n" as *u8) } 202 if cnt[1] > 0 { 203 _p("\n ★" as *u8); _fn(1, cnt[1]) 204 _p(" domain(s) are being published as TOY purely because a declared pattern's CASE is wrong.\n" as *u8) 205 _p(" That is not a measurement of immaturity; it is a measurement of a typo.\n" as *u8) 206 } 207 _p(" verdict=" as *u8) 208 if cnt[1] + cnt[2] + cnt[3] == 0 { _p("GREEN\n" as *u8); sys_exit(0); return 0 } 209 _p("RED\n" as *u8) 210 sys_exit(EV_EXIT_ABSENT); return EV_EXIT_ABSENT 211}