code wiki / _hdl_build / nx_memguard.nx

nx_memguard.nx

buildroot/runtime/_hdl_build/nx_memguard.nx

20505 B500 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

⛔⛔ DISPROVEN 2026-08-06 -- BUILT, MEASURED, AND RETRACTED. NOT DEPLOYED, NOT HOOK-WIRED. The ELF was deliberately removed from _offc. Source kept as a recorded negative result, because the idea is attractive enough that someone will otherwise build it again. WHAT IT WAS MEANT TO DO: derive a query from a new memory's own name+description and warn if the corpus already holds that doctrine -- prevention at write time, where post-hoc detection has a proven ceiling. WHY IT DOES NOT WORK (clean replay + control, both failed): * replay: fed the ORIGINAL July store-law frontmatter, it did NOT surface the June file that says the same thing. It returned project-nofloat-models-vision and netobs-observability instead. * control: a birdsong-synthesis note fired 4/6 against a FETCHER memory. A guard that fires on everything is indistinguishable from no guard, except it also teaches the reader to ignore it. ⚠MY FIRST "VALIDATION" WAS CONTAMINATED and nearly shipped: I pointed it at the July file AFTER stubbing it, and the stub's description literally contains the canonical filename. It scored 17/20 and looked like a triumph. ★ A FIXTURE THAT NAMES ITS OWN ANSWER VALIDATES NOTHING. ★★★★★★ THE ROOT CAUSE, MEASURED, AND IT INDICTS MORE THAN THIS ORGAN: IDF ASSUMES A DIVERSE CORPUS. IN A SINGLE-PROJECT CORPUS THE TOPIC WORDS *ARE* THE COMMON WORDS, SO RARITY WEIGHTING SELECTS FOR THE INCIDENTAL. Document frequency over the 2,178-file corpus (common cutoff = 108): sovereign 1178 · data 1108 · files 803 · store 638 · tsv 438 · txt 388 · ssot 257 · seg 228 Every word that IDENTIFIES the store law is corpus-common and gets dropped; the survivors were "planes" (105) and "queues" (39) -- incidental words that then matched unrelated files. Lowering the word-length floor 5 -> 3 to admit "tsv"/"txt" changed NOTHING, because those are common too. ⇒ Rarity weighting works for distinguishing specific technical artefacts (coulombic, dendrite) and fails for a project's CENTRAL concepts -- which is exactly where duplicated doctrine lives. The same blind spot limits nx_memhealth's duplicate ladder. nx_memfind is unaffected ONLY because a human picks its query terms; that human judgement is the part that cannot currently be automated. ---- original design notes below ---- nx_memguard.nx -- at WRITE time, ask "does this memory already exist?" and name the candidates. WHY THIS AND NOT MORE DETECTION ------------------------------ Measured 2026-08-06, the same doctrine written four times in 90 seconds; the store law written twice by two sessions three weeks apart; nge-browser-first written twice by ONE session. Every one

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_memguard.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 mg_streq 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 ↻ mg_cat mg_say mg_write_all sys_write ↻ mg_base mg_len mg_is_md mg_len ↻ mg_readf sys_openat_rd sys_read sys_close mg_len ↻ mg_alnum mg_lower sys_openat_rd ↻ mg_getdents mg_nameptr sys_close ↻ mg_join mg_has mg_len ↻ mg_lower ↻

structs

none

consts

67const MG_DIR: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory"
68const MG_MAXF: i64 = 8192
69const MG_SLOT: i64 = 128
70const MG_FBUF: i64 = 1048576
71const MG_GBUF: i64 = 65536
72const MG_MSG: i64 = 32768
73const MG_MAXT: i64 = 24 // derived query terms (bitmask is i64)
74const MG_MINW: i64 = 3 // shortest word worth querying. 5 was tried and FAILED: the two
80const MG_WARN: i64 = 3 // this many shared TOPICAL terms before we say anything
81const MG_COMMON: i64 = 20 // a term in more than 1/20 of the corpus carries no topic signal

functions

83func mg_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
85func mg_streq(a: *u8, b: *u8) -> i64
called by 1: main
97func mg_cat(buf: *u8, off: i64, s: *u8) -> i64
called by 1: main
104func mg_catn(buf: *u8, off: i64, v: i64) -> i64
called by 1: main calls 1: sys_mmap
117func mg_write_all(fd: i64, buf: *u8, n: i64) -> i64
called by 1: mg_say calls 1: sys_write
128func mg_say(buf: *u8, n: i64) -> i64 { return mg_write_all(1, buf, n) }
called by 1: main calls 1: mg_write_all
130func mg_getdents(fd: i64, buf: *u8, count: i64) -> i64 { return __syscall(217, fd, buf, count, 0, 0, 0) }
called by 1: main
132func mg_join(dst: *u8, dir: *u8, name: *u8) -> i64
called by 1: main
143func mg_readf(p: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
159func mg_is_md(name: *u8) -> i64
called by 1: main calls 1: mg_len
168func mg_lower(c: u8) -> i64
called by 2: mg_hasmain
173func mg_alnum(c: u8) -> i64
called by 2: mg_hasmain
185func mg_has(buf: *u8, n: i64, pat: *u8) -> i64
called by 1: main calls 3: mg_lenmg_lowermg_alnum
208func mg_nameptr(names: *u8, i: i64) -> *u8 { return ((names as i64) + i * MG_SLOT) as *u8 }
called by 1: main
210func mg_log2(v: i64) -> i64
called by 1: main
218func mg_base(p: *u8) -> *u8
called by 1: main calls 1: mg_len
229func main(argc: i64, argv: *i64) -> i64