code wiki / (root) / nx_autofix_lib_t138.nx

nx_autofix_lib_t138.nx

buildroot/runtime/nx_autofix_lib_t138.nx

55142 B1135 linesdepth 5pulls 9 transitivereach 2 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 5 imports · 2 importers

nx_syscalls.nx nx_estate_path.nx nx_stage_path.nx nx_tool_run.nx nx_build_canon_input_lib.nx nx_autofix_lib_t138.nx nx_autofix_auto_gate_t138.nx nx_autofix_intake_gate_t138.nx

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

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

functions

119func afl_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
120func 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 }
121func afl_catn(d: *u8, o: i64, v: i64) -> i64
135func 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 }
136func 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 }
137func afl_find(hay: *u8, hn: i64, needle: *u8, from: i64) -> i64
151func afl_eol(buf: *u8, n: i64, p: i64) -> i64
158func afl_tok(buf: *u8, ls: i64, le: i64, key: *u8, dst: *u8, cap: i64) -> i64
177func afl_uint_at(buf: *u8, p: i64, n: i64) -> i64
192func afl_int(buf: *u8, ls: i64, le: i64, key: *u8) -> i64
212func afl_conf_int(key: *u8, dflt: i64) -> i64
219func afl_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
220func afl_copyfile(srcp: *u8, dstp: *u8) -> i64
231func afl_bytes_eq(a: *u8, b: *u8) -> i64
243func afl_append(path: *u8, buf: *u8, n: i64) -> i64
251func afl_apply_fix(path: *u8, finds: *u8, repls: *u8) -> i64
278func afl_fn_failing(out: *u8, n: i64, namebuf: *u8) -> i64
313func afl_status_dir(out: *u8) -> i64
326func afl_ledger_read_path(out: *u8) -> i64
334func afl_ledger_write_path(out: *u8) -> i64
339func afl_swbl_write_path(out: *u8) -> i64
345func afl_ledger_append(row: *u8, n: i64, where: *u8) -> i64
358func afl_batch_stats(buf: *u8, n: i64, st: *i64, ck: *i64, cn: *i64, names: *u8, harness: *u8) -> i64
403func afl_admit_row(row: *u8, rl: i64, name: *u8, path: *u8, prov: *u8) -> i64
434func afl_admit_name(v: i64) -> *u8
called by 1: main
444func afl_tool_abs(rel: *u8, out: *u8) -> i64
462func afl_sandbox_root_dir(out: *u8) -> i64
488func afl_run_examined(killed: i64, rc: i64, fnstate: i64) -> i64
called by 2: mainmain
501func afl_parent_dirs(path: *u8) -> i64
519func afl_sandbox_policy(outer: *u8, sb: *u8, tree: *u8, policy: *u8) -> i64
567func afl_candidate_relative(srcpath: *u8, cname: *u8, out: *u8) -> i64
591func afl_closure_copy(sb: *u8, srcpath: *u8, base: *u8) -> i64
666func afl_sandbox_make(ts: i64, cname: *u8, srcpath: *u8, out: *u8) -> i64
707func afl_sandbox_src(sb: *u8, cname: *u8, out: *u8) -> i64
726func afl_sandbox_run(sb: *u8, cname: *u8, out: *u8, cap: i64, wall_ms: i64, as_bytes: i64, st: *i64) -> i64
787func afl_sandbox_reap(sb: *u8, cname: *u8) -> i64
806func 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
843func afl_intake_row(fd: i64, kind: *u8, subject: *u8, oracle: *u8, receipt: *u8, order: i64) -> i64
862func afl_intake_roster(fd: i64, path: *u8, order: *i64, st: *i64) -> i64
928func afl_intake_drift(fd: i64, path: *u8, epoch: i64, order: *i64, st: *i64) -> i64
966func afl_intake_magic(fd: i64, dir: *u8, order: *i64, st: *i64) -> i64
1016func afl_intake_unwired(fd: i64, path: *u8, order: *i64, st: *i64) -> i64
1044func afl_debt_total() -> i64
1060func afl_drift_epoch(path: *u8) -> i64
1079func afl_intake_emit(outpath: *u8, roster: *u8, drift: *u8, driftlog: *u8, magicdir: *u8, unwired: *u8, with_debt: i64) -> i64