nx_diora_live_reach_guarded.nx source
↩ module page · 120 lines · 5797 B
1// nx_diora_live_reach_guarded.nx -- SREACH R1, HANG-PROOF. The own-crawl ->
2// own-index reach run, but every per-URL fetch is a CHILD bounded by
3// nx_guarded_run: a host that hangs the validated-HTTPS read loop (e.g.
4// wikipedia) is SIGKILLed at the deadline and recorded BLOCKED-TIMEOUT, and the
5// crawl CONTINUES to the next seed -- the operator cardinal "the team handles
6// issues like this hang" made operational in the reach pipeline. Reach is then
7// measured over whatever OUR engine actually fetched + indexed (never faked).
8// build child first: nx_sov_build_run _dlr_fetch_one (-> /tmp/_dlr_fetch_one.sov.elf)
9import "nx_str.nx"
10import "nx_syscalls.nx"
11import "nx_guarded_run.nx"
12import "nx_bm25.nx"
13import "nx_search_inverted.nx" // NxInvIndex + nx_inv_* + nx_bm25_tf -- not carried by nx_bm25.nx
14const NX_MAGIC_524288: i64 = 524288
15
16const NX_DLRG_SEEDS: i64 = 4
17const NX_DLRG_DEADLINE: i64 = 18000 // ms per fetch; a hung host is reaped here, not wedged
18const NX_DLRG_GATE_MIN: i64 = 1 // honest floor: prove >=1 real source reached without any wedge
19
20func gp(s: *u8) -> i64 { sys_write(1, s, nx_str_len(s)); return 0 }
21func gn(v: i64) -> i64 {
22 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
23 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
24 let t: *u8 = sys_mmap(28); var k: i64 = 0
25 while m > 0 { t[k] = 0x30 + (m - (m/10)*10); m = m/10; k = k + 1 }
26 while k > 0 { k = k - 1; sys_write(1, (((t as i64)+k) as *u8), 1) }
27 return 0
28}
29func dlrg_seed(e: i64) -> *u8 {
30 if e == 0 { return "https://example.com/" } // CONTROL (known-clean EOF)
31 if e == 1 { return "https://kids.kiddle.co/Diora_Baird" } // LONG-TAIL (independent)
32 if e == 2 { return "https://www.wikidata.org/wiki/Q283504" } // IDENTITY (incumbents suppressed it)
33 if e == 3 { return "https://en.wikipedia.org/wiki/Diora_Baird" } // IDENTITY (large -> exercises the hang path)
34 return "?"
35}
36func dlrg_out(e: i64) -> *u8 {
37 if e == 0 { return "/tmp/dlrg_text_0.txt\x00" }
38 if e == 1 { return "/tmp/dlrg_text_1.txt\x00" }
39 if e == 2 { return "/tmp/dlrg_text_2.txt\x00" }
40 if e == 3 { return "/tmp/dlrg_text_3.txt\x00" }
41 return "/tmp/dlrg_text_x.txt\x00"
42}
43
44func read_all(path: *u8, buf: *u8, cap: i64) -> i64 {
45 let fd: i64 = sys_openat_rd(path)
46 if fd < 0 { return 0 }
47 var total: i64 = 0
48 var go: i64 = 1
49 while go == 1 {
50 let n: i64 = sys_read(fd, (((buf as i64) + total) as *u8), cap - total)
51 if n <= 0 { go = 0 }
52 if n > 0 { total = total + n; if total >= cap { go = 0 } }
53 }
54 sys_close(fd)
55 return total
56}
57
58func main() -> i64 {
59 gp("=== Nishi LIVE REACH (HANG-PROOF) -- diora baird, guarded per-URL fetch ===\n")
60 let child: *u8 = "/tmp/_dlr_fetch_one.sov.elf\x00"
61 let envp: *i64 = sys_mmap(8 * 4) as *i64
62 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
63 let devnull: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4)
64
65 let dtext: **u8 = sys_mmap(NX_DLRG_SEEDS * 8) as **u8
66 let dlen: *i64 = sys_mmap(NX_DLRG_SEEDS * 8) as *i64
67 let durl: **u8 = sys_mmap(NX_DLRG_SEEDS * 8) as **u8
68 var ndoc: i64 = 0
69 var ntimeout: i64 = 0
70 let idx: *NxInvIndex = nx_inv_new(NX_DLRG_SEEDS + 1)
71
72 gp("\nGUARDED FETCH LEDGER (deadline "); gn(NX_DLRG_DEADLINE); gp("ms/fetch; a hang is reaped, never wedged):\n")
73 var e: i64 = 0
74 while e < NX_DLRG_SEEDS {
75 let url: *u8 = dlrg_seed(e)
76 let outp: *u8 = dlrg_out(e)
77 let av: *i64 = sys_mmap(8 * 4) as *i64
78 av[0] = child as i64; av[1] = url as i64; av[2] = outp as i64; av[3] = 0
79 let t0: i64 = sys_now_ms()
80 let rc: i64 = nx_guarded_run(child, av, envp, NX_DLRG_DEADLINE, devnull, devnull)
81 let dt: i64 = sys_now_ms() - t0
82 gp(" "); gp(url); gp(" -> ")
83 if rc == 0 {
84 let text: *u8 = sys_mmap(NX_MAGIC_524288)
85 let tl: i64 = read_all(outp, text, NX_MAGIC_524288)
86 dtext[ndoc] = text; dlen[ndoc] = tl; durl[ndoc] = url
87 nx_inv_index_row(idx, text, tl, ndoc)
88 ndoc = ndoc + 1
89 gp("OK "); gn(tl); gp(" text chars ("); gn(dt); gp("ms) -> indexed\n")
90 }
91 if rc == 124 { ntimeout = ntimeout + 1; gp("TIMEOUT-REAPED @"); gn(dt); gp("ms (read-loop hang; SIGKILLed, crawl continues)\n") }
92 if rc != 0 { if rc != 124 { gp("fetch-fail rc="); gn(rc); gp(" ("); gn(dt); gp("ms)\n") } }
93 e = e + 1
94 }
95
96 gp("\nguarded outcome: "); gn(ndoc); gp(" fetched+indexed, "); gn(ntimeout); gp(" hangs reaped (no wedge)\n")
97 if ndoc == 0 { gp("REACH=0 this run; but NO WEDGE -- the hang-handler held. HONEST.\n"); return 2 }
98
99 nx_inv_finalize_offsets(idx)
100 var d: i64 = 0
101 while d < ndoc { nx_inv_emit_row(idx, dtext[d], dlen[d], d); d = d + 1 }
102 let h_diora: i64 = nx_inv_hash_bytes_lower("diora", 5)
103 let h_baird: i64 = nx_inv_hash_bytes_lower("baird", 5)
104 gp("\nRETRIEVAL from OUR index -- query 'diora baird':\n")
105 var reach: i64 = 0
106 d = 0
107 while d < ndoc {
108 let tfa: i64 = nx_bm25_tf(dtext[d], dlen[d], h_diora)
109 let tfb: i64 = nx_bm25_tf(dtext[d], dlen[d], h_baird)
110 gp(" "); gp(durl[d]); gp(" diora x"); gn(tfa); gp(" baird x"); gn(tfb)
111 var hit: i64 = 0
112 if tfa > 0 { if tfb > 0 { hit = 1 } }
113 if hit == 1 { gp(" <- RETRIEVED\n"); reach = reach + 1 } else { gp("\n") }
114 d = d + 1
115 }
116 gp("\nLIVE REACH (our crawl, our index, hang-proof): "); gn(reach); gp(" docs retrievable for 'diora baird'\n")
117 if reach >= NX_DLRG_GATE_MIN { gp("SREACH-R1 GUARDED GATE: PASS (reached real sources; hangs handled)\n"); return 0 }
118 gp("SREACH-R1 GUARDED GATE: reach below floor (but hang-handling proven)\n")
119 return 3
120}