code wiki / _hdl_build / nx_meet_bug_train.nx
nx_meet_bug_train.nx source
↩ module page · 122 lines · 9281 B
1// nx_meet_bug_train.nx -- Seeds session-specific bug diagnoses into the Doctor's known-issue catalogue for autonomous resolution.
2import "nx_gate_gn.nx"
3// nx_meet_bug_train.nx -- TEAM TRAINING (operator: "get the dr+engineer+team training on these bugs/crashes/slows
4// so they can resolve autonomously"). Seeds THIS session's hard-won diagnoses into the Doctor's machine-matchable
5// KNOWN-ISSUE catalogue (ki-* seg-store) so ki_recall matches a live diagnostic -> remedy (recall-and-route, never
6// re-diagnose). The distinctive ones carry a real SIGNATURE (auto-matched); the dialect/usage ones are recall-by-id
7// disciplines. ADDITIVE: reads the existing ki:ids + appends ours (guarded against clobber). Then SELF-PROVES recall
8// (2 signatured hits + a neg-control miss). Sovereign. license_tier: ORIGINAL
9import "nx_syscalls.nx"
10import "nx_seg_store.nx"
11import "nx_known_issue_store.nx"
12const K_MAGIC_262144: i64 = 262144
13const K_MAGIC_2048: i64 = 2048
14
15func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func tlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
17// 1 if `id` is a TAB-delimited token in idx[0..ilen)
18func idx_has(idx: *u8, ilen: i64, id: *u8) -> i64 {
19 let il: i64 = tlen(id); var i: i64 = 0
20 while i < ilen {
21 var le: i64 = i
22 while le < ilen { if idx[le] == (9 as u8) { break } le = le + 1 }
23 if (le - i) == il { var k: i64=0; var eq: i64=1; while k<il { if idx[i+k]!=id[k]{eq=0;k=il} else {k=k+1} } if eq==1 { return 1 } }
24 i = le + 1
25 }
26 return 0
27}
28
29func main() -> i64 {
30 gp("=== nx_meet_bug_train: seed this session's bugs/crashes/slows into the Doctor's ki- recall catalogue ===\n" as *u8)
31
32 let keys: *i64 = sys_mmap(8*16) as *i64
33 let vals: *i64 = sys_mmap(8*16) as *i64
34 let ids: *i64 = sys_mmap(8*16) as *i64
35 keys[0]="ki:NX-EMPTYS-REALERR" as *u8 as i64; ids[0]="NX-EMPTYS-REALERR" as *u8 as i64
36 vals[0]="NX-EMPTYS-REALERR\tTOOLCHAIN\tDISCIPLINE\tempty .s after retries\tif rm /tmp/<name>.s + rebuild does NOT fix it, it is a SOURCE error the compiler swallows: a reserved-keyword identifier (match/type/...) OR a let-binding reassigned -> rename the ident / change let to var; bisect recent edits" as *u8 as i64
37 keys[1]="ki:NX-WSL-EUNEXPECTED" as *u8 as i64; ids[1]="NX-WSL-EUNEXPECTED" as *u8 as i64
38 vals[1]="NX-WSL-EUNEXPECTED\tENV\tADAPT\tE_UNEXPECTED\tWSL service catastrophic failure -> wsl --shutdown then retry (sibling of LM-009)" as *u8 as i64
39 keys[2]="ki:NX-OFFC-FORK" as *u8 as i64; ids[2]="NX-OFFC-FORK" as *u8 as i64
40 vals[2]="NX-OFFC-FORK\tTOOLCHAIN\tDISCIPLINE\t-\tnx_sov_build_run builds /tmp/<name>.sov.elf + refreshes _offc/<name>.elf ONLY IF present; a NEW organ gate must fork /tmp/<name>.sov.elf or install to _offc first (sibling LM-026)" as *u8 as i64
41 keys[3]="ki:NX-GATE-NESTED-BUILD" as *u8 as i64; ids[3]="NX-GATE-NESTED-BUILD" as *u8 as i64
42 vals[3]="NX-GATE-NESTED-BUILD\tTOOLCHAIN\tDISCIPLINE\t-\tmany NESTED nx_sov_build_run rebuilds inside one gate trip the runner smoke watchdog (exit 15/SIGTERM); pre-build deps or fork existing ELFs, do not nest full rebuilds" as *u8 as i64
43 keys[4]="ki:NX-PUB-DRAIN-DIRTYDIR" as *u8 as i64; ids[4]="NX-PUB-DRAIN-DIRTYDIR" as *u8 as i64
44 vals[4]="NX-PUB-DRAIN-DIRTYDIR\tTOOLCHAIN\tDISCIPLINE\t-\tpub_run_governed wet-drain crashes against the polluted shared knowledge/publish dir; run the drain from a CLEAN per-workstream dir (rp_path) -- NOT a publisher bug" as *u8 as i64
45 keys[5]="ki:NX-EMPTY-STR-MLEN" as *u8 as i64; ids[5]="NX-EMPTY-STR-MLEN" as *u8 as i64
46 vals[5]="NX-EMPTY-STR-MLEN\tDIALECT\tDISCIPLINE\t-\tthe empty-string literal (two double-quotes) is unsafe for mlen (reads len>0); use a sys_mmap buffer with [0]=0 for an empty value (e.g. an empty honeypot)" as *u8 as i64
47 keys[6]="ki:NX-LET-REASSIGN" as *u8 as i64; ids[6]="NX-LET-REASSIGN" as *u8 as i64
48 vals[6]="NX-LET-REASSIGN\tDIALECT\tDISCIPLINE\t-\ta reassigned binding must be `var` not `let` (let is immutable; reassigning it silently compile-fails to an empty .s)" as *u8 as i64
49 // NXASM-UNDEF-MAIN: discovered live 2026-06-23 cycling a real TLS bug through the loop. nxasm rc=102
50 // "UNDEFINED label: main" = a LIBRARY module (no func main) built as a standalone executable (no entry point).
51 // Distinct from CC-UNDEFFN (compiler-level "call to undefined function"). Signature auto-matches the real error.
52 keys[7]="ki:NXASM-UNDEF-MAIN" as *u8 as i64; ids[7]="NXASM-UNDEF-MAIN" as *u8 as i64
53 vals[7]="NXASM-UNDEF-MAIN\tTOOLCHAIN\tDISCIPLINE\tUNDEFINED label: main\tnxasm rc=102 'UNDEFINED label: main' = a LIBRARY module (no func main) built standalone -> build it through its consumer/gate (e.g. nx_tls13 -> nx_pub_tls_gate), NOT standalone; confirm with nx_doc_mainscan:ms_is_library_build_error (ms_has_main==0); do NOT fabricate a main" as *u8 as i64
54 let nrec: i64 = 8
55
56 // read existing ki:ids; GUARD against clobber (only merge if it contains a known ws id)
57 let pq: *i64 = sys_mmap(16) as *i64
58 let lq: *i64 = sys_mmap(16) as *i64
59 let idx: *u8 = sys_mmap(K_MAGIC_262144); var ilen: i64 = 0
60 var have_existing: i64 = 0
61 if ki_get("ki:ids" as *u8, pq, lq) == 1 {
62 let src: *u8 = pq[0] as *u8; let sl: i64 = lq[0]
63 var c: i64 = 0; while c < sl { idx[c] = src[c]; c = c + 1 } ilen = sl
64 if idx_has(idx, ilen, "LM-021" as *u8) == 1 { have_existing = 1 }
65 }
66 if have_existing == 0 {
67 gp(" WARN: could not read a known existing ki:ids (LM-021 absent) -- writing ONLY our ids to avoid clobbering theirs is unsafe; ABORTING index merge. Seeding records only.\n" as *u8)
68 ilen = 0
69 }
70 // append our ids (tab-delimited) if absent
71 var i: i64 = 0
72 while i < nrec {
73 let id: *u8 = ids[i] as *u8
74 if idx_has(idx, ilen, id) == 0 {
75 if ilen > 0 { idx[ilen] = 9 as u8; ilen = ilen + 1 }
76 let il: i64 = tlen(id); var k: i64 = 0
77 while k < il { idx[ilen] = id[k]; ilen = ilen + 1; k = k + 1 }
78 }
79 i = i + 1
80 }
81
82 // commit records + (if safe) the merged index
83 let w: *i64 = ss_begin()
84 i = 0
85 while i < nrec { ss_add(w, 1, keys[i] as *u8, vals[i] as *u8, tlen(vals[i] as *u8)); i = i + 1 }
86 if have_existing == 1 { ss_add(w, 1, "ki:ids" as *u8, idx, ilen) }
87 let segid: i64 = ki_seg_next_p(KI_PREFIX)
88 let rc: i64 = ss_commit(KI_PREFIX, w, segid)
89 gp(" seeded records=" as *u8); gn(nrec); gp(" index-merged=" as *u8); gn(have_existing); gp(" commit_rc=" as *u8); gn(rc); gp("\n" as *u8)
90
91 // SELF-PROVE recall: a live diagnostic -> remedy (the Doctor resolving autonomously)
92 let oid: *u8 = sys_mmap(128); let orem: *u8 = sys_mmap(K_MAGIC_2048); let ostat: *u8 = sys_mmap(64)
93 let d1: *u8 = "[nx_sov_build_run] nx_foo: COMPILE-FAIL (empty .s after retries)" as *u8
94 let r1: i64 = ki_recall(KI_PREFIX, d1, tlen(d1), oid, orem, ostat)
95 var hit1: i64 = 0; if r1 == KI_HIT { if ki_substr(oid, tlen(oid), "NX-EMPTYS" as *u8, 9) >= 0 { hit1 = 1 } }
96 gp(" recall(empty .s) -> id=" as *u8); gp(oid); gp("\n" as *u8)
97 let oid2: *u8 = sys_mmap(128); let orem2: *u8 = sys_mmap(K_MAGIC_2048); let ostat2: *u8 = sys_mmap(64)
98 let d2: *u8 = "Catastrophic failure Error code: Wsl/Service/CreateInstance/E_UNEXPECTED" as *u8
99 let r2: i64 = ki_recall(KI_PREFIX, d2, tlen(d2), oid2, orem2, ostat2)
100 var hit2: i64 = 0; if r2 == KI_HIT { if ki_substr(oid2, tlen(oid2), "NX-WSL" as *u8, 6) >= 0 { hit2 = 1 } }
101 gp(" recall(E_UNEXPECTED) -> id=" as *u8); gp(oid2); gp("\n" as *u8)
102 let oid3: *u8 = sys_mmap(128); let orem3: *u8 = sys_mmap(K_MAGIC_2048); let ostat3: *u8 = sys_mmap(64)
103 let d3: *u8 = "everything compiled and ran fine, all green, nothing to see" as *u8
104 let r3: i64 = ki_recall(KI_PREFIX, d3, tlen(d3), oid3, orem3, ostat3)
105 // the REAL TLS diagnostic cycled live this session -> must recall the new NXASM-UNDEF-MAIN lesson
106 let oid4: *u8 = sys_mmap(128); let orem4: *u8 = sys_mmap(K_MAGIC_2048); let ostat4: *u8 = sys_mmap(64)
107 let d4: *u8 = "nxasm_x86: UNDEFINED label: main" as *u8
108 let r4: i64 = ki_recall(KI_PREFIX, d4, tlen(d4), oid4, orem4, ostat4)
109 var hit4: i64 = 0; if r4 == KI_HIT { if ki_substr(oid4, tlen(oid4), "NXASM-UNDEF-MAIN" as *u8, 16) >= 0 { hit4 = 1 } }
110 gp(" recall(UNDEFINED label: main) -> id=" as *u8); gp(oid4); gp("\n" as *u8)
111
112 var pass: i64 = 0; var fail: i64 = 0
113 if rc == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL commit\n" as *u8) }
114 if hit1 == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL recall-empty-s\n" as *u8) }
115 if hit2 == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL recall-wsl\n" as *u8) }
116 if hit4 == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL recall-nxasm-undef-main\n" as *u8) }
117 if r3 == KI_UNKNOWN { pass=pass+1 } else { fail=fail+1; gp(" FAIL neg-control-false-match\n" as *u8) }
118
119 gp("MEET-BUG-TRAIN pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail)
120 if fail == 0 { gp(" verdict=GREEN (team trained: session bugs/crashes/slows in the Doctor's ki- catalogue; recall HITs the remedy, neg-control clean)\n" as *u8); sys_exit(0); return 0 }
121 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1
122}