nx_unread_sensor_lib.nx source
↩ module page · 185 lines · 8624 B
1// nx_unread_sensor_lib.nx -- the pure core of the UNREAD-SENSOR census.
2//
3// THE PATTERN THIS EXISTS FOR, MEASURED FOUR TIMES IN ONE DAY (2026-09-03):
4// * procchurn.jrnl carried a correct sev= on every frame for 35 DAYS and no organ read that field.
5// * nx_raidwatch was verdict=RED the whole time and nothing consumed it.
6// * loadgov LV1 was the same shape one board over.
7// * nx_health reported overall:OK for 16 services while having NO STORAGE AXIS AT ALL, and
8// nx_healthtruth -- built for exactly that shape -- had been STAGED and never promoted.
9// Four independent rediscoveries of one shape is not four mistakes, it is A STRUCTURAL PATTERN WITH A
10// MEASURED RECURRENCE RATE, and the estate had no instrument for it. A SENSOR WHOSE OUTPUT NOTHING READS
11// CANNOT CHANGE AN OUTCOME, AND FROM ANY DASHBOARD IT IS INDISTINGUISHABLE FROM ONE THAT IS WORKING.
12//
13// WHAT IT MEASURES, STATED AS THE NARROW THING IT IS. For every artifact under knowledge/status/, it
14// counts how many DISTINCT .nx sources mention that filename literally. That count is a FLOOR on readers
15// and writers together, so the buckets are named for what was measured and never for the remedy:
16// NO-LITERAL-REFERENCE no source names it at all -- built from a variable, or genuinely orphaned
17// SINGLE-NAMER exactly one source names it, which is almost always its own producer
18// NAMED-BY-SEVERAL at least two, so something other than the writer can see it
19// SINGLE-NAMER is the suspicious class, NOT a proven defect: a producer that also re-reads its own file
20// is legitimately single. ★ NAME A BUCKET FOR WHAT WAS MEASURED, NEVER FOR THE ACTION YOU IMAGINE
21// FOLLOWS -- a bucket called UNREAD would send the next reader deleting live instruments.
22//
23// DECLARED BLIND SPOTS, because a census that hides its own reach is worse than none:
24// * only .nx sources are scanned. A consumer that names a status file from a .conf, a cron row or a
25// shell fragment is INVISIBLE here, so a SINGLE-NAMER row is a QUESTION, not a verdict.
26// * a path assembled at runtime from a prefix and a variable is invisible by construction.
27// * a file read past the per-file cap contributes only its head, and those files are COUNTED.
28import "nx_syscalls.nx"
29
30const US_CLASS_NONE: i64 = 0
31const US_CLASS_SINGLE: i64 = 1
32const US_CLASS_SEVERAL: i64 = 2
33const US_CLASS_SHARD: i64 = 3
34const US_NAMECAP: i64 = 96
35const US_DOT: i64 = 46
36const US_DASH: i64 = 45
37const US_USCORE: i64 = 95
38const US_D0: i64 = 48
39const US_D9: i64 = 57
40const US_UA: i64 = 65
41const US_UZ: i64 = 90
42const US_LA: i64 = 97
43const US_LZ: i64 = 122
44
45func us_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
46
47// Which bytes may appear in a status filename. Deliberately EXCLUDES '/', so a match on a deeper path
48// stops at the directory boundary instead of swallowing it and inventing a filename nobody has.
49func us_isnamechar(c: i64) -> i64 {
50 if c >= US_D0 { if c <= US_D9 { return 1 } }
51 if c >= US_UA { if c <= US_UZ { return 1 } }
52 if c >= US_LA { if c <= US_LZ { return 1 } }
53 if c == US_DOT { return 1 }
54 if c == US_DASH { return 1 }
55 if c == US_USCORE { return 1 }
56 return 0
57}
58
59// Search [from, n) for a NUL-terminated needle. Returns the offset or -1.
60// Takes `from` so a caller can walk EVERY occurrence in a file: a scan that stops at the first hit would
61// count one reference per source no matter how many distinct artifacts it names.
62func us_find_from(buf: *u8, n: i64, from: i64, needle: *u8) -> i64 {
63 let kl: i64 = us_len(needle)
64 if kl == 0 { return 0 - 1 }
65 var i: i64 = from
66 if i < 0 { i = 0 }
67 while i + kl <= n {
68 var j: i64 = 0
69 var bad: i64 = 0
70 while j < kl {
71 if buf[i + j] != needle[j] { bad = 1 }
72 j = j + 1
73 }
74 if bad == 0 { return i }
75 i = i + 1
76 }
77 return 0 - 1
78}
79
80// Copy the filename token starting at `pos` into out (NUL-terminated). Returns its length, or 0 when
81// there is no name character there at all -- which is the "knowledge/status/" prefix appearing with
82// nothing usable after it, and must not be recorded as a nameless artifact.
83func us_name_at(buf: *u8, n: i64, pos: i64, out: *u8, cap: i64) -> i64 {
84 var i: i64 = pos
85 var k: i64 = 0
86 var go: i64 = 1
87 while go == 1 {
88 if i >= n { go = 0 }
89 if go == 1 { if us_isnamechar(buf[i] as i64) == 0 { go = 0 } }
90 if go == 1 {
91 if k < cap - 1 { out[k] = buf[i]; k = k + 1 }
92 i = i + 1
93 }
94 }
95 out[k] = 0 as u8
96 return k
97}
98
99func us_streq(a: *u8, b: *u8) -> i64 {
100 var i: i64 = 0
101 while a[i] != (0 as u8) {
102 if a[i] != b[i] { return 0 }
103 i = i + 1
104 }
105 if b[i] != (0 as u8) { return 0 }
106 return 1
107}
108
109// Index of `name` in a packed name table, or -1.
110func us_tbl_find(names: *u8, stride: i64, n: i64, name: *u8) -> i64 {
111 var i: i64 = 0
112 while i < n {
113 let e: *u8 = ((names as i64) + i * stride) as *u8
114 if us_streq(e, name) == 1 { return i }
115 i = i + 1
116 }
117 return 0 - 1
118}
119
120// Does this name belong to a seg-store shard family?
121// Those are opened from a string COMPUTED AT RUNTIME as "<prefix>-seg-<n>.<ext>", so a literal reference
122// to one is impossible BY CONSTRUCTION and counting them as unreferenced buries the real finding under
123// its own noise. ★ READ EVERY EARLY HIT AS A CANDIDATE BUCKET RATHER THAN SUPPRESSING IT: this class was
124// 238 of 257 rows on the very first live run, and a detector whose output is 93 percent one known,
125// uninteresting shape is a false-positive machine that teaches everyone to ignore it.
126// The test is structural, not an extension blocklist: "-seg-" followed by a digit, or a "-slock" tail.
127func us_is_store_shard(name: *u8) -> i64 {
128 let n: i64 = us_len(name)
129 var i: i64 = 0
130 while i + 5 <= n {
131 if name[i] == (US_DASH as u8) {
132 if name[i+1] == (115 as u8) { if name[i+2] == (101 as u8) { if name[i+3] == (103 as u8) {
133 if name[i+4] == (US_DASH as u8) {
134 if i + 5 < n {
135 let d: i64 = name[i+5] as i64
136 if d >= US_D0 { if d <= US_D9 { return 1 } }
137 }
138 }
139 } } }
140 }
141 i = i + 1
142 }
143 // The rest of the store family: a per-store lock and a manifest, both opened from the SAME computed
144 // prefix. They were 26 of the 36 rows left after the shard rule landed, and adding them is
145 // CLASSIFICATION, not suppression -- they fail a literal-reference test for exactly the structural
146 // reason the shards do, and a bucket that admits one and not the others is arbitrary.
147 if n >= 6 {
148 if name[n-6] == (US_DASH as u8) {
149 if name[n-4] == (108 as u8) { if name[n-3] == (111 as u8) {
150 if name[n-2] == (99 as u8) { if name[n-1] == (107 as u8) {
151 if name[n-5] == (115 as u8) { return 1 }
152 if name[n-5] == (112 as u8) { return 1 }
153 } }
154 } }
155 }
156 }
157 if n >= 14 {
158 if us_streq(((name as i64) + n - 13) as *u8, "-manifest.txt" as *u8) == 1 { return 1 }
159 }
160 return 0
161}
162
163// Is this artifact the running organ OWN bookkeeping? An instrument that counts its own output measures
164// itself: this census writes a ratchet baseline into the very directory it censuses, so without this the
165// first run creates a new SINGLE-NAMER, the second run reports its own baseline as a suspicious sensor,
166// and the ratchet is permanently RED on a file it created. Passed IN rather than hardcoded, so there is
167// one literal for that filename in the estate and it lives beside the code that writes it.
168func us_is_self(name: *u8, selfname: *u8) -> i64 { return us_streq(name, selfname) }
169
170// name + refs -> class. THE ONE classifier, so the census counts and the printed rows cannot disagree.
171// The shard test runs FIRST because it is decided by the name alone and no reference count can be true
172// of it: a shard with two accidental namers is still a shard.
173func us_classify(name: *u8, refs: i64) -> i64 {
174 if us_is_store_shard(name) == 1 { return US_CLASS_SHARD }
175 if refs <= 0 { return US_CLASS_NONE }
176 if refs == 1 { return US_CLASS_SINGLE }
177 return US_CLASS_SEVERAL
178}
179
180func us_class_name(c: i64) -> *u8 {
181 if c == US_CLASS_NONE { return "NO-LITERAL-REFERENCE" as *u8 }
182 if c == US_CLASS_SINGLE { return "SINGLE-NAMER" as *u8 }
183 if c == US_CLASS_SHARD { return "STORE-FAMILY-prefix-addressed" as *u8 }
184 return "NAMED-BY-SEVERAL" as *u8
185}