code wiki / (root) / nx_nxa_retarget_gate.nx

nx_nxa_retarget_gate.nx source

↩ module page · 252 lines · 18208 B

1// nx_nxa_retarget_gate.nx -- THE DONOR RETARGET GATE: handedness is DERIVED, limb length is 2// preserved BY CONSTRUCTION, and a witness that cannot testify ABSTAINS BY NAME. 3// 4// WHY ITS NEGATIVE CONTROLS ARE STRONGER THAN ANY MUTANT I COULD CONSTRUCT: every RED below is a 5// REAL DEFECT THIS ORGAN ACTUALLY SHIPPED AND THIS LANE ACTUALLY CAUGHT, on the real corpus, within 6// hours. Nothing here is synthetic. 7// - CHIRALITY. Before the mesh-derived anterior cue, frame_det came out +1 / +1 / -1 / -1 across 8// four ordinary humanoids -- i.e. TWO OF FOUR DONORS WERE POSED MIRRORED, left and right 9// swapped, and NO LIMB-LENGTH TOOTH COULD CATCH IT because a mirror preserves every length it 10// checks. The cause: handedness was resolved by argmin over mapping distance, and a bilaterally 11// symmetric point set (every rig here scores sym_permil=1000) is near-ISOMETRIC UNDER MIRRORING, 12// so both options tie and the argmin picks arbitrarily. 13// - VACUOUS BANDS. The anterior cue takes two witnesses, a foot band and a head band, and requires 14// them to agree. With the band height derived from GLOBAL mean joint spacing, paladin measured 15// foot=head=2184 and dark_knight foot=head=-140 -- BYTE-IDENTICAL, because both bands covered 16// the entire mesh. TWO WITNESSES THAT ARE SECRETLY THE SAME WITNESS AGREE ONE HUNDRED PERCENT 17// OF THE TIME. dark_knight's whole verdict rested on -140 units of whole-mesh noise. 18// - UNPOPULATED BANDS. Disjointness turned out to be NECESSARY BUT NOT SUFFICIENT: toon3d8's 19// toe-tip bone is 1 unit long, so its foot band held exactly 2 VERTICES and an entire handedness 20// verdict rested on them. A band must also be POPULATED, and the floor comes from the asset -- 21// a region holding fewer points than the rig has joints is stray vertices, not a shape. 22// 23// The three donors that now REFUSE are therefore the gate's own neg-controls: they prove the teeth 24// can fail, on real assets, for three DISTINCT named reasons. 25// 26// usage: nx_nxa_retarget_gate (no args -- reads the real corpus) 27// license_tier: ORIGINAL expect_exit: 0 28import "nx_syscalls.nx" 29import "nx_gate_verdict.nx" 30import "nx_gatekit_lib.nx" 31import "nx_tool_run.nx" 32 33const RG_ELF: *u8 = "./nx_nxa_retarget.elf" 34const RG_SRC: *u8 = "sites/nishifamily/world/ref9d.nxa" 35const RG_WITCH: *u8 = "knowledge/rigcorpus/dark_witch_rigged.nxa" 36const RG_KNIGHT: *u8 = "knowledge/rigcorpus/dark_knight_rigged.nxa" 37const RG_TOON: *u8 = "knowledge/rigcorpus/toon3d8_rigged.nxa" 38const RG_PAL: *u8 = "knowledge/rigcorpus/paladin_rigged.nxa" 39const RG_POSE: *u8 = "0" 40const RG_CAP: i64 = 65536 41// The organ's own exit codes (its source declares them; this gate does not invent them). 42const RG_EXIT_REFUSE: i64 = 3 43// ---- emit=pose teeth (2026-09-05, /compare/modding MD3) ------------------------------------------------ 44const RG_PLAY: *u8 = "./nx_nxa_play.elf" 45const RG_TMP: *u8 = "/tmp/nx_nxa_retarget_gate" 46const RG_TMP_MODE: i64 = 493 // 0755: gate scratch under /tmp/<gate>/, never a production path 47const RG_POSE_OUT: *u8 = "/tmp/nx_nxa_retarget_gate/witch_pose.nxa" 48const RG_POSE_OUT2: *u8 = "/tmp/nx_nxa_retarget_gate/witch_pose_again.nxa" 49const RG_BAKE_OUT: *u8 = "/tmp/nx_nxa_retarget_gate/witch_bake.nxa" 50const RG_EMIT: *u8 = "emit=pose" 51const RG_NOPOSE: *u8 = "777" // a pose id the emitted library does not hold: identity replay 52const RG_ARGVN: i64 = 8 53const RG_TMO_MS: i64 = 600000 // a hang guard, not a budget: a witch retarget measures in seconds 54const RG_PERMIL: i64 = 1000 55const RG_SQRT3_PERMIL: i64 = 1733 // player = MAX-AXIS displacement, retarget = EUCLIDEAN norm: axis <= norm <= sqrt(3)*axis, a geometric identity 56const RG_TOC_BYTES: i64 = 32 // one TOC entry (nx_nxa.nx: 4 words) 57const RG_POSE_HDR_W: i64 = 3 // POSE payload over an EMPTY library: [count, pose_id, nentries] then 8 words per entry 58const RG_WPE: i64 = 8 59 60// run an elf with up to six arguments (gk_run_capture carries four; emit=pose is the sixth), captured and bounded 61func rg_call(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8, a6: *u8, buf: *u8, cap: i64, bl: *i64) -> i64 { 62 let av: *i64 = sys_mmap(8 * RG_ARGVN) as *i64 63 av[0] = elf as i64; av[1] = a1 as i64; av[2] = a2 as i64; av[3] = a3 as i64 64 av[4] = a4 as i64; av[5] = a5 as i64; av[6] = a6 as i64; av[7] = 0 65 return tr_run_capture_to(elf, av, buf, cap, bl, RG_TMO_MS) 66} 67 68func rg_num_after(buf: *u8, n: i64, key: *u8) -> i64 { 69 let p: i64 = gk_out_pos(buf, n, key) 70 if p < 0 { return 0 - 1000000 } 71 var i: i64 = p + gk_len(key) 72 var neg: i64 = 0 73 if i < n { if buf[i] == (45 as u8) { neg = 1; i = i + 1 } } 74 var v: i64 = 0 75 var got: i64 = 0 76 while i < n { 77 let c: i64 = buf[i] as i64 78 if c < 48 { i = n } 79 if c > 57 { i = n } 80 if i < n { v = v * 10 + (c - 48); got = 1; i = i + 1 } 81 } 82 if got == 0 { return 0 - 1000000 } 83 if neg == 1 { return 0 - v } 84 return v 85} 86func rg_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } 87 88func main(argc: i64, argv: *i64) -> i64 { 89 let ctr: *i64 = gv_ctr() 90 gv_head("nx_nxa_retarget_gate -- handedness DERIVED, limb length preserved, a fake witness ABSTAINS" as *u8) 91 92 let buf: *u8 = sys_mmap(RG_CAP) 93 let bl: *i64 = sys_mmap(64) 94 95 // ---- the source's own frame must resolve, with TWO REAL witnesses ------------------------- 96 let rcw: i64 = gk_run_capture(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_WITCH, buf, RG_CAP, bl) 97 let nw: i64 = bl[0] 98 gv_check("subject-ran-and-produced-output (127 = elf absent, the stale-offc tell)" as *u8, nw > 0, ctr) 99 100 let sov: i64 = rg_num_after(buf, nw, "overlap=" as *u8) 101 let sant: i64 = rg_num_after(buf, nw, "src_anterior=" as *u8) 102 gv_puts(" src_anterior=" as *u8); gv_num(sant); gv_puts(" overlap=" as *u8); gv_num(sov); gv_puts("\n" as *u8) 103 gv_check("source-anterior-RESOLVES (a rig whose own front cannot be found drives nothing)" as *u8, sant != 0, ctr) 104 105 // ---- CHIRALITY: the historical defect was frame_det = -1 on two of four donors ------------- 106 let det: i64 = rg_num_after(buf, nw, "frame_det=" as *u8) 107 gv_puts(" frame_det=" as *u8); gv_num(det); gv_puts("\n" as *u8) 108 gv_check("chirality-frame-determinant-is-PLUS-ONE (a mirrored frame swaps left and right and no length tooth can see it)" as *u8, det == 1, ctr) 109 110 // ---- limb length: preserved BY CONSTRUCTION, so this is a REGRESSION guard ----------------- 111 let lim: i64 = rg_num_after(buf, nw, "limb_len_residual_max=" as *u8) 112 let mx: i64 = rg_num_after(buf, nw, "max_disp=" as *u8) 113 let mn: i64 = rg_num_after(buf, nw, "min_disp=" as *u8) 114 let spr: i64 = rg_num_after(buf, nw, "spread=" as *u8) 115 gv_puts(" limb_resid=" as *u8); gv_num(lim) 116 gv_puts(" max_disp=" as *u8); gv_num(mx) 117 gv_puts(" min_disp=" as *u8); gv_num(mn) 118 gv_puts(" spread=" as *u8); gv_num(spr); gv_puts("\n" as *u8) 119 gv_check("fixture-reached-the-condition (the run actually skinned a mesh and moved it)" as *u8, mx > 0, ctr) 120 // The bound is DERIVED from the motion the same run produced, never a picked tolerance: a 121 // transfer that stretched limbs would put the residual on the order of the motion itself. 122 // A direct dt-transfer -- the naive retarget this organ exists to refuse -- fails this loudly. 123 gv_check("limb-length-residual-is-a-small-fraction-of-the-motion (a dt-transfer retarget FAILS this)" as *u8, lim * 10 < mx, ctr) 124 125 // ---- motion must be JOINT-DRIVEN: a global translate moves every vertex equally ------------ 126 gv_check("motion-is-joint-driven-not-a-global-translate (spread collapses to zero if it is)" as *u8, spr > 0, ctr) 127 gv_check("spread-reconciles-with-its-own-endpoints (mx - mn == spread, a partition that must sum)" as *u8, mx - mn == spr, ctr) 128 129 // ---- the mapping partition must SUM -- a partition that does not sum is a leak ------------- 130 let mp: i64 = rg_num_after(buf, nw, "mapped=" as *u8) 131 let inh: i64 = rg_num_after(buf, nw, "inherited=" as *u8) 132 let oft: i64 = rg_num_after(buf, nw, " of=" as *u8) 133 gv_puts(" mapped=" as *u8); gv_num(mp); gv_puts(" inherited=" as *u8); gv_num(inh) 134 gv_puts(" of=" as *u8); gv_num(oft); gv_puts("\n" as *u8) 135 gv_check("mapped-plus-inherited-SUMS-to-the-joint-count" as *u8, mp + inh == oft, ctr) 136 gv_check("at-least-one-joint-is-actually-MAPPED (all-inherited is the bind pose wearing a retarget name)" as *u8, mp > 0, ctr) 137 gv_check("witch-retarget-exits-clean" as *u8, rcw == 0, ctr) 138 139 // ---- emit=pose: the output is a RIG WITH A LIBRARY, witnessed by the PLAYER, not a baked statue -------- 140 // MEASURED 2026-09-05: every baked donor read poses_in_library=0 joints_posed=0 under nx_nxa_play while the house 141 // rig read 104/104 -- the retarget was publishing statues. These teeth are the two-method-class proof the MD3 142 // rung owes: the retarget MEASURES the motion, the player REPLAYS it from the file and measures it again. 143 sys_mkdir(RG_TMP, RG_TMP_MODE) 144 let rcd: i64 = rg_call(RG_PLAY, RG_WITCH, RG_POSE, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, buf, RG_CAP, bl) 145 let nd: i64 = bl[0] 146 let dlib: i64 = rg_num_after(buf, nd, "poses_in_library=" as *u8) 147 gv_puts(" donor play rc=" as *u8); gv_num(rcd); gv_puts(" poses_in_library=" as *u8); gv_num(dlib); gv_puts("\n" as *u8) 148 gv_check_eq("fixture-reached-the-condition (the donor carries NO pose library before emit)" as *u8, dlib, 0, ctr) 149 150 let rcpo: i64 = rg_call(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_WITCH, RG_POSE_OUT, RG_EMIT, buf, RG_CAP, bl) 151 let npo: i64 = bl[0] 152 let pmode: i64 = gk_out_has(buf, npo, "mode=pose" as *u8) 153 let pent: i64 = rg_num_after(buf, npo, "entries=" as *u8) 154 let ppub: i64 = rg_num_after(buf, npo, "published=" as *u8) 155 gv_puts(" emit=pose rc=" as *u8); gv_num(rcpo); gv_puts(" mode_named=" as *u8); gv_num(pmode) 156 gv_puts(" entries=" as *u8); gv_num(pent); gv_puts(" published=" as *u8); gv_num(ppub); gv_puts("\n" as *u8) 157 gv_check("emit-pose-witch-exits-clean" as *u8, rcpo == 0, ctr) 158 gv_check("emit-pose-receipt-names-its-mode" as *u8, pmode, ctr) 159 gv_check_eq("emit-pose-entries-equal-the-target-joint-count" as *u8, pent, oft, ctr) 160 let dl: *i64 = sys_mmap(16) as *i64 161 let dbf: *u8 = sys_read_file(RG_WITCH, dl) 162 gv_check("donor-readable-for-the-size-prediction" as *u8, (dbf as i64) != 0, ctr) 163 gv_check_eq("emit-pose-bytes-equal-donor-plus-one-toc-entry-plus-payload (a partition that must sum)" as *u8, ppub, dl[0] + RG_TOC_BYTES + (RG_POSE_HDR_W + oft * RG_WPE) * 8, ctr) 164 165 let rcpl: i64 = rg_call(RG_PLAY, RG_POSE_OUT, RG_POSE, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, buf, RG_CAP, bl) 166 let npl: i64 = bl[0] 167 let plib: i64 = rg_num_after(buf, npl, "poses_in_library=" as *u8) 168 let pjp: i64 = rg_num_after(buf, npl, "joints_posed=" as *u8) 169 let pmx: i64 = rg_num_after(buf, npl, "max_disp_umm=" as *u8) 170 gv_puts(" player rc=" as *u8); gv_num(rcpl); gv_puts(" poses_in_library=" as *u8); gv_num(plib) 171 gv_puts(" joints_posed=" as *u8); gv_num(pjp); gv_puts(" max_disp_umm=" as *u8); gv_num(pmx); gv_puts("\n" as *u8) 172 gv_check("player-replays-the-emitted-file" as *u8, rcpl == 0, ctr) 173 gv_check_eq("player-sees-ONE-pose-in-the-library" as *u8, plib, 1, ctr) 174 gv_check_eq("player-poses-EVERY-target-joint (the baked form posed zero)" as *u8, pjp, oft, ctr) 175 gv_check("cross-witness-player-moved-the-mesh" as *u8, pmx > 0, ctr) 176 gv_check("cross-witness-player-max-axis-is-a-lower-bound-of-the-retarget-norm" as *u8, pmx <= mx, ctr) 177 gv_check("cross-witness-retarget-norm-within-sqrt3-of-the-player-max-axis (geometric identity, not a tolerance)" as *u8, mx * RG_PERMIL <= pmx * RG_SQRT3_PERMIL, ctr) 178 179 let rcid: i64 = rg_call(RG_PLAY, RG_POSE_OUT, RG_NOPOSE, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, buf, RG_CAP, bl) 180 let nid: i64 = bl[0] 181 let ijp: i64 = rg_num_after(buf, nid, "joints_posed=" as *u8) 182 let imx: i64 = rg_num_after(buf, nid, "max_disp_umm=" as *u8) 183 gv_puts(" identity replay rc=" as *u8); gv_num(rcid); gv_puts(" joints_posed=" as *u8); gv_num(ijp); gv_puts(" max_disp_umm=" as *u8); gv_num(imx); gv_puts("\n" as *u8) 184 gv_check_eq("identity-replay-poses-no-joint (an id the library lacks drives nothing)" as *u8, ijp, 0, ctr) 185 gv_check("emit-pose-leaves-VERT-at-bind (identity displacement under a thousandth of the motion: NOT baked)" as *u8, imx * RG_PERMIL < pmx, ctr) 186 187 let rcp2: i64 = rg_call(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_POSE_OUT, RG_POSE_OUT2, RG_EMIT, buf, RG_CAP, bl) 188 let np2b: i64 = bl[0] 189 let kept: i64 = rg_num_after(buf, np2b, "kept_poses=" as *u8) 190 let pub2: i64 = rg_num_after(buf, np2b, "published=" as *u8) 191 gv_puts(" re-emit rc=" as *u8); gv_num(rcp2); gv_puts(" kept_poses=" as *u8); gv_num(kept); gv_puts(" published=" as *u8); gv_num(pub2); gv_puts("\n" as *u8) 192 gv_check("re-emit-onto-the-emitted-file-exits-clean" as *u8, rcp2 == 0, ctr) 193 gv_check_eq("re-emit-same-id-keeps-ZERO-old-poses" as *u8, kept, 0, ctr) 194 gv_check_eq("re-emit-same-id-REPLACES-not-DUPLICATES (byte count unchanged)" as *u8, pub2, ppub, ctr) 195 196 let rcbk: i64 = rg_call(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_WITCH, RG_BAKE_OUT, 0 as *u8, buf, RG_CAP, bl) 197 let rcbp: i64 = rg_call(RG_PLAY, RG_BAKE_OUT, RG_POSE, 0 as *u8, 0 as *u8, 0 as *u8, 0 as *u8, buf, RG_CAP, bl) 198 let nbp: i64 = bl[0] 199 let blib: i64 = rg_num_after(buf, nbp, "poses_in_library=" as *u8) 200 gv_puts(" baked rc=" as *u8); gv_num(rcbk); gv_puts(" play rc=" as *u8); gv_num(rcbp); gv_puts(" poses_in_library=" as *u8); gv_num(blib); gv_puts("\n" as *u8) 201 gv_check("baked-mode-still-publishes (the incumbent contract is untouched)" as *u8, rcbk == 0, ctr) 202 gv_bite("neg-control-baked-mode-carries-NO-library (the statue this rung retires; the two modes are distinguishable)" as *u8, blib == 0, plib == 0, ctr) 203 204 // ---- NEG-CONTROL 1: dark_knight -- bands OVERLAP (the vacuous-witness defect) -------------- 205 let rck: i64 = gk_run_capture(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_KNIGHT, buf, RG_CAP, bl) 206 let nk: i64 = bl[0] 207 // RE-BASED 2026-08-23, and the reason is the point: the mesh-derived band FIXED the overlap this 208 // tooth used to catch, so pinning it to OVERLAP made it VACUOUS -- the gate said so itself 209 // ("did not fire on the bad input") rather than passing quietly. A neg-control must track a 210 // failure mode that STILL REPRODUCES. dark_knight still refuses, now for the honest remaining 211 // cause: a stronger head vote contradicting the foot, which is what a mis-placed-joint mesh 212 // produces. Its boneband/meshband ratio (48293/1094 and 51025/160) is the diagnostic. 213 let k_ov: i64 = gk_out_has(buf, nk, "AMBIGUOUS" as *u8) 214 gv_puts(" knight rc=" as *u8); gv_num(rck); gv_puts(" names_ambiguous=" as *u8); gv_num(k_ov); gv_puts("\n" as *u8) 215 gv_bite("neg-control-knight-anterior-AMBIGUOUS-refused-BY-NAME (a rig whose own front cannot be agreed drives nothing)" as *u8, k_ov, rcw != 0, ctr) 216 gv_check("knight-refusal-uses-the-organ-REFUSE-exit" as *u8, rck == RG_EXIT_REFUSE, ctr) 217 218 // ---- NEG-CONTROL 2: toon3d8 -- band too THIN (2 vertices held a whole verdict) ------------- 219 let rct: i64 = gk_run_capture(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_TOON, buf, RG_CAP, bl) 220 let nt2: i64 = bl[0] 221 // toon3d8 was a neg-control for the UNDERPOPULATED band (its 1-unit toe bone gave a 2-vertex 222 // window). The mesh-derived band sizes itself to hold enough vertices, so that defect no longer 223 // reproduces and toon RESOLVES. It is therefore a POSITIVE control now: coverage widening is 224 // the capability claim, so it is asserted rather than described. 225 let t_det: i64 = rg_num_after(buf, nt2, "frame_det=" as *u8) 226 gv_puts(" toon rc=" as *u8); gv_num(rct); gv_puts(" frame_det=" as *u8); gv_num(t_det); gv_puts("\n" as *u8) 227 gv_check("toon-RESOLVES-under-the-mesh-derived-band (it abstained under the bone-derived one)" as *u8, rct == 0, ctr) 228 gv_check("toon-frame-determinant-is-PLUS-ONE (widened coverage must not widen it to a mirror)" as *u8, t_det == 1, ctr) 229 230 // ---- NEG-CONTROL 3: paladin -- bands OVERLAP, a SECOND asset proving the same tooth -------- 231 let rcp: i64 = gk_run_capture(RG_ELF, "retarget" as *u8, RG_SRC, RG_POSE, RG_PAL, buf, RG_CAP, bl) 232 let np2: i64 = bl[0] 233 // paladin was the second OVERLAP neg-control and it too now RESOLVES: its bone bands were 234 // 74484/74424 against mesh bands of 56/78 -- a ratio above 1000x, which is the same mis-placed 235 // extremity-joint signature dark_knight shows. Positive control now, with the determinant 236 // asserted so widening coverage cannot smuggle in a mirrored frame. 237 let p_det: i64 = rg_num_after(buf, np2, "frame_det=" as *u8) 238 gv_puts(" paladin rc=" as *u8); gv_num(rcp); gv_puts(" frame_det=" as *u8); gv_num(p_det); gv_puts("\n" as *u8) 239 gv_check("paladin-RESOLVES-under-the-mesh-derived-band (coverage 1 donor -> 3)" as *u8, rcp == 0, ctr) 240 gv_check("paladin-frame-determinant-is-PLUS-ONE" as *u8, p_det == 1, ctr) 241 242 // ---- the identity-bind convention the whole four-line algorithm rests on ------------------- 243 let rcb: i64 = gk_run_capture(RG_ELF, "bindquats" as *u8, RG_SRC, 0 as *u8, 0 as *u8, buf, RG_CAP, bl) 244 let nb: i64 = bl[0] 245 let holds: i64 = gk_out_has(buf, nb, "identity_bind_convention=HOLDS" as *u8) 246 let nonid: i64 = rg_num_after(buf, nb, "nonidentity_bind_quats=" as *u8) 247 gv_puts(" bindquats rc=" as *u8); gv_num(rcb); gv_puts(" nonidentity=" as *u8); gv_num(nonid); gv_puts("\n" as *u8) 248 gv_check("identity-bind-convention-MEASURED-not-assumed (the four-line form is invalid without it)" as *u8, holds, ctr) 249 gv_check("bindquats-reports-zero-nonidentity-quats" as *u8, nonid == 0, ctr) 250 251 return gv_verdict("NX-NXA-RETARGET" as *u8, ctr, "handedness is derived from an asymmetric mesh cue, limb length is preserved by construction, and a witness that cannot testify abstains by name" as *u8) 252}