code wiki / _hdl_build / nx_train_triage_gate.nx
nx_train_triage_gate.nx source
↩ module page · 104 lines · 5164 B
1// nx_train_triage_gate.nx -- the ENGINEER's gate for the training-triage organ. Seven rows:
2// five KATs whose numbers are the ACTUAL MEASURED runs from the T4 build session 2026-06-10
3// (each failure happened for real before its lesson was banked), one LIVE row (the T4b report
4// the closed-loop lane just emitted must diagnose CONVERGED-HEALTHY), one TAMPER row (a report
5// missing its ACC/LOSS rows must come back BROKEN-REPORT). Gate green iff 7/7 verdicts match.
6// license_tier: ORIGINAL
7import "nx_train_triage.nx"
8
9// write a synthetic report: 8 census classes, given preds/acc and a loss curve
10func ttg_wreport(path: *u8, preds: *i64, right: i64, total: i64, losses: *i64, nloss: i64) -> i64 {
11 let fd: i64 = sys_openat_wr(path, 0x1a4)
12 if fd < 0 { return 0 }
13 let cls: *i64 = sys_mmap(128) as *i64
14 cls[0] = 88; cls[1] = 5; cls[2] = 20; cls[3] = 6; cls[4] = 5; cls[5] = 2; cls[6] = 5; cls[7] = 18
15 var c: i64 = 0
16 while c < 8 {
17 tt_w(fd, "TRIAGE-CLASS id=" as *u8); tt_wn(fd, c)
18 tt_w(fd, " count=" as *u8); tt_wn(fd, cls[c]); tt_w(fd, "\n" as *u8)
19 c = c + 1
20 }
21 c = 0
22 while c < 8 {
23 tt_w(fd, "TRIAGE-PRED id=" as *u8); tt_wn(fd, c)
24 tt_w(fd, " count=" as *u8); tt_wn(fd, preds[c]); tt_w(fd, "\n" as *u8)
25 c = c + 1
26 }
27 tt_w(fd, "TRIAGE-ACC right=" as *u8); tt_wn(fd, right)
28 tt_w(fd, " total=" as *u8); tt_wn(fd, total); tt_w(fd, "\n" as *u8)
29 var i: i64 = 0
30 while i < nloss {
31 tt_w(fd, "TRIAGE-LOSS ep=" as *u8); tt_wn(fd, i * 100)
32 tt_w(fd, " micro=" as *u8); tt_wn(fd, losses[i]); tt_w(fd, "\n" as *u8)
33 i = i + 1
34 }
35 sys_close(fd)
36 return 1
37}
38
39func ttg_row(label: *u8, path: *u8, want: i64, failp: *i64) -> i64 {
40 let got: i64 = tt_diagnose(path)
41 tt_w(1, " row " as *u8); tt_w(1, label)
42 tt_w(1, " want=" as *u8); tt_w(1, tt_name(want))
43 tt_w(1, " got=" as *u8); tt_w(1, tt_name(got))
44 if got == want { tt_w(1, " PASS\n" as *u8) } else { tt_w(1, " FAIL\n" as *u8); failp[0] = failp[0] + 1 }
45 return 0
46}
47
48func main() -> i64 {
49 tt_w(1, "=== TRAIN-TRIAGE GATE (5 real-failure KATs + live T4b report + tamper) ===\n" as *u8)
50 let p: *i64 = sys_mmap(128) as *i64
51 let l: *i64 = sys_mmap(256) as *i64
52 let failp: *i64 = sys_mmap(16) as *i64
53 failp[0] = 0
54
55 // KAT1 MAJORITY-COLLAPSE: the per-sample-Adam run -- every pred svc, acc 88/149, loss frozen
56 p[0]=149; p[1]=0; p[2]=0; p[3]=0; p[4]=0; p[5]=0; p[6]=0; p[7]=0
57 l[0]=88000; l[1]=84000; l[2]=84000; l[3]=84000; l[4]=84000; l[5]=84000
58 ttg_wreport("/tmp/_tt_kat_collapse.log" as *u8, p, 88, 149, l, 6)
59 ttg_row("KAT1-collapse" as *u8, "/tmp/_tt_kat_collapse.log" as *u8, TT_COLLAPSE, failp)
60
61 // KAT2 RARE-CLASS-LOSS: the unweighted full-batch run -- util 0/5 and mon 0/2, acc 142/149
62 p[0]=88; p[1]=7; p[2]=20; p[3]=6; p[4]=10; p[5]=0; p[6]=0; p[7]=18
63 l[0]=230000; l[1]=25000; l[2]=14000; l[3]=12000; l[4]=12000; l[5]=11000
64 ttg_wreport("/tmp/_tt_kat_rare.log" as *u8, p, 142, 149, l, 6)
65 ttg_row("KAT2-rare" as *u8, "/tmp/_tt_kat_rare.log" as *u8, TT_RARE, failp)
66
67 // KAT3 POST-CONVERGENCE-BLOWUP: the 8-byte run -- loss hit 0 at ep600 then rose to 104+
68 p[0]=88; p[1]=5; p[2]=20; p[3]=11; p[4]=5; p[5]=2; p[6]=0; p[7]=18
69 l[0]=1491; l[1]=121; l[2]=76; l[3]=14; l[4]=7; l[5]=5; l[6]=0; l[7]=1; l[8]=224; l[9]=104; l[10]=104
70 ttg_wreport("/tmp/_tt_kat_blowup.log" as *u8, p, 144, 149, l, 11)
71 ttg_row("KAT3-blowup" as *u8, "/tmp/_tt_kat_blowup.log" as *u8, TT_BLOWUP, failp)
72
73 // KAT4 PLATEAU: the uncentered-features run -- loss frozen 44 milli across optim steps, acc 108
74 p[0]=70; p[1]=10; p[2]=25; p[3]=6; p[4]=5; p[5]=2; p[6]=5; p[7]=26
75 l[0]=402000; l[1]=46000; l[2]=44000; l[3]=44000; l[4]=44000; l[5]=43000
76 ttg_wreport("/tmp/_tt_kat_plateau.log" as *u8, p, 108, 149, l, 6)
77 ttg_row("KAT4-plateau" as *u8, "/tmp/_tt_kat_plateau.log" as *u8, TT_PLATEAU, failp)
78
79 // KAT5 CONVERGED-HEALTHY: the final T4 run -- 149/149, early-stopped at the curve minimum
80 p[0]=88; p[1]=5; p[2]=20; p[3]=6; p[4]=5; p[5]=2; p[6]=5; p[7]=18
81 l[0]=1491; l[1]=121; l[2]=76; l[3]=14; l[4]=7; l[5]=4
82 ttg_wreport("/tmp/_tt_kat_healthy.log" as *u8, p, 149, 149, l, 6)
83 ttg_row("KAT5-healthy" as *u8, "/tmp/_tt_kat_healthy.log" as *u8, TT_HEALTHY, failp)
84
85 // LIVE row: the report the T4b closed-loop lane actually emitted this session
86 ttg_row("LIVE-t4b" as *u8, "knowledge/status/train_report_t4b.log" as *u8, TT_HEALTHY, failp)
87
88 // TAMPER row: a report with no ACC/LOSS rows must be BROKEN, never silently judged
89 let fd: i64 = sys_openat_wr("/tmp/_tt_kat_tamper.log" as *u8, 0x1a4)
90 if fd >= 0 {
91 tt_w(fd, "TRIAGE-CLASS id=0 count=88\n" as *u8)
92 sys_close(fd)
93 }
94 ttg_row("TAMPER-broken" as *u8, "/tmp/_tt_kat_tamper.log" as *u8, TT_BROKEN, failp)
95
96 if failp[0] == 0 {
97 tt_w(1, " TRAIN-TRIAGE GATE: PASS 7/7 (the T4 lessons are now a team-owned instrument)\n" as *u8)
98 sys_exit(0)
99 return 0
100 }
101 tt_w(1, " TRAIN-TRIAGE GATE: FAIL rows=" as *u8); tt_wn(1, failp[0]); tt_w(1, "\n" as *u8)
102 sys_exit(1)
103 return 1
104}