code wiki / _hdl_build / nx_memguard.nx
nx_memguard.nx
buildroot/runtime/_hdl_build/nx_memguard.nx
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
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
| 67 | const MG_DIR: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory" |
| 68 | const MG_MAXF: i64 = 8192 |
| 69 | const MG_SLOT: i64 = 128 |
| 70 | const MG_FBUF: i64 = 1048576 |
| 71 | const MG_GBUF: i64 = 65536 |
| 72 | const MG_MSG: i64 = 32768 |
| 73 | const MG_MAXT: i64 = 24 // derived query terms (bitmask is i64) |
| 74 | const MG_MINW: i64 = 3 // shortest word worth querying. 5 was tried and FAILED: the two |
| 80 | const MG_WARN: i64 = 3 // this many shared TOPICAL terms before we say anything |
| 81 | const MG_COMMON: i64 = 20 // a term in more than 1/20 of the corpus carries no topic signal |
functions
| 83 | func mg_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 85 | func mg_streq(a: *u8, b: *u8) -> i64 called by 1: main |
| 97 | func mg_cat(buf: *u8, off: i64, s: *u8) -> i64 called by 1: main |
| 104 | func mg_catn(buf: *u8, off: i64, v: i64) -> i64 |
| 117 | func mg_write_all(fd: i64, buf: *u8, n: i64) -> i64 |
| 128 | func mg_say(buf: *u8, n: i64) -> i64 { return mg_write_all(1, buf, n) } |
| 130 | func mg_getdents(fd: i64, buf: *u8, count: i64) -> i64 { return __syscall(217, fd, buf, count, 0, 0, 0) } called by 1: main |
| 132 | func mg_join(dst: *u8, dir: *u8, name: *u8) -> i64 called by 1: main |
| 143 | func mg_readf(p: *u8, buf: *u8, cap: i64) -> i64 |
| 159 | func mg_is_md(name: *u8) -> i64 |
| 168 | func mg_lower(c: u8) -> i64 |
| 173 | func mg_alnum(c: u8) -> i64 |
| 185 | func mg_has(buf: *u8, n: i64, pat: *u8) -> i64 |
| 208 | func mg_nameptr(names: *u8, i: i64) -> *u8 { return ((names as i64) + i * MG_SLOT) as *u8 } called by 1: main |
| 210 | func mg_log2(v: i64) -> i64 called by 1: main |
| 218 | func mg_base(p: *u8) -> *u8 |
| 229 | func main(argc: i64, argv: *i64) -> i64 |