code wiki / _hdl_build / nx_memcliff.nx

nx_memcliff.nx

buildroot/runtime/_hdl_build/nx_memcliff.nx

38401 B822 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_memcliff.nx -- SOVEREIGN owner of the MEMORY.md byte budget. Replaces memindex_enforce.py (Stop hook) and the eviction half of memory_cliff_check.ps1 (SessionStart/PostToolUse) with ONE nishi organ, so no interpreter sits in the hook path. WHY AN ORGAN AND NOT A SCRIPT ----------------------------- MEMORY.md is injected into every session; past a byte limit the harness DROPS THE TAIL SILENTLY -- no error, no marker. The dropped lines are exactly the ones that would have told you they were dropped. The rail-side enforcer cannot own this file (it runs NAS-side; MEMORY.md is laptop-local, nx_memindex_put -> `no-md-file`), so ownership has to live here, next to the file. WHAT WAS ACTUALLY BROKEN -- MEASURED 2026-08-06, not assumed ------------------------------------------------------------ The Python enforcer was NOT missing: it had run 64 times (64 eviction stamps in the overflow) and had compacted the file at 13:47 the same day. It had JAMMED: "22013 bytes over budget but NO evictable entries found -- refusing to guess" Root cause, measured: its rule NEVER EVICT THE NEWEST DAY pinned 8 of 8 candidates, because every evictable entry carried today's date. Survivors after the pin: ZERO. ★LAW: A PIN THAT CAN COVER 100% OF ITS CANDIDATES IS AN OFF SWITCH. The rule that protects today's record disables enforcement precisely on the heaviest days -- the file grew 4.2KB in the two hours after that successful compaction, with nothing left able to evict it. The fix is not to drop the pin (it earned its place: a pure oldest-first cut once ate the current session's own record) but to make it YIELD: keep the newest `keep_newest_day` entries of the newest day and release the rest, rather than pinning the whole day unconditionally. SECOND MEASURED DEFECT -- the enforcer could not measure its subject in the unit the limit uses. MEMORY.md is CRLF (63 CRLF, 0 bare LF). Python read it in text mode, which collapses CRLF to LF, so it measured 22,013 against a file of 22,076 bytes -- UNDERSTATING by exactly the line count. The harness cliff is a property of the bytes on disk, so every decision was made against a number that was never the file's size. ★LAW: A BUDGET ENFORCER THAT CANNOT MEASURE ITS SUBJECT IN THE UNIT THE LIMIT USES IS GUESSING. ⚠WHAT I FIRST WROTE HERE AND THEN DISPROVED: I claimed the two owners also flipped the file's line endings against each other (py writing LF, the ps1 writing CRLF). THE EXPERIMENT REFUTED IT -- a CRLF fixture through the oracle came out CRLF=26 / bare-LF=0, because Python's text-mode WRITE translates back on Windows, exactly undoing the read. The round trip is lossless; only the measurement was wrong. Recorded rather than quietly deleted, because a plausible mechanism I had not run is precisely the kind of premise that spends like evidence. This organ works in RAW BYTES and reconstructs each line with its original terminator, so it is byte-exact by construction rather than by a translation that happens to cancel out (verified: the same CRLF fixture out at CRLF=26 / bare-LF=0).

dependencies 1 imports · 0 importers

nx_memplane_lib.nx nx_memcliff.nx

imports: nx_memplane_lib.nx

imported by: nobody (leaf or entry point)

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

main mp_streq mc_join mp_readf mc_conf mc_at mp_len mp_len ↻ mc_isdigit mc_fsize mc_exists mp_cat mc_emit mp_write_all sys_write mp_cat ↻ mc_split mp_catn 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 ↻ mc_find mc_at ↻ mc_is_entry mc_find ↻ mc_datekey mc_isdigit ↻ mp_len ↻

structs

none

consts

83const MC_DIR: *u8 = "/mnt/c/Users/elder/.claude/projects/C--Users-elder/memory"
84const MC_N_MEM: *u8 = "MEMORY.md"
85const MC_N_OVF: *u8 = "reference-index-recent-refs-dormant.md"
86const MC_N_CNF: *u8 = "memcliff.conf"
87const MC_N_TMP: *u8 = "MEMORY.md.mctmp"
89const MC_MAXL: i64 = 8192 // max lines in the index (64 today; vast headroom)
90const MC_BUF: i64 = 4194304 // 4MB read buffer
91const MC_OUT: i64 = 4194304 // 4MB assembled output
92const MC_MSG: i64 = 8192 // report buffer
95const MC_D_CLIFF: i64 = 25000 // below the 26,229 B measured truncation
96const MC_D_TARGET: i64 = 23000 // evict down to this; above the 22,076 B measured-good load
97const MC_D_WARN: i64 = 21000 // report headroom from here up
98const MC_D_KEEP: i64 = 3 // newest-day entries always kept when the pin has to yield
99const MC_D_PIN: i64 = 12 // pinned head: header + survival block, never evicted
105const MC_D_MAXLINE: i64 = 200 // measured: line 201+ is not delivered
106const MC_D_TGTLINE: i64 = 180 // evict down to this, so ordinary appends don't immediately rebreach
108const MC_PTRTAG: *u8 = "verbatim by nx_memcliff:"

functions

116func mc_at(buf: *u8, pos: i64, lim: i64, pat: *u8) -> i64
called by 2: mc_findmc_conf calls 1: mp_len
128func mc_find(buf: *u8, from: i64, lim: i64, pat: *u8) -> i64
called by 2: mc_is_entrymain calls 1: mc_at
140func mc_isdigit(c: u8) -> i64
150func mc_emit(json: i64, buf: *u8, n: i64) -> i64
called by 1: main calls 2: mp_write_allmp_cat
180func mc_join(dir: *u8, name: *u8) -> *u8
called by 1: main
194func mc_fsize(path: *u8) -> i64
called by 1: main
202func mc_exists(path: *u8) -> i64
called by 1: main
209func mp_readf(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main
228func mc_conf(cbuf: *u8, clen: i64, key: *u8, dflt: i64) -> i64
called by 1: main calls 3: mc_atmp_lenmc_isdigit
271func mc_split(buf: *u8, n: i64, ls: *i64, ll: *i64, cap: i64) -> i64
called by 1: main
290func mc_datekey(buf: *u8, s: i64, e: i64) -> i64
called by 1: main calls 1: mc_isdigit
346func mc_is_entry(buf: *u8, s: i64, e: i64) -> i64
called by 1: main calls 1: mc_find
357func main(argc: i64, argv: *i64) -> i64