nx_autofix_lib_t138.nx
buildroot/runtime/nx_autofix_lib_t138.nx
about
nx_autofix_lib.nx -- THE SHARED RULERS OF THE AUTONOMOUS FIX LOOP (autodev M0, 2026-08-27).
WHY A LIB: nx_autofix_auto (the loop), nx_autofix_intake_gate (the intake) and nx_swebench_local_gate
(the judge) each carried their own copy of "find the failing FNRES row", their own ledger path
literal (/home/elderwesto/nx_stage/...) and their own idea of what a proposal row means. Three
organs that must agree cannot be kept agreeing by discipline; only one copy holds. This is the
one copy, and the contract symbols on the /compare/autodev board (af_episode_ledger,
af_sandbox_root, af_null_control, af_admit_untrusted, af_intake_board) are thin composers over it in
nx_autofix_auto.nx -- the loop's call sites -- while the gates drive these rulers in-process.
THE FIVE RULERS
AD5 EPISODE LEDGER afl_ledger_* -- one row per episode, appended AS DECIDED to an estate-relative
journal (knowledge/status/autofix_ledger.jrnl) so a run interrupted at 95 percent
keeps 95 percent, and the page reads the plane and nothing else. The dev-box
stage ledger stays the fallback (nx_stage_path), never a literal.
AD7 SANDBOX ROOT afl_sandbox_* -- every candidate builds and runs in /tmp/afx_sb_<ts>_<name>/
with its import closure COPIED (not linked: a write through a link would reach
the tree), the toolchain linked read-only, a real _build/, RLIMIT_CPU and
RLIMIT_AS on the child, a wall deadline that kills the whole process group.
The tree copy is never opened for write; afl_bytes_eq is the witness.
AD4 NULL CONTROLS afl_null_controls -- the empty patch and a replay of a prior solution are run
through the SAME judge; a null that scores GREEN is an oracle defect and the
batch is REFUSED, never published. Echo is rejected pre-verify by byte identity
(structural) and the revert patch is the empty patch by construction; both are
named on the line rather than counted twice.
AD6 UNTRUSTED INPUT afl_admit_row -- deny by default: a proposal row is LOCAL (built and run in the
sandbox) or EXTERNAL DATA-ONLY (provenance-pinned h<sha> AND maintainer-merged,
never executed); an external row missing either is refused BY NAME.
AD3 INTAKE PLANE afl_intake_emit -- folds the estate's own boards into one task plane: roster
RED gates, the adjudicated drift worklist, the magic ratchet counts, the unwired
baseline; every task carries its oracle and a RED-before receipt; the partition
prints its sum; debt rows carry no executable oracle and are REFUSED as
UNREPRODUCED (counted, never hidden); a source that is absent says ABSENT-SOURCE.
CONF (rule 17: env > conf > bootstrap): knowledge/autofix.conf rows sandbox_wall_ms, sandbox_as_bytes,
bon_n, bon_temp_pm, bon_topp_pm, bon_topk, null_controls_max_green. The defaults below are the July
contract values with the reason each was chosen written beside it.
license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 5 imports · 2 importers
imports: nx_syscalls.nxnx_estate_path.nxnx_stage_path.nxnx_tool_run.nxnx_build_canon_input_lib.nx
imported by: nx_autofix_auto_gate_t138.nxnx_autofix_intake_gate_t138.nx
structs
| none |
consts
| 45 | const AFL_PATH: i64 = 4096 // Linux PATH_MAX, the same bound nx_stage_path uses |
| 46 | const AFL_LINE: i64 = 2048 |
| 47 | const AFL_NAME: i64 = 64 |
| 48 | const AFL_HARNESS: i64 = 128 |
| 49 | const AFL_MODE_0644: i64 = 420 |
| 50 | const AFL_MODE_0755: i64 = 493 |
| 51 | const AFL_ABSENT: i64 = 0 - 999999 |
| 52 | const AFL_CAPTURE: i64 = 1048576 // one grader capture; the July candidates print under 1 KB, the bound announces when it binds |
| 53 | const AFL_LEDGER_JRNL: *u8 = "knowledge/status/autofix_ledger.jrnl" |
| 54 | const AFL_SWBL_JRNL: *u8 = "knowledge/status/swebench_local.jrnl" |
| 55 | const AFL_INTAKE_JRNL: *u8 = "knowledge/status/autodev_intake.jrnl" |
| 58 | const AFL_STATUS_PROBE: *u8 = "knowledge/status/harness.jrnl" |
| 59 | const AFL_LEDGER_STAGE: *u8 = "autofix_ledger.log" |
| 60 | const AFL_SWBL_STAGE: *u8 = "swebench_local_ledger.log" |
| 61 | const AFL_CLUSTER_MAX: i64 = 256 // distinct located functions in one batch; a batch above this reads UNMEASURED, announced |
| 62 | const AFL_CONF: *u8 = "knowledge/autofix.conf" |
| 63 | const AFL_KEY_WALL: *u8 = "sandbox_wall_ms=" |
| 64 | const AFL_KEY_AS: *u8 = "sandbox_as_bytes=" |
| 65 | const AFL_KEY_BON_N: *u8 = "bon_n=" |
| 66 | const AFL_KEY_BON_TEMP: *u8 = "bon_temp_pm=" |
| 67 | const AFL_KEY_BON_TOPP: *u8 = "bon_topp_pm=" |
| 68 | const AFL_KEY_BON_TOPK: *u8 = "bon_topk=" |
| 69 | const AFL_KEY_NULL_MAX: *u8 = "null_controls_max_green=" |
| 72 | const AFL_WALL_MS_DEFAULT: i64 = 300000 |
| 76 | const AFL_AS_BYTES_DEFAULT: i64 = 4294967296 |
| 77 | const AFL_BON_N_DEFAULT: i64 = 3 // the A1 best-of-N precedent |
| 78 | const AFL_BON_TEMP_DEFAULT: i64 = 800 // permil temperature, the A1 precedent |
| 79 | const AFL_BON_TOPP_DEFAULT: i64 = 950 // permil nucleus mass |
| 80 | const AFL_BON_TOPK_DEFAULT: i64 = 40 // top-k cutoff (the nsv sampler caps at 256) |
| 81 | const AFL_NULL_MAX_DEFAULT: i64 = 0 // ANY null control scoring GREEN refuses the batch |
| 82 | const AFL_POLL_MS: i64 = 100 // wait4(WNOHANG) cadence, the same the build runner polls its children at |
| 83 | const AFL_SIGKILL: i64 = 9 |
| 84 | const AFL_MS_PER_S: i64 = 1000 |
| 85 | const AFL_CLOSURE_MAX: i64 = 64 // import closure files copied into a sandbox; announces when it binds |
| 92 | const AFL_SB_NAME: *u8 = "afx_sb_" |
| 93 | const AFL_SB_TMP: *u8 = "/tmp/" |
| 94 | const AFL_TREE_PROBE: *u8 = "runtime/nx_syscalls.nx" |
| 95 | const AFL_RLIM_BYTES: i64 = 16 // struct rlimit64 { cur, max } |
| 96 | const AFL_EXIT_EXEC_FAIL: i64 = 127 |
| 97 | const AFL_EXIT_CHDIR_FAIL: i64 = 126 |
| 98 | const AFL_BUILDER_REL: *u8 = "_offc/nx_sov_build_run.elf" |
| 99 | const AFL_CC_REL: *u8 = "_offc/nx_cc_sovereign.elf" |
| 100 | const AFL_ASM_REL: *u8 = "_offc/nxasm_x86_main.elf" |
| 101 | const AFL_ADMIT_REL: *u8 = "_build/nx_build_admit.sov.elf" |
| 103 | const AFL_ADMIT_LOCAL: i64 = 1 |
| 104 | const AFL_ADMIT_DATA_ONLY: i64 = 2 |
| 105 | const AFL_REFUSED_UNPINNED: i64 = 0 - 1 |
| 106 | const AFL_REFUSED_UNMERGED: i64 = 0 - 2 |
| 107 | const AFL_REFUSED_MALFORMED: i64 = 0 - 3 |
| 109 | const AFL_ROSTER_JRNL: *u8 = "knowledge/status/gateroster.jrnl" |
| 110 | const AFL_DRIFT_WORKLIST: *u8 = "knowledge/status/adoption_worklist_laneB.txt" |
| 111 | const AFL_DRIFT_LOG: *u8 = "knowledge/status/artifactdrift.log" |
| 112 | const AFL_MAGIC_DIR: *u8 = "knowledge/status/magicbase" |
| 113 | const AFL_UNWIRED_BASE: *u8 = "nishi-ops/unwired.baseline" |
| 114 | const AFL_DEBT_ELF: *u8 = "./nx_debt.elf" |
| 115 | const AFL_ROSTER_MAX: i64 = 4096 // distinct gate names in the roster journal (633 today); announces when it binds |
| 116 | const AFL_DIRBUF: i64 = 65536 |
| 117 | const AFL_DEBT_TMO_MS: i64 = 60000 // the board's sev verb answers in seconds; a minute is the announce point |
| 495 | const AFL_CANON_CONF: *u8 = "knowledge/tree_canon.conf" |
| 496 | const AFL_CANON_HASH: *u8 = "knowledge/status/treecanon_laptop_hash.mf" |
| 497 | const AFL_CANON_RUNTIME: *u8 = "runtime/" |
| 498 | const AFL_CANON_MAP: *u8 = "candidate_source.rel" |
| 499 | const AFL_CANON_PATH_MAX: i64 = 503 |
functions
| 119 | func afl_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 120 | func afl_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } d[p] = 0 as u8; return p } |
| 121 | func afl_catn(d: *u8, o: i64, v: i64) -> i64 |
| 135 | func afl_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] == b[i] { if a[i] == (0 as u8) { return 1 } i = i + 1 } return 0 } |
| 136 | func afl_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 } |
| 137 | func afl_find(hay: *u8, hn: i64, needle: *u8, from: i64) -> i64 |
| 151 | func afl_eol(buf: *u8, n: i64, p: i64) -> i64 |
| 158 | func afl_tok(buf: *u8, ls: i64, le: i64, key: *u8, dst: *u8, cap: i64) -> i64 |
| 177 | func afl_uint_at(buf: *u8, p: i64, n: i64) -> i64 |
| 192 | func afl_int(buf: *u8, ls: i64, le: i64, key: *u8) -> i64 |
| 212 | func afl_conf_int(key: *u8, dflt: i64) -> i64 |
| 219 | func afl_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } |
| 220 | func afl_copyfile(srcp: *u8, dstp: *u8) -> i64 |
| 231 | func afl_bytes_eq(a: *u8, b: *u8) -> i64 |
| 243 | func afl_append(path: *u8, buf: *u8, n: i64) -> i64 |
| 251 | func afl_apply_fix(path: *u8, finds: *u8, repls: *u8) -> i64 called by 2: mainafl_null_controls calls 7: sys_mmapsys_read_fileafl_slenafl_findsys_openat_wrsys_write+1 |
| 278 | func afl_fn_failing(out: *u8, n: i64, namebuf: *u8) -> i64 |
| 313 | func afl_status_dir(out: *u8) -> i64 called by 2: afl_ledger_write_pathafl_swbl_write_path calls 4: sys_mmapep_artifact_pathsys_munmapafl_slen |
| 326 | func afl_ledger_read_path(out: *u8) -> i64 |
| 334 | func afl_ledger_write_path(out: *u8) -> i64 |
| 339 | func afl_swbl_write_path(out: *u8) -> i64 |
| 345 | func afl_ledger_append(row: *u8, n: i64, where: *u8) -> i64 |
| 358 | func afl_batch_stats(buf: *u8, n: i64, st: *i64, ck: *i64, cn: *i64, names: *u8, harness: *u8) -> i64 |
| 403 | func afl_admit_row(row: *u8, rl: i64, name: *u8, path: *u8, prov: *u8) -> i64 |
| 434 | func afl_admit_name(v: i64) -> *u8 called by 1: main |
| 444 | func afl_tool_abs(rel: *u8, out: *u8) -> i64 |
| 462 | func afl_sandbox_root_dir(out: *u8) -> i64 |
| 488 | func afl_run_examined(killed: i64, rc: i64, fnstate: i64) -> i64 |
| 501 | func afl_parent_dirs(path: *u8) -> i64 |
| 519 | func afl_sandbox_policy(outer: *u8, sb: *u8, tree: *u8, policy: *u8) -> i64 called by 1: afl_sandbox_make calls 12: sys_mmapep_joinsys_read_filebci_conf_rowsafl_parent_dirsafl_copyfile+6 |
| 567 | func afl_candidate_relative(srcpath: *u8, cname: *u8, out: *u8) -> i64 |
| 591 | func afl_closure_copy(sb: *u8, srcpath: *u8, base: *u8) -> i64 called by 1: afl_sandbox_make calls 12: sys_mmapafl_catbci_relative_pathafl_slenafl_parent_dirsafl_copyfile+6 |
| 666 | func afl_sandbox_make(ts: i64, cname: *u8, srcpath: *u8, out: *u8) -> i64 |
| 707 | func afl_sandbox_src(sb: *u8, cname: *u8, out: *u8) -> i64 |
| 726 | func afl_sandbox_run(sb: *u8, cname: *u8, out: *u8, cap: i64, wall_ms: i64, as_bytes: i64, st: *i64) -> i64 called by 3: mainmainafl_null_controls calls 18: sys_mmapafl_tool_abssys_forksys_setpgidnx_prlimitsys_chdir+12 |
| 787 | func afl_sandbox_reap(sb: *u8, cname: *u8) -> i64 |
| 806 | func afl_null_controls(sb: *u8, cname: *u8, sbsrc: *u8, snapshot: *u8, buggy: *u8, prior: *u8, out: *u8, cap: i64, wall_ms: i64, as_bytes: i64) -> i64 |
| 843 | func afl_intake_row(fd: i64, kind: *u8, subject: *u8, oracle: *u8, receipt: *u8, order: i64) -> i64 |
| 862 | func afl_intake_roster(fd: i64, path: *u8, order: *i64, st: *i64) -> i64 |
| 928 | func afl_intake_drift(fd: i64, path: *u8, epoch: i64, order: *i64, st: *i64) -> i64 |
| 966 | func afl_intake_magic(fd: i64, dir: *u8, order: *i64, st: *i64) -> i64 called by 1: afl_intake_emit calls 14: sys_openat_rdsys_mmapsys_getdents64dirent_namedirent_typeafl_slen+8 |
| 1016 | func afl_intake_unwired(fd: i64, path: *u8, order: *i64, st: *i64) -> i64 |
| 1044 | func afl_debt_total() -> i64 |
| 1060 | func afl_drift_epoch(path: *u8) -> i64 |
| 1079 | func afl_intake_emit(outpath: *u8, roster: *u8, drift: *u8, driftlog: *u8, magicdir: *u8, unwired: *u8, with_debt: i64) -> i64 |