code wiki / (root) / nx_autofix_lib.nx

nx_autofix_lib.nx

buildroot/runtime/nx_autofix_lib.nx

49846 B1005 linesdepth 5pulls 8 transitivereach 4 importersview sourcekind librarytopic autofix
docsdependenciesstructsconstsfunctions

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 4 imports · 4 importers

nx_syscalls.nx nx_estate_path.nx nx_stage_path.nx nx_tool_run.nx nx_autofix_lib.nx nx_autofix_auto.nx nx_autofix_auto_gate.nx nx_autofix_intake_gate.nx nx_swebench_local_gate.nx

imports: nx_syscalls.nxnx_estate_path.nxnx_stage_path.nxnx_tool_run.nx

imported by: nx_autofix_auto.nxnx_autofix_auto_gate.nxnx_autofix_intake_gate.nxnx_swebench_local_gate.nx

structs

none

consts

44const AFL_PATH: i64 = 4096 // Linux PATH_MAX, the same bound nx_stage_path uses
45const AFL_LINE: i64 = 2048
46const AFL_NAME: i64 = 64
47const AFL_HARNESS: i64 = 128
48const AFL_MODE_0644: i64 = 420
49const AFL_MODE_0755: i64 = 493
50const AFL_ABSENT: i64 = 0 - 999999
51const AFL_CAPTURE: i64 = 1048576 // one grader capture; the July candidates print under 1 KB, the bound announces when it binds
52const AFL_LEDGER_JRNL: *u8 = "knowledge/status/autofix_ledger.jrnl"
53const AFL_SWBL_JRNL: *u8 = "knowledge/status/swebench_local.jrnl"
54const AFL_INTAKE_JRNL: *u8 = "knowledge/status/autodev_intake.jrnl"
57const AFL_STATUS_PROBE: *u8 = "knowledge/status/harness.jrnl"
58const AFL_LEDGER_STAGE: *u8 = "autofix_ledger.log"
59const AFL_SWBL_STAGE: *u8 = "swebench_local_ledger.log"
60const AFL_CLUSTER_MAX: i64 = 256 // distinct located functions in one batch; a batch above this reads UNMEASURED, announced
61const AFL_CONF: *u8 = "knowledge/autofix.conf"
62const AFL_KEY_WALL: *u8 = "sandbox_wall_ms="
63const AFL_KEY_AS: *u8 = "sandbox_as_bytes="
64const AFL_KEY_BON_N: *u8 = "bon_n="
65const AFL_KEY_BON_TEMP: *u8 = "bon_temp_pm="
66const AFL_KEY_BON_TOPP: *u8 = "bon_topp_pm="
67const AFL_KEY_BON_TOPK: *u8 = "bon_topk="
68const AFL_KEY_NULL_MAX: *u8 = "null_controls_max_green="
71const AFL_WALL_MS_DEFAULT: i64 = 300000
75const AFL_AS_BYTES_DEFAULT: i64 = 4294967296
76const AFL_BON_N_DEFAULT: i64 = 3 // the A1 best-of-N precedent
77const AFL_BON_TEMP_DEFAULT: i64 = 800 // permil temperature, the A1 precedent
78const AFL_BON_TOPP_DEFAULT: i64 = 950 // permil nucleus mass
79const AFL_BON_TOPK_DEFAULT: i64 = 40 // top-k cutoff (the nsv sampler caps at 256)
80const AFL_NULL_MAX_DEFAULT: i64 = 0 // ANY null control scoring GREEN refuses the batch
81const AFL_POLL_MS: i64 = 100 // wait4(WNOHANG) cadence, the same the build runner polls its children at
82const AFL_SIGKILL: i64 = 9
83const AFL_MS_PER_S: i64 = 1000
84const AFL_CLOSURE_MAX: i64 = 64 // import closure files copied into a sandbox; announces when it binds
91const AFL_SB_NAME: *u8 = "afx_sb_"
92const AFL_SB_TMP: *u8 = "/tmp/"
93const AFL_TREE_PROBE: *u8 = "runtime/nx_syscalls.nx"
94const AFL_RLIM_BYTES: i64 = 16 // struct rlimit64 { cur, max }
95const AFL_EXIT_EXEC_FAIL: i64 = 127
96const AFL_EXIT_CHDIR_FAIL: i64 = 126
97const AFL_BUILDER_REL: *u8 = "_offc/nx_sov_build_run.elf"
98const AFL_CC_REL: *u8 = "_offc/nx_cc_sovereign.elf"
99const AFL_ASM_REL: *u8 = "_offc/nxasm_x86_main.elf"
100const AFL_ADMIT_REL: *u8 = "_build/nx_build_admit.sov.elf"
102const AFL_ADMIT_LOCAL: i64 = 1
103const AFL_ADMIT_DATA_ONLY: i64 = 2
104const AFL_REFUSED_UNPINNED: i64 = 0 - 1
105const AFL_REFUSED_UNMERGED: i64 = 0 - 2
106const AFL_REFUSED_MALFORMED: i64 = 0 - 3
108const AFL_ROSTER_JRNL: *u8 = "knowledge/status/gateroster.jrnl"
109const AFL_DRIFT_WORKLIST: *u8 = "knowledge/status/adoption_worklist_laneB.txt"
110const AFL_DRIFT_LOG: *u8 = "knowledge/status/artifactdrift.log"
111const AFL_MAGIC_DIR: *u8 = "knowledge/status/magicbase"
112const AFL_UNWIRED_BASE: *u8 = "nishi-ops/unwired.baseline"
113const AFL_DEBT_ELF: *u8 = "./nx_debt.elf"
114const AFL_ROSTER_MAX: i64 = 4096 // distinct gate names in the roster journal (633 today); announces when it binds
115const AFL_DIRBUF: i64 = 65536
116const AFL_DEBT_TMO_MS: i64 = 60000 // the board's sev verb answers in seconds; a minute is the announce point

functions

118func afl_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
119func 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 }
120func afl_catn(d: *u8, o: i64, v: i64) -> i64
134func 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 }
135func 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 }
136func afl_find(hay: *u8, hn: i64, needle: *u8, from: i64) -> i64
150func afl_eol(buf: *u8, n: i64, p: i64) -> i64
157func afl_tok(buf: *u8, ls: i64, le: i64, key: *u8, dst: *u8, cap: i64) -> i64
176func afl_uint_at(buf: *u8, p: i64, n: i64) -> i64
191func afl_int(buf: *u8, ls: i64, le: i64, key: *u8) -> i64
211func afl_conf_int(key: *u8, dflt: i64) -> i64
218func afl_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
219func afl_copyfile(srcp: *u8, dstp: *u8) -> i64
230func afl_bytes_eq(a: *u8, b: *u8) -> i64
242func afl_append(path: *u8, buf: *u8, n: i64) -> i64
250func afl_apply_fix(path: *u8, finds: *u8, repls: *u8) -> i64
277func afl_fn_failing(out: *u8, n: i64, namebuf: *u8) -> i64
312func afl_status_dir(out: *u8) -> i64
325func afl_ledger_read_path(out: *u8) -> i64
333func afl_ledger_write_path(out: *u8) -> i64
338func afl_swbl_write_path(out: *u8) -> i64
344func afl_ledger_append(row: *u8, n: i64, where: *u8) -> i64
357func afl_batch_stats(buf: *u8, n: i64, st: *i64, ck: *i64, cn: *i64, names: *u8, harness: *u8) -> i64
402func afl_admit_row(row: *u8, rl: i64, name: *u8, path: *u8, prov: *u8) -> i64
433func afl_admit_name(v: i64) -> *u8
called by 2: mainmain
443func afl_tool_abs(rel: *u8, out: *u8) -> i64
461func afl_sandbox_root_dir(out: *u8) -> i64
488func afl_closure_copy(sb: *u8, srcpath: *u8, base: *u8) -> i64
559func afl_sandbox_make(ts: i64, cname: *u8, srcpath: *u8, out: *u8) -> i64
585func afl_sandbox_src(sb: *u8, cname: *u8, out: *u8) -> i64
called by 2: episodemain calls 1: afl_cat
596func afl_sandbox_run(sb: *u8, cname: *u8, out: *u8, cap: i64, wall_ms: i64, as_bytes: i64, st: *i64) -> i64
657func afl_sandbox_reap(sb: *u8, cname: *u8) -> i64
676func 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
713func afl_intake_row(fd: i64, kind: *u8, subject: *u8, oracle: *u8, receipt: *u8, order: i64) -> i64
732func afl_intake_roster(fd: i64, path: *u8, order: *i64, st: *i64) -> i64
798func afl_intake_drift(fd: i64, path: *u8, epoch: i64, order: *i64, st: *i64) -> i64
836func afl_intake_magic(fd: i64, dir: *u8, order: *i64, st: *i64) -> i64
886func afl_intake_unwired(fd: i64, path: *u8, order: *i64, st: *i64) -> i64
914func afl_debt_total() -> i64
930func afl_drift_epoch(path: *u8) -> i64
949func afl_intake_emit(outpath: *u8, roster: *u8, drift: *u8, driftlog: *u8, magicdir: *u8, unwired: *u8, with_debt: i64) -> i64