code wiki / _hdl_build / nx_vizsla_recruiter_gate.nx

nx_vizsla_recruiter_gate.nx source

↩ module page · 325 lines · 14811 B

1// nx_vizsla_recruiter_gate.nx -- VIZSLA V2c gate: the recruiter-channel engine 2// is gate-proven against a HAND-ROUTED fixture corpus and HAND-COUNTED day 3// arithmetic (the oracle is this header, not the module under test). 4// 5// channels: recruiter=700 referral=550 cold-apply=100; strong_permil=500; 6// stale_days=30; agents r1(jane: compilers systems nishilang), 7// r2(sam: sales marketing), f1(cousin-max: writing editing), 8// portal(cold-apply: *) 9// postings: j1[compilers rust writing] j2[nishilang compilers systems] 10// j3[sales travel] j4[editing writing remote] j5[travel logistics] 11// hand routing: 12// j1: r1 ov=1 (700) beats f1 ov=1 (550) -> recruiter/r1 700 STRONG 13// j2: r1 ov=3 -> recruiter/r1 700 STRONG 14// j3: r2 ov=1 -> recruiter/r2 700 STRONG 15// j4: no recruiter overlap; f1 ov=2 -> referral/f1 550 STRONG 16// j5: only portal wildcard -> cold-apply/portal 100 WEAK 17// => posts=5 strong=4 weak=1 unrouted=0 18// touches (seg-3001): r1@2026-06-01, r2@2026-04-20, r1@2026-05-28 19// warm today=2026-06-10: r1 last=2026-06-01 days=9 FRESH (LATEST date wins, 20// not last-stored: 05-28 is stored AFTER 06-01); r2 days=51 STALE; f1 COLD; 21// portal EXCLUDED (cold-apply 100 < strong 500 = not worth tending, by data) 22// => agents=3 fresh=1 stale=1 cold=1 23// DATA-DRIVEN: stale_days 30->60 in fixture data only => r2 days=51 FRESH, 24// verdict fresh=2 stale=0 cold=1, same binary. 25// 26// Rows: 27// 1 loud-fail-missing-channels route on absent file => exit 1 28// 2 route-recruiter-strong j2 recruiter/r1 strength=700 overlap=3 STRONG 29// 3 route-referral-fallback j4 referral/f1 strength=550 overlap=2 STRONG 30// 4 cold-apply-weak-named j5 cold-apply/portal 100 WEAK + verdict 5/4/1/0 31// 5 best-channel-wins j1 via recruiter r1, not referral f1 32// 6 route-determinism byte-identical twice 33// 7 touch-load new=3 committed seg-3001 34// 8 idempotent-retouch new=0 dup_instore=3 segment=none (law 10) 35// 9 latest-date-wins r1 last=2026-06-01 days=9 FRESH 36// 10 stale-reconnect r2 days=51 STALE action=reconnect 37// 11 cold-introduce-weak-excluded f1 COLD action=introduce AND no portal row 38// 12 DATA-DRIVEN-stale-threshold stale_days=60 file => r2 FRESH, no recompile 39// 13 warm-determinism byte-identical twice 40// Evidence: VIZSLA-RECRUIT-GATE line -> stdout + knowledge/status/vizsla_gate.log; 41// exit 0 iff 13/13. 42// spec: knowledge/specs/2026-06-10-nishi-vizsla-ladder.md license_tier: ORIGINAL 43import "nx_syscalls.nx" 44import "nx_gate_verdict.nx" 45 46func rg_slen(s: *u8) -> i64 { 47 var n: i64 = 0 48 while s[n] != (0 as u8) { n = n + 1 } 49 return n 50} 51 52func rg_p(s: *u8) -> i64 { 53 sys_write(1, s, rg_slen(s)) 54 return 0 55} 56 57func rg_cat(dst: *u8, off: i64, s: *u8) -> i64 { 58 var i: i64 = 0 59 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 60 return off + i 61} 62 63func rg_catn(dst: *u8, off: i64, v: i64) -> i64 { 64 var o: i64 = off 65 var m: i64 = v 66 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 67 let t: *u8 = sys_mmap(28) 68 var k: i64 = 0 69 if m == 0 { t[0] = 48 as u8; k = 1 } 70 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 71 var i: i64 = 0 72 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 73 return o + k 74} 75 76func rg_write(path: *u8, content: *u8) -> i64 { 77 let fd: i64 = sys_openat_wr(path, 0x1a4) 78 if fd < 0 { return 0 - 1 } 79 sys_write(fd, content, rg_slen(content)) 80 sys_close(fd) 81 return 0 82} 83 84func rg_readall(path: *u8, szout: *i64) -> *u8 { 85 let fd: i64 = sys_openat_rd(path) 86 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 87 let sz: i64 = sys_lseek(fd, 0, 2) 88 sys_lseek(fd, 0, 0) 89 let buf: *u8 = sys_mmap(sz + 64) 90 var got: i64 = 0 91 var n: i64 = 1 92 while n > 0 { 93 n = sys_read(fd, (buf as i64 + got) as *u8, 65536) 94 if n > 0 { got = got + n } 95 } 96 sys_close(fd) 97 szout[0] = got 98 return buf 99} 100 101func rg_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, outpath: *u8) -> i64 { 102 let pid: i64 = sys_fork() 103 if pid == 0 { 104 if (outpath as i64) != 0 { 105 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 106 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 107 } 108 let argv: *i64 = sys_mmap(64) as *i64 109 argv[0] = elf as i64 110 var i: i64 = 1 111 if (a1 as i64) != 0 { argv[i] = a1 as i64; i = i + 1 } 112 if (a2 as i64) != 0 { argv[i] = a2 as i64; i = i + 1 } 113 if (a3 as i64) != 0 { argv[i] = a3 as i64; i = i + 1 } 114 if (a4 as i64) != 0 { argv[i] = a4 as i64; i = i + 1 } 115 argv[i] = 0 116 let envp: *i64 = sys_mmap(16) as *i64 117 envp[0] = 0 118 sys_execve(elf, argv, envp) 119 sys_exit(127) 120 } 121 let st: *i64 = sys_mmap(16) as *i64 122 sys_wait4(pid, st, 0) 123 let sig: i64 = st[0] & 0x7f 124 if sig != 0 { return 128 + sig } 125 return (st[0] >> 8) & 0xff 126} 127 128func rg_has(path: *u8, needle: *u8) -> i64 { 129 let szp: *i64 = sys_mmap(16) as *i64 130 let b: *u8 = rg_readall(path, szp) 131 let sz: i64 = szp[0] 132 let n: i64 = rg_slen(needle) 133 if sz < n { return 0 } 134 var i: i64 = 0 135 while i + n <= sz { 136 var ok: i64 = 1 137 var j: i64 = 0 138 while j < n { 139 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } 140 } 141 if ok == 1 { return 1 } 142 i = i + 1 143 } 144 return 0 145} 146 147func rg_fileeq(p1: *u8, p2: *u8) -> i64 { 148 let s1: *i64 = sys_mmap(16) as *i64 149 let s2: *i64 = sys_mmap(16) as *i64 150 let b1: *u8 = rg_readall(p1, s1) 151 let b2: *u8 = rg_readall(p2, s2) 152 if s1[0] != s2[0] { return 0 } 153 if s1[0] <= 0 { return 0 } 154 var i: i64 = 0 155 while i < s1[0] { 156 if b1[i] != b2[i] { return 0 } 157 i = i + 1 158 } 159 return 1 160} 161 162func rg_row(name: *u8, pass: i64) -> i64 { 163 rg_p("ROW " as *u8) 164 rg_p(name) 165 if pass == 1 { rg_p(" PASS\n" as *u8) } else { rg_p(" FAIL\n" as *u8) } 166 return pass 167} 168 169func main(argc: i64, argv: *i64) -> i64 { 170 rg_p("=== VIZSLA RECRUITER GATE: hand-routed channel KATs (relationship > cold-apply) ===\n" as *u8) 171 var rb: *u8 = "buildroot/_build/nx_vizsla_recruiter.sov.elf" as *u8 172 if argc > 1 { rb = argv[1] as *u8 } 173 let pr: i64 = sys_openat_rd(rb) 174 if pr >= 0 { sys_close(pr) } 175 else { 176 rg_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 177 rg_run("_offc/nx_sov_build_run.elf" as *u8, "nx_vizsla_recruiter" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, "/tmp/vzr_rebuild.out" as *u8) 178 } 179 180 // epoch-unique virgin store prefix for the touch ledger 181 let pfx: *u8 = sys_mmap(128) 182 var po: i64 = 0 183 po = rg_cat(pfx, po, "/tmp/vzrG" as *u8) 184 po = rg_catn(pfx, po, sys_now_us()) 185 po = rg_cat(pfx, po, "-" as *u8) 186 pfx[po] = 0 as u8 187 188 let ch: *u8 = "CONF stale_days 30\nCONF strong_permil 500\nCHANNEL recruiter 700\nCHANNEL referral 550\nCHANNEL cold-apply 100\nAGENT recruiter r1 jane-doe compilers systems nishilang\nAGENT recruiter r2 sam-lee sales marketing\nAGENT referral f1 cousin-max writing editing\nAGENT cold-apply portal direct-application *\n" as *u8 189 rg_write("/tmp/vzr_ch.txt" as *u8, ch) 190 // same data, stale_days 60 (the ONLY change): the threshold is data, not code 191 let ch60: *u8 = "CONF stale_days 60\nCONF strong_permil 500\nCHANNEL recruiter 700\nCHANNEL referral 550\nCHANNEL cold-apply 100\nAGENT recruiter r1 jane-doe compilers systems nishilang\nAGENT recruiter r2 sam-lee sales marketing\nAGENT referral f1 cousin-max writing editing\nAGENT cold-apply portal direct-application *\n" as *u8 192 rg_write("/tmp/vzr_ch60.txt" as *u8, ch60) 193 let posts: *u8 = "POST j1 9000000 compilers rust writing\nPOST j2 12000000 nishilang compilers systems\nPOST j3 7500000 sales travel\nPOST j4 8000000 editing writing remote\nPOST j5 7000000 travel logistics\n" as *u8 194 rg_write("/tmp/vzr_posts.txt" as *u8, posts) 195 // r1 touched 06-01 then an OLDER 05-28 stored after it: latest date must win 196 let tch: *u8 = "TOUCH 2026-06-01 r1 ada coffee-chat\nTOUCH 2026-04-20 r2 ada conference-intro\nTOUCH 2026-05-28 r1 ada followup-email\n" as *u8 197 rg_write("/tmp/vzr_tch.txt" as *u8, tch) 198 199 let fch: *u8 = "/tmp/vzr_ch.txt" as *u8 200 let fpo: *u8 = "/tmp/vzr_posts.txt" as *u8 201 let flog: *u8 = "/tmp/vzr_fix.log" as *u8 202 var pass: i64 = 0 203 var r: i64 = 0 204 205 // row 1: loud-fail on missing channels 206 let rc1: i64 = rg_run(rb, "route" as *u8, "/tmp/vzr_ch_NOPE.txt" as *u8, fpo, flog, "/tmp/vzr_out1.txt" as *u8) 207 r = 0 208 if rc1 == 1 { r = 1 } 209 pass = pass + rg_row("loud-fail-missing-channels" as *u8, r) 210 211 // row 2: recruiter route with full overlap 212 let rc2: i64 = rg_run(rb, "route" as *u8, fch, fpo, flog, "/tmp/vzr_out2.txt" as *u8) 213 r = 0 214 if rc2 == 0 { 215 if rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j2 channel=recruiter via=r1 strength=700 overlap=3 state=STRONG" as *u8) == 1 { r = 1 } 216 } 217 pass = pass + rg_row("route-recruiter-strong" as *u8, r) 218 219 // row 3: referral fallback when no recruiter overlaps 220 r = rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j4 channel=referral via=f1 strength=550 overlap=2 state=STRONG" as *u8) 221 pass = pass + rg_row("route-referral-fallback" as *u8, r) 222 223 // row 4: the broken standard process NAMED per posting + verdict counts 224 r = 0 225 if rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j5 channel=cold-apply via=portal strength=100 overlap=0 state=WEAK" as *u8) == 1 { 226 if rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE-VERDICT posts=5 strong=4 weak=1 unrouted=0" as *u8) == 1 { r = 1 } 227 } 228 pass = pass + rg_row("cold-apply-weak-named" as *u8, r) 229 230 // row 5: equal overlap, higher channel weight wins (r1 over f1 on j1) 231 r = rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j1 channel=recruiter via=r1 strength=700 overlap=1 state=STRONG" as *u8) 232 pass = pass + rg_row("best-channel-wins" as *u8, r) 233 234 // row 6: route determinism 235 rg_run(rb, "route" as *u8, fch, fpo, flog, "/tmp/vzr_out6.txt" as *u8) 236 r = rg_fileeq("/tmp/vzr_out2.txt" as *u8, "/tmp/vzr_out6.txt" as *u8) 237 pass = pass + rg_row("route-determinism" as *u8, r) 238 239 // row 7: touch 3 contacts into seg-3001 240 let rc7: i64 = rg_run(rb, "touch" as *u8, "/tmp/vzr_tch.txt" as *u8, pfx, "3001" as *u8, "/tmp/vzr_out7.txt" as *u8) 241 r = 0 242 if rc7 == 0 { 243 if rg_has("/tmp/vzr_out7.txt" as *u8, "VIZSLA-RECRUIT-TOUCH scanned=3 new=3 dup_infile=0 dup_instore=0 segment=seg-3001" as *u8) == 1 { r = 1 } 244 } 245 pass = pass + rg_row("touch-load" as *u8, r) 246 247 // row 8: idempotent re-touch (law 10) 248 let rc8: i64 = rg_run(rb, "touch" as *u8, "/tmp/vzr_tch.txt" as *u8, pfx, "3009" as *u8, "/tmp/vzr_out8.txt" as *u8) 249 r = 0 250 if rc8 == 0 { 251 if rg_has("/tmp/vzr_out8.txt" as *u8, "VIZSLA-RECRUIT-TOUCH scanned=3 new=0 dup_infile=0 dup_instore=3 segment=none" as *u8) == 1 { r = 1 } 252 } 253 pass = pass + rg_row("idempotent-retouch" as *u8, r) 254 255 // row 9: keep-warm -- LATEST date wins (06-01, not the later-stored 05-28) 256 let rc9: i64 = rg_run(rb, "warm" as *u8, pfx, fch, "2026-06-10" as *u8, "/tmp/vzr_out9.txt" as *u8) 257 r = 0 258 if rc9 == 0 { 259 if rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=r1 channel=recruiter last=2026-06-01 days=9 state=FRESH action=none" as *u8) == 1 { r = 1 } 260 } 261 pass = pass + rg_row("latest-date-wins" as *u8, r) 262 263 // row 10: hand-counted 51 days => STALE reconnect 264 r = rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=r2 channel=recruiter last=2026-04-20 days=51 state=STALE action=reconnect" as *u8) 265 pass = pass + rg_row("stale-reconnect" as *u8, r) 266 267 // row 11: never-touched referral COLD; weak-channel portal EXCLUDED by data 268 r = 0 269 if rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=f1 channel=referral last=never days=-1 state=COLD action=introduce" as *u8) == 1 { 270 if rg_has("/tmp/vzr_out9.txt" as *u8, "agent=portal" as *u8) == 0 { 271 if rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM-VERDICT agents=3 fresh=1 stale=1 cold=1" as *u8) == 1 { r = 1 } 272 } 273 } 274 pass = pass + rg_row("cold-introduce-weak-excluded" as *u8, r) 275 276 // row 12: DATA-DRIVEN threshold -- stale_days=60 file flips r2 to FRESH, same binary 277 let rc12: i64 = rg_run(rb, "warm" as *u8, pfx, "/tmp/vzr_ch60.txt" as *u8, "2026-06-10" as *u8, "/tmp/vzr_out12.txt" as *u8) 278 r = 0 279 if rc12 == 0 { 280 if rg_has("/tmp/vzr_out12.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=r2 channel=recruiter last=2026-04-20 days=51 state=FRESH action=none" as *u8) == 1 { 281 if rg_has("/tmp/vzr_out12.txt" as *u8, "VIZSLA-RECRUIT-WARM-VERDICT agents=3 fresh=2 stale=0 cold=1" as *u8) == 1 { r = 1 } 282 } 283 } 284 pass = pass + rg_row("data-driven-stale-threshold" as *u8, r) 285 286 // row 13: warm determinism 287 rg_run(rb, "warm" as *u8, pfx, fch, "2026-06-10" as *u8, "/tmp/vzr_out13.txt" as *u8) 288 r = rg_fileeq("/tmp/vzr_out9.txt" as *u8, "/tmp/vzr_out13.txt" as *u8) 289 pass = pass + rg_row("warm-determinism" as *u8, r) 290 291 let permil: i64 = (pass * 1000) / 13 292 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 293 var fdi: i64 = 0 294 while fdi < 2 { 295 var fd: i64 = 1 296 if fdi == 1 { fd = logfd } 297 if fd > 0 { 298 let line: *u8 = sys_mmap(256) 299 var o: i64 = 0 300 o = rg_cat(line, o, "VIZSLA-RECRUIT-GATE epoch=" as *u8) 301 o = rg_catn(line, o, sys_now_realtime_sec()) 302 o = rg_cat(line, o, " rows=13 pass=" as *u8) 303 o = rg_catn(line, o, pass) 304 o = rg_cat(line, o, " permil=" as *u8) 305 o = rg_catn(line, o, permil) 306 if pass == 13 { 307 o = rg_cat(line, o, " verdict=GREEN\n" as *u8) 308 } else { 309 o = rg_cat(line, o, " verdict=RED\n" as *u8) 310 } 311 sys_write(fd, line, o) 312 } 313 fdi = fdi + 1 314 } 315 if logfd > 0 { sys_close(logfd) } 316 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 317 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 318 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 319 let ctr__dry: *i64 = gv_ctr() 320 ctr__dry[0] = pass 321 ctr__dry[1] = 13 322 let rc__dry: i64 = gv_verdict("VIZSLA-RECRUITER-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 323 sys_exit(rc__dry) 324 return rc__dry 325}