nx_ctlbyte_repair.nx
buildroot/runtime/nx_ctlbyte_repair.nx
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
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
structs
| none |
consts
| 46 | const CB_MAX_FILES: i64 = 32768 |
| 47 | const CB_PATH_MAX: i64 = 4096 |
| 48 | const CB_DIRBUF: i64 = 65536 |
| 51 | const CB_FILEBUF: i64 = 4194304 |
| 54 | const CB_BYTE: i64 = 14 |
| 55 | const CB_OBSERVED_RUN: i64 = 119 |
| 58 | const CB_LOOKBACK: i64 = 400 |
| 60 | const CB_CLASS_INSERT: i64 = 0 |
| 61 | const CB_CLASS_DROP: i64 = 1 |
| 62 | const CB_CLASS_UNKNOWN: i64 = 2 |
| 64 | const CB_EXIT_CLEAN: i64 = 0 |
| 65 | const CB_EXIT_PRESENT: i64 = 1 |
| 66 | const CB_EXIT_USAGE: i64 = 2 |
| 67 | const CB_EXIT_UNPROVEN: i64 = 3 |
| 68 | const CB_MODE_0644: i64 = 0x1a4 |
functions
| 71 | func cb_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 72 | func cb_eq_n(a: *u8, b: *u8, n: i64) -> i64 |
| 77 | func cb_ends_with(s: *u8, sfx: *u8) -> i64 |
| 84 | func cb_region_has(buf: *u8, from: i64, to: i64, needle: *u8) -> i64 |
| 95 | func cb_cat(dst: *u8, at: i64, s: *u8, cap: i64) -> i64 called by 1: cb_walk |
| 107 | func cb_puts(s: *u8) -> i64 { sys_write(1, s, cb_len(s)) return 0 } |
| 108 | func cb_putn(v: i64) -> i64 |
| 124 | func cb_fix_text() -> *u8 called by 1: main |
| 129 | func cb_walk(dir: *u8, tab: *i64, cap: i64, n_in: i64, full: *i64) -> i64 |
| 161 | func cb_class_name(c: i64) -> *u8 called by 1: main |
| 167 | func main(argc: i64, argv: *i64) -> i64 |