nx_dyna_bind_skin_gate.nx source
↩ module page · 362 lines · 20685 B
1// nx_dyna_bind_skin_gate.nx -- THE MOTION GATE: one tooth per NAMED failure mode, every bound READ
2// FROM knowledge/gamefeel_oracle.conf, never written here.
3//
4// WHY THE TEETH ARE SHAPED THIS WAY. The operator's bar is that the motion be best-of-breed and
5// that previous attempts were awful. "Awful" is not one thing, so a single "it deformed" tooth
6// would pass the exact solver we are trying to beat. Each recognisable way secondary motion reads
7// as wrong therefore gets its OWN tooth with its OWN derived bound:
8// dead -- no visible secondary motion. Tooth: the excitation must actually reach the plant.
9// jelly -- under-damped, never settles. Tooth: residual excursion must decay.
10// buzzing -- unstable at the substep. Tooth: the measured natural frequency must be far below
11// the sampling rate; a plant that "oscillates" AT the sample rate is quantization
12// chatter, which is exactly the defect this lane hit and fixed on 2026-08-23.
13// unobservable -- a profile whose response does not complete a period inside the window. Tooth:
14// that must report UNOBSERVABLE and must NOT be scored as a pass. An instrument
15// that cannot see must abstain, never acquit.
16// swimming/symmetry -- the binding must DISCRIMINATE: some skin vertices bound to a region and
17// some skin-locked. Both signals present at once, or the tooth proves nothing.
18// The plant-vs-subject comparison (fn, zeta) is REPORTED against the cited bands. It is deliberately
19// NOT a pass/fail tooth in this gate: knowledge/gamefeel_oracle.conf itself records that our two
20// shipped profiles bracket the human band, so failing the build on it would be failing on a
21// modelling result rather than on a regression. The numbers are printed every run so the movement
22// is visible, and the ratchet belongs in the profile lane that owns those constants.
23//
24// SUBJECT: ./nx_dyna_bind_skin.elf -- the promoted binary, forked. Subprocess capture comes from
25// nx_gatekit_lib because a hand-rolled pipe DEADLOCKED a sibling gate in production today
26// (pid 2240, 50+ minutes in pipe_wait). Never re-roll that plumbing.
27// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
28import "nx_syscalls.nx"
29import "nx_gate_verdict.nx"
30import "nx_gatekit_lib.nx"
31
32const DG_ELF: *u8 = "./nx_dyna_bind_skin.elf"
33const DG_CONF: *u8 = "knowledge/gamefeel_oracle.conf"
34const DG_CAP: i64 = 65536
35const DG_AMP_CMM: i64 = 3200
36
37// Sample geometry of the probe, mirrored here ONLY to derive the buzz bound. The probe samples one
38// point per solver reference step, so its Nyquist limit is half that rate; a plant reporting a
39// natural frequency anywhere near it is chatter, not physics. Nyquist is arithmetic, not a taste.
40const DG_DT_US: i64 = 4167
41const DG_US_PER_S: i64 = 1000000
42const DG_MHZ: i64 = 1000
43// SIGN CHANGES NEEDED BEFORE A PERIOD EXISTS. DERIVED FROM THE SUBJECT, NOT CHOSEN: dbs_analyze
44// records the first three sign changes as c1/c2/c3 and sets fn_mhz ONLY inside
45// `if c1 > 0 { if c3 > c1 {`, because c1 -> c3 is what spans one full period. So three crossings
46// is exactly the subject's own precondition for reporting a frequency at all -- change that shape
47// and this number must move with it.
48const DG_CROSS_FOR_PERIOD: i64 = 3
49
50func dg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
51
52// read a "key<TAB>min<TAB>max<TAB>..." row, ANCHORED at line start so a key appearing inside a
53// source field can never be mistaken for a row. Explicit stop flags: clobbering the cursor to exit
54// a scan is the banked sentinel defect and it destroys the very position the caller needs.
55func dg_band(b: *u8, n: i64, key: *u8, out: *i64) -> i64 {
56 let kl: i64 = dg_slen(key)
57 var i: i64 = 0
58 var at_ls: i64 = 1
59 var found: i64 = 0
60 while i < n {
61 if found == 0 {
62 if at_ls == 1 {
63 var hit_k: i64 = 1
64 var m: i64 = 0
65 while m < kl {
66 if i + m >= n { hit_k = 0; m = kl }
67 else {
68 if b[i + m] != key[m] { hit_k = 0; m = kl }
69 else { m = m + 1 }
70 }
71 }
72 if hit_k == 1 {
73 if i + kl < n {
74 if b[i + kl] == (9 as u8) {
75 var p: i64 = i + kl + 1
76 var v1: i64 = 0
77 var st1: i64 = 0
78 while st1 == 0 {
79 if p >= n { st1 = 1 }
80 else {
81 let c: i64 = b[p] as i64
82 if c >= 48 {
83 if c <= 57 { v1 = v1 * 10 + (c - 48); p = p + 1 }
84 else { st1 = 1 }
85 } else { st1 = 1 }
86 }
87 }
88 if p < n {
89 if b[p] == (9 as u8) {
90 var q: i64 = p + 1
91 var v2: i64 = 0
92 var st2: i64 = 0
93 while st2 == 0 {
94 if q >= n { st2 = 1 }
95 else {
96 let c2: i64 = b[q] as i64
97 if c2 >= 48 {
98 if c2 <= 57 { v2 = v2 * 10 + (c2 - 48); q = q + 1 }
99 else { st2 = 1 }
100 } else { st2 = 1 }
101 }
102 }
103 out[0] = v1
104 out[1] = v2
105 found = 1
106 }
107 }
108 }
109 }
110 }
111 }
112 if b[i] == (10 as u8) { at_ls = 1 } else { at_ls = 0 }
113 }
114 i = i + 1
115 }
116 return found
117}
118
119// pull the integer that follows a key inside the probe's own output line
120func dg_after(buf: *u8, n: i64, key: *u8) -> i64 {
121 let kl: i64 = dg_slen(key)
122 var i: i64 = 0
123 while i + kl < n {
124 var m: i64 = 0
125 var hit_k: i64 = 1
126 while m < kl {
127 if buf[i + m] != key[m] { hit_k = 0; m = kl } else { m = m + 1 }
128 }
129 if hit_k == 1 {
130 var p: i64 = i + kl
131 var neg: i64 = 0
132 if p < n { if buf[p] == (45 as u8) { neg = 1; p = p + 1 } }
133 var v: i64 = 0
134 var st: i64 = 0
135 var got: i64 = 0
136 while st == 0 {
137 if p >= n { st = 1 }
138 else {
139 let c: i64 = buf[p] as i64
140 if c >= 48 {
141 if c <= 57 { v = v * 10 + (c - 48); p = p + 1; got = 1 }
142 else { st = 1 }
143 } else { st = 1 }
144 }
145 }
146 if got == 1 { if neg == 1 { return 0 - v } return v }
147 }
148 i = i + 1
149 }
150 return 0 - 1
151}
152
153func dg_ringdown(prof: *u8, buf: *u8, blen: *i64) -> i64 {
154 return gk_run_capture(DG_ELF, "ringdown" as *u8, prof, "3200" as *u8, 0 as *u8, buf, DG_CAP, blen)
155}
156
157func dg_ringdown_amp(prof: *u8, amp: *u8, buf: *u8, blen: *i64) -> i64 {
158 return gk_run_capture(DG_ELF, "ringdown" as *u8, prof, amp, 0 as *u8, buf, DG_CAP, blen)
159}
160
161func main(argc: i64, argv: *i64) -> i64 {
162 let ctr: *i64 = gv_ctr()
163 gv_puts("nx_dyna_bind_skin_gate -- one tooth per named motion failure mode, bounds read from the conf\n\n" as *u8)
164
165 // ---- bounds come from the conf, never from this file ----
166 let clp: *i64 = sys_mmap(16) as *i64
167 let cb: *u8 = sys_read_file(DG_CONF, clp)
168 var have_conf: i64 = 0
169 if (cb as i64) != 0 { have_conf = 1 }
170 gv_check("conf-readable (bounds are DATA; a gate that cannot read them must not invent them)" as *u8, have_conf, ctr)
171 let band: *i64 = sys_mmap(32) as *i64
172 var fn_lo: i64 = 0
173 var fn_hi: i64 = 0
174 var ze_lo: i64 = 0
175 var ze_hi: i64 = 0
176 var amp_lo: i64 = 0
177 var amp_hi: i64 = 0
178 if have_conf == 1 {
179 let n: i64 = clp[0]
180 if dg_band(cb, n, "tissue_fn_mhz" as *u8, band) == 1 { fn_lo = band[0]; fn_hi = band[1] }
181 if dg_band(cb, n, "tissue_zeta_permil" as *u8, band) == 1 { ze_lo = band[0]; ze_hi = band[1] }
182 if dg_band(cb, n, "tissue_amp_walk_mm" as *u8, band) == 1 { amp_lo = band[0]; amp_hi = band[1] }
183 }
184 gv_puts(" subject rows: tissue_fn_mhz=" as *u8); gv_num(fn_lo); gv_puts(".." as *u8); gv_num(fn_hi)
185 gv_puts(" tissue_zeta_permil=" as *u8); gv_num(ze_lo); gv_puts(".." as *u8); gv_num(ze_hi)
186 gv_puts(" tissue_amp_walk_mm=" as *u8); gv_num(amp_lo); gv_puts(".." as *u8); gv_num(amp_hi); gv_puts("\n" as *u8)
187 var rows_ok: i64 = 0
188 if fn_lo > 0 { if ze_lo > 0 { if amp_lo > 0 { rows_ok = 1 } } }
189 gv_check("all-three-subject-rows-present (an absent row must not read as a zero bound)" as *u8, rows_ok, ctr)
190
191 let buf: *u8 = sys_mmap(DG_CAP)
192 let bl: *i64 = sys_mmap(16) as *i64
193
194 // ---- LARGE_SOFT: the operator's primary case ----
195 let rc0: i64 = dg_ringdown("0" as *u8, buf, bl)
196 gv_check("probe-runs-and-exits-zero (127 = the elf is absent, the stale-offc tell)" as *u8, rc0 == 0, ctr)
197 let n0: i64 = bl[0]
198 let cell0: i64 = dg_after(buf, n0, "cell_mm=" as *u8)
199 let mx0: i64 = dg_after(buf, n0, "maxabs_cmm=" as *u8)
200 let rs0: i64 = dg_after(buf, n0, "residual_cmm=" as *u8)
201 let fn0: i64 = dg_after(buf, n0, "fn_mhz=" as *u8)
202 let ze0: i64 = dg_after(buf, n0, "zeta_permil=" as *u8)
203 let cr0: i64 = dg_after(buf, n0, "crossings=" as *u8)
204 gv_puts(" [LARGE_SOFT] cell_mm=" as *u8); gv_num(cell0)
205 gv_puts(" maxabs_cmm=" as *u8); gv_num(mx0)
206 gv_puts(" residual_cmm=" as *u8); gv_num(rs0)
207 gv_puts(" crossings=" as *u8); gv_num(cr0)
208 gv_puts(" fn_mhz=" as *u8); gv_num(fn0)
209 gv_puts(" zeta_permil=" as *u8); gv_num(ze0); gv_puts("\n" as *u8)
210
211 // the lattice step must be DERIVED, and a derived step is a real one
212 gv_check("lattice-step-derived-and-nondegenerate (a one-cell cage silently reports zeros)" as *u8, cell0 > 0, ctr)
213
214 // ANTI-VACUITY: the excitation must actually reach the plant, or every later tooth is vacuous.
215 // Bound: the response must reach at least half the commanded amplitude. Half is not a taste --
216 // it is the point at which the plant has absorbed more of the excitation than it returned, so
217 // anything below it means the drive never coupled.
218 gv_check("fixture-reached-the-condition (the excitation actually moved the plant)" as *u8, mx0 > DG_AMP_CMM / 2, ctr)
219
220 // DEAD: the walking excitation is a REAL measured amplitude (tissue_amp_walk_mm). If the plant
221 // cannot express it, the motion reads as dead. Bound is the conf row, converted mm -> cmm.
222 var dead_ok: i64 = 0
223 if amp_lo > 0 { if mx0 >= amp_lo * 100 / 2 { dead_ok = 1 } }
224 gv_check("not-DEAD (response reaches the measured walking amplitude scale)" as *u8, dead_ok, ctr)
225
226 // JELLY: after the window the excursion must have collapsed. Bound: the residual must be under
227 // one part in a hundred of the peak -- derived from the peak itself, so it scales with any
228 // excitation rather than pinning a length.
229 var jelly_ok: i64 = 0
230 if mx0 > 0 { if rs0 * 100 < mx0 { jelly_ok = 1 } }
231 gv_check("not-JELLY (residual decayed to under one percent of peak)" as *u8, jelly_ok, ctr)
232
233 // BUZZ: a plant reporting a natural frequency near the sampling Nyquist is quantization
234 // chatter, not tissue. This tooth is the regression guard for the exact defect measured and
235 // fixed on 2026-08-23, when an extrema detector reported fn == the sample rate.
236 let nyq_mhz: i64 = DG_US_PER_S * DG_MHZ / (2 * DG_DT_US)
237 var buzz_ok: i64 = 0
238 if fn0 > 0 { if fn0 * 4 < nyq_mhz { buzz_ok = 1 } }
239 gv_puts(" nyquist_mhz=" as *u8); gv_num(nyq_mhz); gv_puts("\n" as *u8)
240 gv_check("not-BUZZING (natural frequency far below the sampling Nyquist)" as *u8, buzz_ok, ctr)
241
242 // DETERMINISM: same command, same numbers. A stochastic solver cannot be gated at all.
243 let buf2: *u8 = sys_mmap(DG_CAP)
244 let bl2: *i64 = sys_mmap(16) as *i64
245 let rc0b: i64 = dg_ringdown("0" as *u8, buf2, bl2)
246 let fn0b: i64 = dg_after(buf2, bl2[0], "fn_mhz=" as *u8)
247 let ze0b: i64 = dg_after(buf2, bl2[0], "zeta_permil=" as *u8)
248 var det_ok: i64 = 0
249 if rc0b == 0 { if fn0b == fn0 { if ze0b == ze0 { det_ok = 1 } } }
250 gv_check("DETERMINISTIC (same command, identical fn and zeta)" as *u8, det_ok, ctr)
251
252 // UNOBSERVABLE IS NOT A PASS -- AND THIS TOOTH NOW ASSERTS THE CONTRACT, NOT ONE OBSERVATION.
253 // WHAT IT USED TO SAY, AND WHY IT WENT RED (measured 2026-08-28, gate read 14/15):
254 // `if fn2 == 0 { abst_ok = 1 }`, on the premise that "GLUTE is heavily damped and does not
255 // complete a period inside the window". Measured directly on the live binary, GLUTE now reads
256 // crossings=8 fn_mhz=3333 period_us=300024 -- so the PREMISE IS STALE and the tooth was
257 // failing because THE PLANT BECAME MORE OBSERVABLE, which reads exactly like a regression.
258 // ★A TOOTH THAT PINS A MEASURED VALUE INSTEAD OF THE INVARIANT IT PROTECTS GOES RED WHEN ITS
259 // SUBJECT IMPROVES, AND THE RED IS INDISTINGUISHABLE FROM A REAL FAULT.
260 // THE INVARIANT is that the organ must never report a frequency it did not observe. dbs_analyze
261 // sets fn ONLY once c1->c3 spans a full period, so `fn > 0` and `crossings >= DG_CROSS_FOR_PERIOD`
262 // are the SAME claim: either one true without the other is a FABRICATED or a SUPPRESSED reading.
263 // Asserted as a biconditional, so it holds for ANY profile and cannot go stale on a solver fix.
264 let buf3: *u8 = sys_mmap(DG_CAP)
265 let bl3: *i64 = sys_mmap(16) as *i64
266 let rc2: i64 = dg_ringdown("2" as *u8, buf3, bl3)
267 let n2: i64 = bl3[0]
268 let fn2: i64 = dg_after(buf3, n2, "fn_mhz=" as *u8)
269 let mx2: i64 = dg_after(buf3, n2, "maxabs_cmm=" as *u8)
270 let cr2: i64 = dg_after(buf3, n2, "crossings=" as *u8)
271 gv_puts(" [GLUTE] maxabs_cmm=" as *u8); gv_num(mx2)
272 gv_puts(" crossings=" as *u8); gv_num(cr2)
273 gv_puts(" fn_mhz=" as *u8); gv_num(fn2); gv_puts("\n" as *u8)
274 // dg_after returns -1 for a field absent from the output. Without this conjunct a MISSING
275 // crossings= would read as "fewer than three" and would SATISFY the abstain arm below -- a
276 // tooth passing because it could not look.
277 var have_cr2: i64 = 0
278 if cr2 >= 0 { have_cr2 = 1 }
279 gv_check("crossings-field-present (a tooth must not be satisfied by a field it failed to parse)" as *u8, have_cr2, ctr)
280 var abst_ok: i64 = 0
281 if rc2 == 0 { if mx2 > 0 { if have_cr2 == 1 {
282 if fn2 == 0 { if cr2 < DG_CROSS_FOR_PERIOD { abst_ok = 1 } }
283 if fn2 > 0 { if cr2 >= DG_CROSS_FOR_PERIOD { abst_ok = 1 } }
284 } } }
285 gv_check("period-report-matches-period-evidence (fn>0 IFF a full period was actually observed: no fabricated frequency, and no suppressed one)" as *u8, abst_ok, ctr)
286 // HONEST SCOPE, NAMED RATHER THAN HIDDEN: with GLUTE now completing 8 crossings, NO shipped
287 // profile exercises the fn==0 arm of that biconditional today, so the tooth is ONE-SIDED ON
288 // CURRENT DATA. The arm is kept because it costs nothing and re-arms itself the moment any
289 // profile stops completing a period -- and the run says which arm it took.
290 if fn2 == 0 { gv_puts(" NOTE: GLUTE abstained (fn=0) -- the UNOBSERVABLE arm WAS exercised this run\n" as *u8) }
291 if fn2 > 0 { gv_puts(" NOTE: GLUTE completes a period on this build, so the UNOBSERVABLE arm of the abstention contract is NOT exercised by any shipped profile today\n" as *u8) }
292
293 // NEG-CONTROL: a profile index the solver has no table for must REFUSE, not return a silent
294 // zero-motion pass. Good leg is the real profile that must NOT refuse.
295 let buf4: *u8 = sys_mmap(DG_CAP)
296 let bl4: *i64 = sys_mmap(16) as *i64
297 let rcbad: i64 = dg_ringdown("99" as *u8, buf4, bl4)
298 gv_bite("neg-control-unknown-profile-refused-and-real-profile-admitted" as *u8, rcbad != 0, rc0 != 0, ctr)
299
300 // ---- THE LINEAR LIMIT: compare like with like -------------------------------------------
301 // WHY A SMALL AMPLITUDE IS THE CORRECT ONE, AND WHY IT IS NOT TUNING TO HIT THE BAND. The
302 // subject row tissue_fn_mhz carries its own provenance: "free-vibration-modes". A free
303 // vibration IS a small-amplitude measurement. Exciting our plant at tissue_amp_walk_mm (a
304 // DRIVEN walking excursion of 32 mm) and comparing that to a free-vibration band was a
305 // category error in the PROBE, not a property of the solver. Measured 2026-08-23 on
306 // LARGE_SOFT: at 32 mm the up/down ratio is 1.139 and fn sits BELOW the band; at 3.2 mm the
307 // ratio is 1.017 and fn sits INSIDE it. The amplitude is therefore DERIVED FROM THE BAND'S
308 // OWN PROVENANCE, and the linearity tooth below is what keeps that honest rather than
309 // convenient: if the branches did NOT converge we would not be in the regime the subject was
310 // measured in, and no comparison would be admissible at all.
311 let bs: *u8 = sys_mmap(DG_CAP)
312 let bls: *i64 = sys_mmap(16) as *i64
313 let bd: *u8 = sys_mmap(DG_CAP)
314 let bld: *i64 = sys_mmap(16) as *i64
315 let rcu: i64 = dg_ringdown_amp("0" as *u8, "320" as *u8, bs, bls)
316 let rcd: i64 = dg_ringdown_amp("0" as *u8, "-320" as *u8, bd, bld)
317 let fnu: i64 = dg_after(bs, bls[0], "fn_mhz=" as *u8)
318 let fnd: i64 = dg_after(bd, bld[0], "fn_mhz=" as *u8)
319 let zeu: i64 = dg_after(bs, bls[0], "zeta_permil=" as *u8)
320 let zed: i64 = dg_after(bd, bld[0], "zeta_permil=" as *u8)
321 let mxu: i64 = dg_after(bs, bls[0], "maxabs_cmm=" as *u8)
322 let mxd: i64 = dg_after(bd, bld[0], "maxabs_cmm=" as *u8)
323 gv_puts(" [LINEAR LIMIT +-320 cmm] up fn=" as *u8); gv_num(fnu)
324 gv_puts(" zeta=" as *u8); gv_num(zeu)
325 gv_puts(" maxabs=" as *u8); gv_num(mxu)
326 gv_puts(" | down fn=" as *u8); gv_num(fnd)
327 gv_puts(" zeta=" as *u8); gv_num(zed)
328 gv_puts(" maxabs=" as *u8); gv_num(mxd); gv_puts("\n" as *u8)
329
330 // FIXTURE-REACHED, BOTH SIGNS. The absence of exactly this check is what let the probe excite
331 // upward only, measure one branch of an asymmetric plant, and report it as the whole -- the
332 // coverage error corrected on 2026-08-23. This gate cannot repeat it.
333 var both_excited: i64 = 0
334 if rcu == 0 { if rcd == 0 { if mxu > 0 { if mxd > 0 { both_excited = 1 } } } }
335 gv_check("fixture-reached-BOTH-signs (a one-sided sweep measures one branch and reports it as the plant)" as *u8, both_excited, ctr)
336
337 // LINEARITY: branches must converge at small amplitude. Bound is one tenth -- a tenth is the
338 // scale at which the measured ratio (1.017) is unambiguously separated from the large-
339 // amplitude ratio (1.139), so it discriminates the two regimes we actually observed.
340 var lin_ok: i64 = 0
341 if fnu > 0 { if fnd > 0 {
342 var hi: i64 = fnu
343 var lo: i64 = fnd
344 if fnd > fnu { hi = fnd; lo = fnu }
345 if (hi - lo) * 10 < lo { lin_ok = 1 }
346 } }
347 gv_check("LINEAR-REGIME-REACHED (branches converge, so the free-vibration band is applicable)" as *u8, lin_ok, ctr)
348
349 var inband_fn: i64 = 0
350 if lin_ok == 1 { if fnu >= fn_lo { if fnu <= fn_hi { if fnd >= fn_lo { if fnd <= fn_hi { inband_fn = 1 } } } } }
351 gv_check("plant-fn-IN-SUBJECT-BAND-at-the-linear-limit (both branches)" as *u8, inband_fn, ctr)
352 var inband_ze: i64 = 0
353 if lin_ok == 1 { if zeu >= ze_lo { if zeu <= ze_hi { if zed >= ze_lo { if zed <= ze_hi { inband_ze = 1 } } } } }
354 gv_check("plant-zeta-IN-SUBJECT-BAND-at-the-linear-limit (both branches)" as *u8, inband_ze, ctr)
355
356 gv_puts("\n PLANT vs SUBJECT (reported, not gated -- the profile constants are owned elsewhere):\n" as *u8)
357 gv_puts(" LARGE_SOFT fn=" as *u8); gv_num(fn0); gv_puts(" mhz vs band " as *u8); gv_num(fn_lo)
358 gv_puts(".." as *u8); gv_num(fn_hi); gv_puts(" zeta=" as *u8); gv_num(ze0)
359 gv_puts(" permil vs band " as *u8); gv_num(ze_lo); gv_puts(".." as *u8); gv_num(ze_hi); gv_puts("\n" as *u8)
360
361 return gv_verdict("NX-DYNA-BIND-SKIN" as *u8, ctr, "secondary motion is measured against cited biomechanics, and each way it can read as awful has its own tooth" as *u8)
362}