code wiki / _hdl_build / nx_store_janitor_beat.nx
nx_store_janitor_beat.nx
buildroot/runtime/_hdl_build/nx_store_janitor_beat.nx
about
nx_store_janitor_beat.nx -- standing reclamation of SUPERSEDED seg-store segment files.
WHY A BEAT AND NOT A ONE-SHOT: on 2026-07-30 a single manual sweep moved 57,348 MB across 336 planes
(14,585 live segment .docs down to 2,973). Within the SAME session debt- went from 1 segment back to 18
and down again as siblings wrote and compacted. The seg-store is append-only and every commit writes a NEW
segment, so superseded files re-accumulate CONTINUOUSLY. A cleanup that has to be remembered is a
workaround; the fix is a standing sweep row that keeps the property true without anyone noticing.
SIBLING TO nx_store_fold_beat AND DELIBERATELY ORDERED AFTER IT: fold_beat MERGES a bloated plane (segment
COUNT / scan cost), which by construction supersedes the segments it merged. This beat then reclaims those
files (disk / directory hygiene). Fold makes garbage; janitor takes it out. Neither replaces the other.
Forks the proven ./nx_store_janitor.elf per plane exactly as fold_beat forks nx_store_compact -- the worker
owns the safety argument (manifest IS the definition of live, REFUSES on an unreadable manifest, moves aside
into retired/ and never unlinks, and re-reads the manifest afterwards to restore anything a concurrent
writer made live mid-walk). This beat adds discovery and aggregation ONLY; it must not re-implement policy.
Sweep-row contract: exit 0 = every plane reclaimed or already clean; exit 1 = a plane REFUSED (unknown live
set) or a live segment was moved and restored -- surfaced RED, never silent.
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_tool_run.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
| 24 | const JB_DIRBUF: i64 = 262144 |
| 25 | const JB_PATHCAP: i64 = 1024 |
| 26 | const JB_OUTCAP: i64 = 65536 |
| 27 | const JB_STORE: *u8 = "knowledge/store" as *u8 |
| 28 | const JB_JANITOR: *u8 = "./nx_store_janitor.elf" as *u8 |
| 29 | const JB_MANI: *u8 = "manifest.txt" as *u8 |
| 30 | const JB_MANILEN: i64 = 12 |
| 31 | const JB_STDOUT: i64 = 1 |
| 32 | const JB_NL: i64 = 10 |
| 33 | const JB_AVCAP: i64 = 40 |
functions
| 35 | func jb_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 36 | func jb_puts(s: *u8) -> i64 { sys_write(JB_STDOUT, s, jb_len(s)); return 0 } |
| 37 | func jb_putn(v: i64) -> i64 |
| 54 | func jb_ends_manifest(nm: *u8) -> i64 |
| 73 | func jb_field(buf: *u8, n: i64, key: *u8) -> i64 |
| 106 | func main(argc: i64, argv: *i64) -> i64 |