code wiki / (root) / nx_ctlbyte_repair.nx

nx_ctlbyte_repair.nx

buildroot/runtime/nx_ctlbyte_repair.nx

16899 B359 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_ctlbyte_repair.nx -- FIND AND REPAIR CONTROL-BYTE CORRUPTION IN NishiLang SOURCES. WHAT HAPPENED, MEASURED 2026-09-03. A whole-population compiler census (nx_langcensus) found 314 of the tree's 13,721 top-level programs refused with "a control byte (decimal 14) sits in the source here" -- the single largest refusal class in the estate, larger than the next nineteen combined. Every one carries ONE contiguous run of EXACTLY 119 bytes of 0x0E, and in every case that run sits inside an integer-print helper, between the digit loop and its `return 0`. The corruption is present on BOTH trees, so it cannot be recovered from a twin, and the run length is a fixed filler that does not equal the length of the text it replaced -- so it cannot be recovered from the pattern either. It CAN be recovered from the CONTRACT: the enclosing function has already handled zero and sign and has built the digits into d[0..k) in reverse, so the only thing the lost bytes can have done is reverse them and write them. ★★★★★★A LOST REGION IS RECOVERABLE WHEN THE CODE AROUND IT PINS ITS CONTRACT -- AND THE ONLY HONEST REPAIR IS THE ONE THE SURROUNDING CODE FORCES, NEVER THE ONE THAT MERELY LOOKS PLAUSIBLE. 13 of the affected sources are on the gate roster, so their binaries RUN while their sources cannot rebuild them: the AHEAD class, where the served artifact carries code no source can reproduce. TWO SHAPES, ONE DECIDABLE RULE. Between the digit loop and the corrupt run: - no `sys_write(` yet -> the reversal AND the write were destroyed -> INSERT the tail, drop the run. - a `sys_write(` already -> only trailing cleanup was destroyed -> DROP the run, insert nothing. Anything else -> UNKNOWN, and this organ REFUSES to touch it. ★A REPAIRER THAT GUESSES IS A CORRUPTER WITH GOOD INTENTIONS: the unknown shapes are NAMED for a human, never silently rewritten. Usage: nx_ctlbyte_repair [--apply] [root ...] Default is a DRY census: every file, its class, and the partition -- nothing is written. `--apply` performs only the repairs whose class is decided, and re-reads each file afterwards to prove the byte is gone. ROOTS ARE ARGUMENTS, AND THE ORGAN PRINTS THE ONES IT WALKED. Measured 2026-09-03: with the roots hard-coded as `runtime/`, running this on the NAS (CWD = the serving root, where `runtime/` holds 17 files) reported `files=17 ... verdict=CLEAN` over a tree whose sources live in `buildroot/runtime/`. ★★★★★A SCANNER POINTED AT THE WRONG ROOT PRODUCES A CONFIDENT, COMPLETE-LOOKING FALSE NEGATIVE -- and a bare relative path is not a tree name, it is an expression whose meaning is the caller's CWD. Defaults (runtime, runtime/_hdl_build) apply only when no root is named, and are printed either way. Exit: 0 CLEAN (no corruption found) - 1 CORRUPTION PRESENT (dry run, or unknown shapes remain) 2 usage - 3 UNPROVEN (a walk cap filled, or a write-back could not be verified). RESOURCE ENVELOPE: one read and at most one write per affected file, sequential; buffers sized from the file and reused; nothing outside the named source files is written. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_ctlbyte_repair.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main cb_eq_n cb_len sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ cb_puts sys_write ↻ cb_len ↻ cb_walk sys_openat_rd sys_mmap ↻ sys_getdents64 dirent_name cb_ends_with cb_len ↻ cb_eq_n ↻ cb_cat dirent_reclen sys_close sys_exit ↻ cb_putn sys_write ↻ sys_mmap ↻ sys_read_file sys_openat_rd ↻ sys_lseek sys_mmap ↻

structs

none

consts

46const CB_MAX_FILES: i64 = 32768
47const CB_PATH_MAX: i64 = 4096
48const CB_DIRBUF: i64 = 65536
51const CB_FILEBUF: i64 = 4194304
54const CB_BYTE: i64 = 14
55const CB_OBSERVED_RUN: i64 = 119
58const CB_LOOKBACK: i64 = 400
60const CB_CLASS_INSERT: i64 = 0
61const CB_CLASS_DROP: i64 = 1
62const CB_CLASS_UNKNOWN: i64 = 2
64const CB_EXIT_CLEAN: i64 = 0
65const CB_EXIT_PRESENT: i64 = 1
66const CB_EXIT_USAGE: i64 = 2
67const CB_EXIT_UNPROVEN: i64 = 3
68const CB_MODE_0644: i64 = 0x1a4

functions

71func cb_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
72func cb_eq_n(a: *u8, b: *u8, n: i64) -> i64
77func cb_ends_with(s: *u8, sfx: *u8) -> i64
called by 1: cb_walk calls 2: cb_lencb_eq_n
84func cb_region_has(buf: *u8, from: i64, to: i64, needle: *u8) -> i64
called by 1: main calls 2: cb_lencb_eq_n
95func cb_cat(dst: *u8, at: i64, s: *u8, cap: i64) -> i64
called by 1: cb_walk
107func cb_puts(s: *u8) -> i64 { sys_write(1, s, cb_len(s)) return 0 }
called by 1: main calls 2: sys_writecb_len
108func cb_putn(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
124func cb_fix_text() -> *u8
called by 1: main
129func cb_walk(dir: *u8, tab: *i64, cap: i64, n_in: i64, full: *i64) -> i64
161func cb_class_name(c: i64) -> *u8
called by 1: main
167func main(argc: i64, argv: *i64) -> i64