code wiki / _hdl_build / nx_evclass_route.nx

nx_evclass_route.nx source

↩ module page · 364 lines · 16716 B

1// nx_evclass_route.nx -- route DERIVED oracle rows to the DOMAINS that actually earned them. 2// 3// THE DEFECT THIS CLOSES (measured 2026-08-01): nx_evoracle_sweep correctly derives third-party oracle 4// rows -- RFC 9807, RFC 7748, RFC 9497, FIPS 180-4 -- and writes them ALL to knowledge/status/ 5// evclass_sovereign.conf. But `sovereign` IS NOT A DOMAIN (no sovereign.matrix), while nx_sota_status 6// reads evclass_<domain>.conf per domain. So 7 genuine third-party attestations landed in a file NO 7// CONSUMER READS, and PROVEN stayed 0/41 with the evidence sitting right there. 8// 9// ★★★★★A NEAR-ZERO MATCH MEANS A WRONG JOIN KEY, NOT A MISSING POPULATION. The derivation was never the 10// problem; the rows simply were not addressed to anyone. 11// 12// THE JOIN: every derived row carries `gate=<name>`, and knowledge/compare/<domain>.gates names the gates 13// a domain claims. So gate -> domain is a real, checkable key, not an inference. 14// 15// OUTCOMES ARE NEVER COLLAPSED (the sweep's own law): ROUTED / ALREADY / UNROUTED are counted and named 16// separately -- a row nobody claims and a row already present must never look the same. 17// ⛔CORRECTED 2026-09-03 -- THIS LINE USED TO SAY the rows remain UNSIGNED because at_verify_row refuses 18// them "until an operator-held key exists", and that this organ cannot supply ATTRIBUTION. IT IS WRONG FOR 19// THE TWO CLASSES THIS ORGAN ACTUALLY ROUTES. It was inherited verbatim from nx_evoracle_sweep's header, 20// which was true when IT was written and stopped being true hours later when an agent created 21// knowledge/attest_keys.conf and registered two role=machine keys -- sanctioned there in its own words 22// because for EV_CLASS_ORACLE "independence comes from the REFERENCE, not the signer". 23// PROVEN END TO END 2026-09-03, not argued: a derived oracle row signed with the registered machine key 24// (pub=08fc04ab..4fa8) returned at_verify_row -> OK (rc=0) against the LIVE registry, and 25// nx_attest_ceremony's gate is 10/10 with T6 oracle+machine=OK and T9 experiential+machine=OK. Only T4, 26// class=human, refuses a machine key -- correct, and never to be loosened. 27// ⇒ A RENEWED ORACLE OR EXPERIENTIAL ROW MAY AND SHOULD BE MACHINE-SIGNED. Withholding the signature is 28// what kept PROVEN at 0 while this organ's own header recorded 45 domains holding fresh evidence. 29// ★★★★★★THE COMMENT WAS THE BUG: nothing in the code was wrong, and a stale sentence copied between two 30// organs became an estate-wide belief that only the operator could unblock the honesty ratio. 31// 32// nx_evclass_route [srcfile] default knowledge/status/evclass_sovereign.conf 33// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 34import "nx_gateorder_lib.nx" 35import "nx_estate_path.nx" // ep_anchor: the CWD must not decide this organ verdict 36const ER_MAGIC_65536: i64 = 65536 37 38const ER_CAP: i64 = 262144 39const ER_PATH: i64 = 512 40const ER_NAMEW: i64 = 96 41const ER_MAXDOM: i64 = 128 42 43static er_src: *u8 44static er_gates: *u8 45static er_doms: *u8 46static er_ndom: i64 47static er_routed: i64 48static er_already: i64 49static er_unrouted: i64 50static er_rows: i64 51static er_renewed: i64 52 53// RENEWAL (2026-09-02): an attestation expires on the same TTL as a stamp (nx_sota_status, half-life law 54// in nx_evidence_beat), so a routed row that is merely PRESENT is not evidence once it is old -- and until 55// today this organ counted an EXPIRED row as ALREADY and appended nothing. MEASURED: 45 domains carried 56// rows from 2026-08-01..03 against a 604800 s TTL, the sweep re-derived 10 fresh rows, and route reported 57// ROUTED=0 ALREADY=4 -- so the board read PROVEN 0/105 with fresh evidence in hand. Now a present row 58// whose epoch is older than half the policy TTL is RENEWED: the fresh row is APPENDED (additive-only, the 59// loader ORs classes and counts freshness per row), and the outcome is named separately. 60const ER_DEF_TTL_SEC: i64 = 604800 61func er_num_after(buf: *u8, n: i64, key: *u8, from: i64) -> i64 { 62 var kl: i64 = 0 63 while key[kl] != (0 as u8) { kl = kl + 1 } 64 var i: i64 = from 65 while i + kl <= n { 66 if go_match_at(buf, i, n, key) == 1 { 67 var p: i64 = i + kl 68 var v: i64 = 0 69 var got: i64 = 0 70 var go: i64 = 1 71 while go == 1 { 72 if p >= n { go = 0 } else { 73 let c: i64 = buf[p] as i64 74 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); got = 1; p = p + 1 } else { go = 0 } } else { go = 0 } 75 } 76 } 77 if got == 1 { return v } 78 return 0 - 1 79 } 80 i = i + 1 81 } 82 return 0 - 1 83} 84// the policy TTL the referee reads (knowledge/evidence_policy.conf ttl_sec=), else the referee's default. 85func er_policy_ttl() -> i64 { 86 let lp: *i64 = sys_mmap(16) as *i64 87 lp[0] = 0 88 let b: *u8 = sys_read_file("knowledge/evidence_policy.conf\x00" as *u8, lp) 89 if lp[0] <= 0 { return ER_DEF_TTL_SEC } 90 let v: i64 = er_num_after(b, lp[0], "ttl_sec=" as *u8, 0) 91 if v <= 0 { return ER_DEF_TTL_SEC } 92 return v 93} 94// IDEMPOTENCE (2026-09-02, caught on the second live run): the renewal must read the NEWEST row for a 95// gate, not the first -- go_first lands on the original expired row every time, so each run appended 96// another fresh copy (measured: deploy went 2 -> 4 rows in two runs). Scan every occurrence, keep the 97// max epoch; a row renewed within the half-life is then ALREADY, not RENEWED again. 98func er_newest_epoch(buf: *u8, n: i64, gname: *u8) -> i64 { 99 var best: i64 = 0 - 1 100 var i: i64 = 0 101 while i < n { 102 if go_match_at(buf, i, n, gname) == 1 { 103 let ep: i64 = er_row_epoch(buf, n, i) 104 if ep > best { best = ep } 105 } 106 i = i + 1 107 } 108 return best 109} 110// epoch= of the row that starts at (or after) offset `at` in buf, bounded to that row's line. 111func er_row_epoch(buf: *u8, n: i64, at: i64) -> i64 { 112 var e: i64 = at 113 while e < n { if buf[e] == (10 as u8) { e = n + 1 } else { e = e + 1 } } 114 var end: i64 = e 115 if end > n { end = e - 1 } 116 return er_num_after(buf, end, "epoch=" as *u8, at) 117} 118 119func er_init() { 120 er_renewed = 0 121 er_src = sys_mmap(ER_CAP + 64) as *u8 122 er_gates = sys_mmap(ER_CAP + 64) as *u8 123 er_doms = sys_mmap(ER_MAXDOM * ER_NAMEW + 64) as *u8 124 er_ndom = 0 125 er_routed = 0 126 er_already = 0 127 er_unrouted = 0 128 er_rows = 0 129} 130 131func er_read_into(path: *u8, buf: *u8, cap: i64) -> i64 { 132 let fd: i64 = sys_openat_rd(path) 133 if fd < 0 { return 0 - 1 } 134 var total: i64 = 0 135 var done: i64 = 0 136 while done == 0 { 137 let want: i64 = cap - total 138 if want <= 0 { done = 1 } 139 else { 140 let got: i64 = sys_read(fd, ((buf as i64) + total) as *u8, want) 141 if got <= 0 { done = 1 } 142 else { total = total + got } 143 } 144 } 145 sys_close(fd) 146 buf[total] = 0 as u8 147 return total 148} 149 150// Collect domain names from knowledge/compare/*.gates 151func er_collect_domains() { 152 let dfd: i64 = sys_openat_rd("knowledge/compare" as *u8) 153 if dfd < 0 { return } 154 let dbuf: *u8 = sys_mmap(ER_MAGIC_65536 + 64) as *u8 155 var looping: i64 = 1 156 while looping == 1 { 157 let nread: i64 = sys_getdents64(dfd, dbuf, ER_MAGIC_65536) 158 if nread <= 0 { looping = 0 } 159 else { 160 var off: i64 = 0 161 while off < nread { 162 let lo: i64 = dbuf[off + 16] as i64 163 let hi: i64 = dbuf[off + 17] as i64 164 let reclen: i64 = lo + hi * 256 165 let nm: *u8 = ((dbuf as i64) + off + 19) as *u8 166 var nlen: i64 = 0 167 while nm[nlen] != (0 as u8) { nlen = nlen + 1 } 168 if nlen > 6 { 169 if go_match_at(nm, nlen - 6, nlen, ".gates" as *u8) == 1 { 170 if er_ndom < ER_MAXDOM { 171 var w: i64 = 0 172 let slot: i64 = (er_doms as i64) + er_ndom * ER_NAMEW 173 while w < nlen - 6 { 174 if w < ER_NAMEW - 1 { 175 let d: *u8 = (slot + w) as *u8 176 d[0] = nm[w] 177 } 178 w = w + 1 179 } 180 let term: *u8 = (slot + w) as *u8 181 term[0] = 0 as u8 182 er_ndom = er_ndom + 1 183 } 184 } 185 } 186 if reclen <= 0 { off = nread } 187 else { off = off + reclen } 188 } 189 } 190 } 191 sys_close(dfd) 192} 193 194func er_path_for(pre: *u8, dom: *u8, suf: *u8, out: *u8) { 195 var w: i64 = 0 196 var i: i64 = 0 197 while pre[i] != (0 as u8) { 198 out[w] = pre[i] 199 w = w + 1 200 i = i + 1 201 } 202 var j: i64 = 0 203 while dom[j] != (0 as u8) { 204 if w < ER_PATH - 12 { 205 out[w] = dom[j] 206 w = w + 1 207 } 208 j = j + 1 209 } 210 var k: i64 = 0 211 while suf[k] != (0 as u8) { 212 out[w] = suf[k] 213 w = w + 1 214 k = k + 1 215 } 216 out[w] = 0 as u8 217} 218 219func main(argc: i64, argv: *i64) -> i64 { 220 // ANCHOR FIRST (2026-08-04, nx_cwdguard finding): this organ reads a RELATIVE 221 // knowledge/ path, so its answer depended on where it was launched. No-op when 222 // already at the estate root, so the cron/MCP context is unchanged. 223 ep_anchor() 224 er_init() 225 var src: *u8 = "knowledge/status/evclass_sovereign.conf" as *u8 226 if argc > 1 { src = argv[1] as *u8 } 227 go_puts("=== NX-EVCLASS-ROUTE: address derived oracle rows to the domains that earned them ===\n\n" as *u8) 228 let sn: i64 = er_read_into(src, er_src, ER_CAP) 229 if sn <= 0 { 230 go_puts("no derived rows to route (run nx_evoracle_sweep first)\n" as *u8) 231 return 0 232 } 233 er_collect_domains() 234 go_kv("domains_with_gates" as *u8, er_ndom) 235 go_puts("\n\n" as *u8) 236 237 let gpath: *u8 = sys_mmap(ER_PATH + 64) as *u8 238 let opath: *u8 = sys_mmap(ER_PATH + 64) as *u8 239 let gname: *u8 = sys_mmap(ER_NAMEW + 64) as *u8 240 241 var ls: i64 = 0 242 var i: i64 = 0 243 while i <= sn { 244 var eol: i64 = 0 245 if i == sn { eol = 1 } 246 else { if er_src[i] == (10 as u8) { eol = 1 } } 247 if eol == 1 { 248 var skip: i64 = 0 249 if ls >= i { skip = 1 } 250 else { if er_src[ls] == (35 as u8) { skip = 1 } } 251 if skip == 0 { 252 // pull gate=<name> out of the row -- the join key 253 var gp: i64 = 0 - 1 254 var s: i64 = ls 255 while s < i { 256 if go_match_at(er_src, s, i, "gate=" as *u8) == 1 { 257 gp = s + 5 258 s = i 259 } else { s = s + 1 } 260 } 261 if gp > 0 { 262 er_rows = er_rows + 1 263 var w: i64 = 0 264 var q: i64 = gp 265 var stop: i64 = 0 266 while stop == 0 { 267 if q >= i { stop = 1 } 268 else { 269 if er_src[q] == (32 as u8) { stop = 1 } 270 else { 271 if w < ER_NAMEW - 1 { 272 gname[w] = er_src[q] 273 w = w + 1 274 } 275 q = q + 1 276 } 277 } 278 } 279 gname[w] = 0 as u8 280 var hit: i64 = 0 281 var d: i64 = 0 282 while d < er_ndom { 283 let dom: *u8 = ((er_doms as i64) + d * ER_NAMEW) as *u8 284 er_path_for("knowledge/compare/" as *u8, dom, ".gates" as *u8, gpath) 285 let gn: i64 = er_read_into(gpath, er_gates, ER_CAP) 286 if gn > 0 { 287 if go_first(er_gates, gn, gname) >= 0 { 288 hit = 1 289 er_path_for("knowledge/status/evclass_" as *u8, dom, ".conf" as *u8, opath) 290 // ALREADY vs ROUTED must not look the same 291 let existing: i64 = er_read_into(opath, er_gates, ER_CAP) 292 var dup: i64 = 0 293 var renew: i64 = 0 294 if existing > 0 { 295 let at: i64 = go_first(er_gates, existing, gname) 296 if at >= 0 { 297 dup = 1 298 // RENEWAL: a present row older than half the policy TTL is not 299 // evidence for long -- append the fresh derivation beside it. 300 let ep: i64 = er_newest_epoch(er_gates, existing, gname) 301 let now: i64 = sys_now_realtime_sec() 302 let half: i64 = er_policy_ttl() / 2 303 if ep <= 0 { renew = 1 } else { if now - ep > half { renew = 1 } } 304 } 305 } 306 if renew == 1 { dup = 0 } 307 if dup == 1 { 308 er_already = er_already + 1 309 } else { 310 if renew == 1 { 311 er_renewed = er_renewed + 1 312 go_puts(" RENEWED " as *u8) 313 go_puts(gname) 314 go_puts(" (present row older than half the policy TTL -- fresh derivation appended)\n" as *u8) 315 } 316 let fd: i64 = sys_openat_append(opath, 0x1A4) 317 if fd >= 0 { 318 if existing <= 0 { 319 sys_write(fd, "# DERIVED by nx_evoracle_sweep, ADDRESSED here by nx_evclass_route.\n" as *u8, 68) 320 sys_write(fd, "# Join key: the row's gate= is cited by this domain's .gates. UNSIGNED -- at_verify_row\n" as *u8, 88) 321 sys_write(fd, "# refuses these until an operator-held key is registered. Derivation, not attribution.\n" as *u8, 87) 322 } 323 sys_write(fd, ((er_src as i64) + ls) as *u8, i - ls) 324 sys_write(fd, "\n" as *u8, 1) 325 sys_close(fd) 326 er_routed = er_routed + 1 327 go_puts(" ROUTED " as *u8) 328 go_puts(gname) 329 go_puts(" -> " as *u8) 330 go_puts(dom) 331 go_puts("\n" as *u8) 332 } 333 } 334 } 335 } 336 d = d + 1 337 } 338 if hit == 0 { 339 er_unrouted = er_unrouted + 1 340 go_puts(" UNROUTED " as *u8) 341 go_puts(gname) 342 go_puts(" (no domain's .gates cites this gate -- real evidence with no claimant)\n" as *u8) 343 } 344 } 345 } 346 ls = i + 1 347 } 348 i = i + 1 349 } 350 351 go_puts("\n-- RESULT (outcomes named separately, never collapsed) --\n" as *u8) 352 go_kv("rows_read" as *u8, er_rows) 353 go_kv("ROUTED" as *u8, er_routed) 354 go_kv("ALREADY" as *u8, er_already) 355 go_kv("RENEWED" as *u8, er_renewed) 356 go_kv("UNROUTED" as *u8, er_unrouted) 357 go_puts("\n\n" as *u8) 358 go_puts(" UNROUTED is not a failure of derivation -- it is a gate whose third-party evidence NO\n" as *u8) 359 go_puts(" domain currently claims. Wiring it into a <domain>.gates converts it into countable\n" as *u8) 360 go_puts(" evidence; leaving it means a real external attestation benefits nobody.\n" as *u8) 361 go_puts(" ⚠ROUTED rows are UNSIGNED and will be REFUSED by at_verify_row until an operator-held\n" as *u8) 362 go_puts(" key is registered. This organ supplies ADDRESSING; only that key supplies ATTRIBUTION.\n" as *u8) 363 return 0 364}