code wiki / (root) / nx_swebench_local_gate.nx

nx_swebench_local_gate.nx source

↩ module page · 103 lines · 6416 B

1// nx_swebench_local_gate.nx -- grade our autonomous fix loop by SWE-BENCH'S OWN CONTRACT (operator 2// 2026-07-16), NOW PUBLISHING THROUGH THE RIGOR ENVELOPE (autodev AD1, 2026-08-27). 3// SWE-bench = 2,294 real GitHub-issue problems (500 human-verified) across real Python repos. The 4// contract: an instance is RESOLVED iff, after the patch, FAIL_TO_PASS tests pass AND PASS_TO_PASS 5// tests still pass. The test suite is the only judge. Our nx_autofix_auto loop already IS this 6// contract sovereignly: a candidate's per-function grader rows are FAIL_TO_PASS (the located failing 7// function) + PASS_TO_PASS (every other function). HONEST SCOPE: a sovereign NishiLang ANALOG under 8// SWE-bench's contract and metric over OUR foreign-bug set -- NOT a run of SWE-bench's Python instances. 9// 10// WHAT CHANGED (2026-08-27): the D001 migration that shipped here set ctr[1] = the EPISODE COUNT of the 11// newest batch, so wherever the ledger existed this gate printed "passed 4/14 verdict=RED" -- FOUR of 12// its own teeth against FOURTEEN episodes, a denominator mismatch that read RED on a healthy loop. 13// ★A GATE'S PASS/TOTAL IS ITS TOOTH COUNT, NEVER ITS SUBJECT'S POPULATION. It is now per-tooth gv_check, 14// and the resolve rate is published as a gv_envelope STRUCT (k, n, Wilson + hierarchical bootstrap, 15// seed, harness) rather than a bare percentage -- the same ruler /compare/autograde and /compare/gen 16// now share. SKIP when the ledger is unreachable (a host without the fix-loop stage is not a failure). 17// expect_exit: 0 license_tier: ORIGINAL 18import "nx_syscalls.nx" 19import "nx_gate_verdict.nx" 20import "nx_stage_path.nx" 21import "nx_autofix_lib.nx" 22 23const SWBL_ENV_BYTES: i64 = 128 24const SWBL_HARNESS: i64 = 128 25 26func swb_resolved(f2p_now: i64, f2p_total: i64, p2p_now: i64, p2p_total: i64) -> i64 { 27 if f2p_now != f2p_total { return 0 } 28 if p2p_now != p2p_total { return 0 } 29 return 1 30} 31 32func main() -> i64 { 33 let ctr: *i64 = gv_ctr() 34 gv_head("nx_swebench_local_gate -- our fix loop graded by SWE-bench's cheat-proof contract, the living resolve rate published as a rigor envelope (n, Wilson interval, hierarchical bootstrap, seed, harness)" as *u8) 35 36 // ---- T1/T2: the contract itself, pure and gate-testable ---- 37 gv_check("T1 CONTRACT resolves a clean fix (FAIL_TO_PASS 1/1 + PASS_TO_PASS 2/2)" as *u8, swb_resolved(1, 1, 2, 2), ctr) 38 var reg: i64 = 0 39 if swb_resolved(1, 1, 1, 2) == 0 { reg = 1 } 40 gv_check("T2 neg-control-regressive-fix-not-resolved: target passes but a PASS_TO_PASS test broke -> NOT resolved (the anti-regression discipline)" as *u8, reg, ctr) 41 42 // ---- precondition: the fix-loop ledger must be reachable (estate journal or the dev-box stage) ---- 43 let ledp: *u8 = sys_mmap(SP_PATH_MAX) 44 let rung: i64 = afl_ledger_read_path(ledp) 45 gv_need("the fix-loop episode ledger (knowledge/status/autofix_ledger.jrnl or the nx_stage autofix_ledger.log)" as *u8, rung, ctr) 46 47 if rung > 0 { 48 gv_puts(" ledger (rung " as *u8); gv_num(rung); gv_puts("): " as *u8); gv_puts(ledp); gv_puts("\n" as *u8) 49 let lb: *i64 = sys_mmap(8) as *i64 50 let buf: *u8 = sys_read_file(ledp, lb) 51 let bst: *i64 = sys_mmap(32) as *i64 52 let ck: *i64 = sys_mmap(AFL_CLUSTER_MAX * 8) as *i64 53 let cn: *i64 = sys_mmap(AFL_CLUSTER_MAX * 8) as *i64 54 let names: *u8 = sys_mmap(AFL_CLUSTER_MAX * AFL_NAME) 55 let harness: *u8 = sys_mmap(SWBL_HARNESS) 56 var nc: i64 = 0 57 if (buf as i64) != 0 { nc = afl_batch_stats(buf, lb[0], bst, ck, cn, names, harness) } 58 let resolved: i64 = bst[2] 59 let total: i64 = bst[1] 60 61 // T3 the newest batch has a real population and its clusters SUM to (resolved, total) 62 var sk: i64 = 0 63 var sn: i64 = 0 64 var c: i64 = 0 65 while c < nc { sk = sk + ck[c]; sn = sn + cn[c]; c = c + 1 } 66 var t3: i64 = 0 67 if total > 0 { if sk == resolved { if sn == total { t3 = 1 } } } 68 gv_puts(" newest batch ts=" as *u8); gv_num(bst[0]); gv_puts(" resolved=" as *u8); gv_num(resolved); gv_puts("/" as *u8); gv_num(total); gv_puts(" clusters=" as *u8); gv_num(nc); gv_puts(" (sum_k=" as *u8); gv_num(sk); gv_puts(" sum_n=" as *u8); gv_num(sn); gv_puts(")\n" as *u8) 69 gv_check("T3 the newest batch carries a real population and its per-located-function clusters partition the resolve count" as *u8, t3, ctr) 70 71 // T4 THE RESOLVE RATE AS A RIGOR ENVELOPE (the AD1 contract): k of n with a Wilson interval 72 // widened by a hierarchical bootstrap over the located-function clusters, its parameters from 73 // knowledge/rigor.conf. A page that reads this envelope cannot print a bare percentage. 74 let rp: *i64 = sys_mmap(32) as *i64 75 sp_rigor_params(rp) 76 let env: *i64 = sys_mmap(SWBL_ENV_BYTES) as *i64 77 var envrc: i64 = 0 78 if total > 0 { envrc = gv_envelope(resolved, total, ck, cn, nc, rp[0], rp[1], rp[2], rp[3], env) } 79 gv_envelope_print("SWEBENCH-LOCAL resolve-rate" as *u8, env, harness) 80 var t4: i64 = 0 81 if envrc == 1 { if env[GV_ENV_MEASURED] == 1 { t4 = 1 } } 82 gv_check("T4 the resolve rate publishes as a rigor envelope (k/n + interval + seed + method), never a bare percentage" as *u8, t4, ctr) 83 84 // T5 persist the envelope JSON line as the living record (append-only; the page reads the plane) 85 let d: *u8 = sys_mmap(AFL_LINE) 86 var o: i64 = afl_cat(d, 0, "SWBL ts=" as *u8) 87 o = afl_catn(d, o, sys_now_realtime_sec()) 88 o = afl_cat(d, o, " contract=swebench-faillpass+passtopass scope=sovereign-nishilang-analog envelope=" as *u8) 89 o = gv_envelope_json(d, o, env, harness) 90 o = afl_cat(d, o, "\n" as *u8) 91 let sp: *u8 = sys_mmap(SP_PATH_MAX) 92 afl_swbl_write_path(sp) 93 let wrote: i64 = afl_append(sp, d, o) 94 gv_puts(" persisted envelope record: " as *u8); gv_puts(sp); gv_puts(" (" as *u8); gv_num(wrote); gv_puts(" B)\n" as *u8) 95 var t5: i64 = 0 96 if wrote > 0 { t5 = 1 } 97 gv_check("T5 the living resolve-rate record is APPENDED as an envelope JSON line (never a whole-file rewrite)" as *u8, t5, ctr) 98 } 99 100 let rc: i64 = gv_verdict("SWEBENCH-LOCAL-GATE" as *u8, ctr, "loop graded by the field's cheat-proof contract; the resolve rate is a rigor envelope, not a bare percentage" as *u8) 101 sys_exit(rc) 102 return rc 103}