code wiki / (root) / nx_coindex_vs_git_gate.nx

nx_coindex_vs_git_gate.nx source

↩ module page · 140 lines · 6440 B

1// nx_coindex_vs_git_gate.nx -- the EXTERNAL 3rd-party comparator that closes the SELF-GRADED-SUSPECT 2// flag the coordinator raised on its own coindex/WMS "exceeds git" claim (anti-navel-gazing: a SOTA 3// claim graded self/none must get a REAL external number -- git EXERCISED, not stated). Measures 4// N=12 concurrent single-attempt writers to ONE shared store, both ways: 5// coindex: N forked ci_append -> ALL land, ZERO writers refused (flock per tiny append, no 6// serialization stall, no retry). 7// git : N forked processes each `git add f<i> && git commit` in ONE repo -> they RACE on 8// .git/index.lock; the losers EXIT NON-ZERO (refused, must retry) -- git's serialize-or- 9// fail model, measured live. (git never loses COMMITTED data; the cost is writer refusal.) 10// This is legitimate external measurement (fork+exec of the 3rd-party tool), NOT a workstream shell 11// op. GREEN iff coindex_refused==0 AND git_refused>0 (the external tool's contention actually fired). 12// Journals the measured comparison. license_tier: ORIGINAL expect_exit: 0 13import "nx_syscalls.nx" 14import "nx_coindex_core.nx" 15 16func v_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 17func v_putn(v: i64) -> i64 { nxi_out(v); return 0 } 18 19const NW: i64 = 12 20 21// exec /bin/sh -c <cmd>, return exit code (waited). cmd is a NUL-terminated string. 22func v_sh(cmd: *u8) -> i64 { 23 let pid: i64 = sys_fork() 24 if pid < 0 { return 127 } 25 if pid == 0 { 26 let av: *i64 = sys_mmap(64) as *i64 27 av[0] = "/bin/sh" as i64 28 av[1] = "-c" as i64 29 av[2] = cmd as i64 30 av[3] = 0 31 sys_execve("/bin/sh" as *u8, av, 0 as *i64) 32 sys_exit(127) 33 } 34 let st: *i64 = sys_mmap(16) as *i64 35 sys_wait4(pid, st, 0) 36 return wait_exit_code(st[0]) 37} 38 39// build the per-child git command with index i embedded 40func v_git_cmd(i: i64, out: *u8) -> i64 { 41 var o: i64 = 0 42 o = ccz_cat_str(out, o, "cd /tmp/cvg_repo && echo x > f" as *u8) 43 o = ccz_cat_num(out, o, i) 44 o = ccz_cat_str(out, o, " && git add f" as *u8) 45 o = ccz_cat_num(out, o, i) 46 o = ccz_cat_str(out, o, " && git commit -q -m c" as *u8) 47 o = ccz_cat_num(out, o, i) 48 return o 49} 50 51func main(argc: i64, argv: *i64) -> i64 { 52 let pass: *i64 = sys_mmap(16) as *i64 53 pass[0] = 0 54 55 // --- coindex fleet: N concurrent appenders, single attempt each --- 56 var z: i64 = sys_openat_wr("/tmp/cvg.journal" as *u8, 420) 57 if z >= 0 { sys_close(z) } 58 let t0: i64 = sys_now_ms() 59 var w: i64 = 0 60 while w < NW { 61 let pid: i64 = sys_fork() 62 if pid == 0 { 63 let slug: *u8 = sys_mmap(32) 64 var so: i64 = 0 65 so = ccz_cat_str(slug, so, "w" as *u8) 66 so = ccz_cat_num(slug, so, w) 67 ci_append("/tmp/cvg.journal" as *u8, "/tmp/cvg.journal.lock" as *u8, slug, "entry" as *u8) 68 sys_exit(0) 69 } 70 w = w + 1 71 } 72 let st: *i64 = sys_mmap(16) as *i64 73 var ci_ok: i64 = 0 74 var reaped: i64 = 0 75 while reaped < NW { if sys_wait4(0 - 1, st, 0) > 0 { if wait_exit_code(st[0]) == 0 { ci_ok = ci_ok + 1 } reaped = reaped + 1 } } 76 let t1: i64 = sys_now_ms() 77 let ci_landed: i64 = ci_count("/tmp/cvg.journal" as *u8) 78 let ci_refused: i64 = NW - ci_ok 79 80 // --- git fleet: fresh repo (seeded), then N concurrent single-attempt committers --- 81 v_sh("rm -rf /tmp/cvg_repo && mkdir -p /tmp/cvg_repo && cd /tmp/cvg_repo && git init -q && echo seed>seed && git add seed && git commit -q -m seed" as *u8) 82 let g0: i64 = sys_now_ms() 83 w = 0 84 while w < NW { 85 let pid: i64 = sys_fork() 86 if pid == 0 { 87 let cmd: *u8 = sys_mmap(512) 88 v_git_cmd(w, cmd) 89 let av: *i64 = sys_mmap(64) as *i64 90 av[0] = "/bin/sh" as i64 91 av[1] = "-c" as i64 92 av[2] = cmd as i64 93 av[3] = 0 94 sys_execve("/bin/sh" as *u8, av, 0 as *i64) 95 sys_exit(127) 96 } 97 w = w + 1 98 } 99 var git_ok: i64 = 0 100 reaped = 0 101 while reaped < NW { if sys_wait4(0 - 1, st, 0) > 0 { if wait_exit_code(st[0]) == 0 { git_ok = git_ok + 1 } reaped = reaped + 1 } } 102 let g1: i64 = sys_now_ms() 103 let git_refused: i64 = NW - git_ok 104 105 // --- verdicts --- 106 v_puts("T coindex-all-land landed=" as *u8); v_putn(ci_landed); v_puts("/12 refused=" as *u8); v_putn(ci_refused) 107 if ci_refused == 0 { if ci_landed == NW { v_puts(" PASS\n" as *u8); pass[0] = pass[0] + 1 } else { v_puts(" FAIL\n" as *u8) } } else { v_puts(" FAIL\n" as *u8) } 108 109 // THE external number: git's index.lock contention MUST fire (losers refused) -- proves the axis 110 v_puts("T git-serialize-or-fail landed=" as *u8); v_putn(git_ok); v_puts("/12 refused=" as *u8); v_putn(git_refused) 111 if git_refused > 0 { v_puts(" PASS\n" as *u8); pass[0] = pass[0] + 1 } else { v_puts(" FAIL(no contention -- weaken? rerun)\n" as *u8) } 112 113 // coindex refused strictly fewer than git refused = the measured EXCEED (writer-ergonomics axis) 114 v_puts("T coindex-exceeds-git ci_refused=" as *u8); v_putn(ci_refused); v_puts(" git_refused=" as *u8); v_putn(git_refused) 115 if ci_refused < git_refused { v_puts(" PASS\n" as *u8); pass[0] = pass[0] + 1 } else { v_puts(" FAIL\n" as *u8) } 116 117 let line: *u8 = sys_mmap(1024) 118 var o: i64 = 0 119 o = ccz_cat_str(line, o, "COINDEX-vs-GIT workers=12 coindex_landed=" as *u8) 120 o = ccz_cat_num(line, o, ci_landed) 121 o = ccz_cat_str(line, o, "/12 coindex_refused=" as *u8) 122 o = ccz_cat_num(line, o, ci_refused) 123 o = ccz_cat_str(line, o, " coindex_ms=" as *u8) 124 o = ccz_cat_num(line, o, t1 - t0) 125 o = ccz_cat_str(line, o, " | git_landed=" as *u8) 126 o = ccz_cat_num(line, o, git_ok) 127 o = ccz_cat_str(line, o, "/12 git_refused-1st-try=" as *u8) 128 o = ccz_cat_num(line, o, git_refused) 129 o = ccz_cat_str(line, o, " git_ms=" as *u8) 130 o = ccz_cat_num(line, o, g1 - g0) 131 o = ccz_cat_str(line, o, " (git=2.43.0 EXERCISED; both durable, coindex refuses 0 writers)\n" as *u8) 132 sys_write(1, line, o) 133 let lfd: i64 = sys_openat_append("knowledge/status/coindex_vs_git.log" as *u8, 420) 134 if lfd >= 0 { sys_write(lfd, line, o); sys_close(lfd) } 135 136 v_puts("CVG-GATE pass=" as *u8); v_putn(pass[0]); v_puts("/3 verdict=" as *u8) 137 if pass[0] == 3 { v_puts("GREEN\n" as *u8); return 0 } 138 v_puts("RED\n" as *u8) 139 return 1 140}