code wiki / (root) / nx_medrec_gate.nx

nx_medrec_gate.nx source

↩ module page · 136 lines · 9189 B

1// nx_medrec_gate.nx -- GREEN/RED gate for the media-recovery admission core. 2// EVERY fixture row below is a VERBATIM CDX row pulled LIVE from web.archive.org on 2026-08-06 -- 3// nothing here is invented or hand-shaped (Rule 4, and the estate law: a ruler from a REAL corpus). 4// Inherits nx_gate_verdict (D001) so nx_gate_green can judge this from outside and flake stays visible. 5// Composes nx_medrec + nx_cdx_parse. Deterministic, no network. license_tier: ORIGINAL 6import "nx_medrec.nx" 7import "nx_gate_verdict.nx" 8 9func ap(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { buf[off+i]=s[i]; i=i+1 } return off+i } 10func apnl(buf: *u8, off: i64) -> i64 { buf[off]=0x0a as u8; return off+1 } 11func eqi(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 } 12func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13func andi(a: i64, b: i64) -> i64 { if a == 1 { if b == 1 { return 1 } } return 0 } 14 15func main() -> i64 { 16 let ctr: *i64 = gv_ctr() 17 gv_head("nx_medrec_gate -- tombstone-vs-media admission, on LIVE-PULLED Wayback CDX rows" as *u8) 18 let o2: *i64 = sys_mmap(64) as *i64 19 let FLOOR: i64 = 2048 20 21 // FIXTURE A: the i.imgur.com "image not found" placeholder. 5 captures 2013->2026, ONE digest, 22 // 335..827 B. This is the set that magic-byte validation cannot reject. 23 let TB: *u8 = sys_mmap(8192) 24 var o: i64 = 0 25 o=ap(TB,o,"com,imgur,i)/00000.jpeg 20260617140532 https://i.imgur.com/00000.jpeg image/jpeg 200 VXEDWGPHSNERWHDOUD6YWRWNT4ZOLEX4 827" as *u8); o=apnl(TB,o) 26 o=ap(TB,o,"com,imgur,i)/00000.jpg 20130420012445 http://i.imgur.com/00000.jpg image/jpeg 200 VXEDWGPHSNERWHDOUD6YWRWNT4ZOLEX4 335" as *u8); o=apnl(TB,o) 27 o=ap(TB,o,"com,imgur,i)/00000.jpg 20201112014645 https://i.imgur.com/00000.jpg image/jpeg 200 VXEDWGPHSNERWHDOUD6YWRWNT4ZOLEX4 339" as *u8); o=apnl(TB,o) 28 o=ap(TB,o,"com,imgur,i)/00000.jpg 20210125175731 https://i.imgur.com/00000.jpg image/jpeg 200 VXEDWGPHSNERWHDOUD6YWRWNT4ZOLEX4 457" as *u8); o=apnl(TB,o) 29 o=ap(TB,o,"com,imgur,i)/00000.jpg 20230509174153 https://i.imgur.com/00000.jpg image/jpeg 200 VXEDWGPHSNERWHDOUD6YWRWNT4ZOLEX4 789" as *u8); o=apnl(TB,o) 30 let tbn: i64 = o 31 let TRS: *i64 = sys_mmap(64*8) as *i64 32 let TRE: *i64 = sys_mmap(64*8) as *i64 33 let tbrows: i64 = cdx_rows(TB, tbn, TRS, TRE, 64) 34 35 // FIXTURE B: a REAL 1 MB image from the SAME host, 3 captures 2023+2025. 36 let RB: *u8 = sys_mmap(8192) 37 o = 0 38 o=ap(RB,o,"com,imgur,i)/ot6muiy.jpg 20230509025649 https://i.imgur.com/OT6mUiy.jpg image/jpeg 200 6PYVXUDUV5WT3VSTAK33KZYTSI4BA56Z 1090473" as *u8); o=apnl(RB,o) 39 o=ap(RB,o,"com,imgur,i)/ot6muiy.jpg 20250815150548 https://i.imgur.com/OT6mUiy.jpg image/jpeg 200 6PYVXUDUV5WT3VSTAK33KZYTSI4BA56Z 1083440" as *u8); o=apnl(RB,o) 40 o=ap(RB,o,"com,imgur,i)/ot6muiy.jpg 20250815230643 https://i.imgur.com/OT6mUiy.jpg image/jpeg 200 6PYVXUDUV5WT3VSTAK33KZYTSI4BA56Z 1083439" as *u8); o=apnl(RB,o) 41 let rbn: i64 = o 42 let RRS: *i64 = sys_mmap(64*8) as *i64 43 let RRE: *i64 = sys_mmap(64*8) as *i64 44 let rbrows: i64 = cdx_rows(RB, rbn, RRS, RRE, 64) 45 46 // FIXTURE C: mixed real rows -- a page3.com media jpeg, a reddit 301 carrying the empty-payload 47 // SHA1, and an i.redd.it warc/revisit row whose STATUSCODE column is literally "-". 48 let MB: *u8 = sys_mmap(8192) 49 o = 0 50 o=ap(MB,o,"com,page3)/3zine_pages/html_preview/01/03.jpg 20060429031625 http://www.page3.com:80/3zine_pages/html_preview/01/03.jpg image/jpeg 200 SCEQ2MZIA5GWHZQ25LJMZRQUAVBQTM5T 40763" as *u8); o=apnl(MB,o) 51 o=ap(MB,o,"com,reddit)/user/spez 20051210161042 http://reddit.com:80/user/spez text/html 301 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ 294" as *u8); o=apnl(MB,o) 52 o=ap(MB,o,"it,redd,i)/ 20160616062812 http://i.redd.it/ warc/revisit - 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ 448" as *u8); o=apnl(MB,o) 53 let mbn: i64 = o 54 let MRS: *i64 = sys_mmap(64*8) as *i64 55 let MRE: *i64 = sys_mmap(64*8) as *i64 56 let mbrows: i64 = cdx_rows(MB, mbn, MRS, MRE, 64) 57 58 gv_puts(" fixtures parsed: tombstone-set=" as *u8); gv_num(tbrows) 59 gv_puts(" real-set=" as *u8); gv_num(rbrows) 60 gv_puts(" mixed-set=" as *u8); gv_num(mbrows); gv_puts("\n" as *u8) 61 let t0: i64 = andi(andi(eqi(tbrows,5), eqi(rbrows,3)), eqi(mbrows,3)) 62 gv_check("T0 all three live fixture sets parsed (5/3/3)" as *u8, t0, ctr) 63 64 // T1 -- the placeholder is REJECTED by identity, though it is a valid 200 image/jpeg. 65 let a1: i64 = mr_row_admit(TB, TRS[0], TRE[0], FLOOR, o2) 66 gv_check("T1 imgur placeholder (200, valid jpeg) -> REJ_TOMBSTONE" as *u8, eqi(a1, MR_REJ_TOMBSTONE), ctr) 67 68 // T2 -- the real 1 MB image is ADMITTED. 69 let a2: i64 = mr_row_admit(RB, RRS[0], RRE[0], FLOOR, o2) 70 gv_check("T2 real 1,090,473 B imgur image -> ADMIT" as *u8, eqi(a2, MR_ADMIT), ctr) 71 72 // T3 -- a 301 redirect row is rejected on STATUS before anything else. 73 let a3: i64 = mr_row_admit(MB, MRS[1], MRE[1], FLOOR, o2) 74 gv_check("T3 reddit 301 redirect row -> REJ_STATUS" as *u8, eqi(a3, MR_REJ_STATUS), ctr) 75 76 // T4 -- FAIL-CLOSED: a warc/revisit row with statuscode "-" is UNKNOWN, never admitted. 77 let a4: i64 = mr_row_admit(MB, MRS[2], MRE[2], FLOOR, o2) 78 gv_check("T4 warc/revisit statuscode '-' -> UNKNOWN (fail-closed)" as *u8, eqi(a4, MR_UNKNOWN), ctr) 79 80 // T5 -- best-pick takes the LARGEST admitted capture, not the earliest. 81 let a5: i64 = mr_pick_best(RB, RRS, RRE, rbrows, FLOOR, o2) 82 gv_check("T5 pick_best on real set -> row 0 (largest 1090473, not earliest)" as *u8, eqi(a5, 0), ctr) 83 84 // T6/T7 -- BITE CELL. The detector must FIRE on the placeholder set and stay SILENT on the real one. 85 // The real set ALSO collapses to a single digest across its 3 captures, so a detector keyed on 86 // digest-collapse alone would fire on both and be VACUOUS. This cell makes that visible. 87 let bad: i64 = mr_rowset_is_tombstone(TB, TRS, TRE, tbrows, FLOOR, o2) 88 let good: i64 = mr_rowset_is_tombstone(RB, RRS, RRE, rbrows, FLOOR, o2) 89 gv_bite("T6/T7 rowset tombstone detector" as *u8, bad, good, ctr) 90 91 // T8 -- nothing in the placeholder set is admissible, so best-pick must find nothing. 92 let a8: i64 = mr_pick_best(TB, TRS, TRE, tbrows, FLOOR, o2) 93 gv_check("T8 pick_best on placeholder set -> UNKNOWN (no admissible capture)" as *u8, eqi(a8, MR_UNKNOWN), ctr) 94 95 // T9 -- the page3.com media row admits, and the SAME row rejects under a floor above its size, 96 // proving the threshold is the CALLER's and not baked in (Rule 11). 97 let a9a: i64 = mr_row_admit(MB, MRS[0], MRE[0], FLOOR, o2) 98 let a9b: i64 = mr_row_admit(MB, MRS[0], MRE[0], 100000, o2) 99 gv_check("T9 page3.com 40763 B jpeg: ADMIT at floor 2048, REJ_TOOSMALL at 100000" as *u8, 100 andi(eqi(a9a, MR_ADMIT), eqi(a9b, MR_REJ_TOOSMALL)), ctr) 101 102 // T10 -- url kinds over the REAL 2016 r/pics url mix (8 of 12 were PAGE urls, not images). 103 let k1: i64 = mr_url_kind("http://i.imgur.com/OT6mUiy.jpg" as *u8) 104 let k2: i64 = mr_url_kind("http://imgur.com/uMsbUmj" as *u8) 105 let k3: i64 = mr_url_kind("http://imgur.com/gallery/9x6tHq0/new" as *u8) 106 let k4: i64 = mr_url_kind("https://i.redd.it/mup6rvwj0o7h1.png" as *u8) 107 let t10: i64 = andi(andi(eqi(k1,MR_URL_DIRECT), eqi(k2,MR_URL_PAGE)), andi(eqi(k3,MR_URL_GALLERY), eqi(k4,MR_URL_DIRECT))) 108 gv_check("T10 url_kind: i.imgur=DIRECT imgur/<id>=PAGE gallery=GALLERY i.redd.it=DIRECT" as *u8, t10, ctr) 109 110 // T11 -- a single capture is not a pattern; must not be called a tombstone. 111 let a11: i64 = mr_rowset_is_tombstone(TB, TRS, TRE, 1, FLOOR, o2) 112 gv_check("T11 single capture -> 0 (one save is not a pattern)" as *u8, eqi(a11, 0), ctr) 113 114 // T12/T13 -- THE URL->MEDIA JOIN KEY, the property the whole byurl reverse index rests on. 115 // The CDX 'original' column and a page's own <img src> MUST produce the same key or the renderer 116 // finds nothing and it reads as missing media rather than a bad hash. Real page3.com forms: 117 let uA: *u8 = "http://www.page3.com:80/3zine_pages/html_preview/01/03.jpg" as *u8 118 let uB: *u8 = "/3zine_pages/html_preview/01/03.jpg" as *u8 119 let uC: *u8 = "http://page3.com/3zine_pages/html_preview/01/03.jpg?v=2" as *u8 120 let uD: *u8 = "/3zine_pages/html_preview/01/04.jpg" as *u8 121 let hA: i64 = mr_canon_hash(uA, 0, slen(uA)) 122 let hB: i64 = mr_canon_hash(uB, 0, slen(uB)) 123 let hC: i64 = mr_canon_hash(uC, 0, slen(uC)) 124 let hD: i64 = mr_canon_hash(uD, 0, slen(uD)) 125 gv_check("T12 www.host:80 absolute == bare-host absolute with query (port/www/query folded)" as *u8, 126 eqi(hA, hC), ctr) 127 // BITE CELL: the key must MATCH the same path via a different url form, and must NOT match a 128 // different path. A hash returning a constant would satisfy the first half alone -- this is what 129 // makes the join provable rather than merely asserted. 130 gv_bite("T13 join key: absolute-vs-relative same path matches, 03.jpg vs 04.jpg does not" as *u8, 131 eqi(hA, hB), eqi(hA, hD), ctr) 132 133 let rc: i64 = gv_verdict("MEDREC" as *u8, ctr, "tombstones rejected from the INDEX, zero bytes fetched" as *u8) 134 sys_exit(rc) 135 return rc 136}