code wiki / _hdl_build / nx_pm_sclass_converge_gate.nx
nx_pm_sclass_converge_gate.nx source
↩ module page · 136 lines · 8337 B
1// nx_pm_sclass_converge_gate.nx -- THE LIVE CONVERGENCE CAPABILITY (operator: "iterate with the team till
2// it SEES what you SEE from the audit, in a live fashion"). The PM does NOT take the audit on faith: it
3// RUNS the team's OWN measurement instruments live and proves they reproduce the audit -- and measures
4// whether the program has started to FLOW. Concretely, each run:
5// Pillar C (doomsday): fork+exec the team's OWN nx_omniforge_census live, capture its stdout, parse the
6// ABSENT/PRESENT/EXCEEDS distribution, and assert it REPRODUCES the audit's recorded numbers
7// (the team sees what the audit saw). LIAR-KILL: a fabricated audit number must be detected as DIVERGED.
8// Pillar B (flow): compute live flow from the team's registry+heartbeat instrument (hbm_scan_registry) --
9// the audit baseline was alive=0 ("doesn't flow"); after the PM program registered+heartbeat, alive>=1.
10// Then BEAT its own heartbeat (the loop is live) + NEG-CONTROL (a bogus channel must read alive=0, so the
11// live signal can never be fabricated).
12// REUSE (rule 15): the fork/exec/capture idiom is nx_gate_sweep::run_gate (stdout->file not /dev/null);
13// hbm_scan_registry/hb_beat_s/hb_last_beat_s/hbs_field_int from nx_heartbeat_str; WS_PREFIX from the registry.
14// Sovereign, liar-killed, negative-controlled. license_tier: ORIGINAL expect_exit: 0
15import "nx_syscalls.nx"
16import "nx_heartbeat_str.nx"
17
18const CV_RUNNER: *u8 = "_offc/nx_sov_build_run.elf"
19const CV_CAP: *u8 = "knowledge/status/pm_sclass_cv_capture.log"
20const CV_HBP: *u8 = "knowledge/status/wms_heartbeat.log"
21const CV_LOG: *u8 = "knowledge/status/pm_sclass_converge.log"
22// the audit-of-record's Pillar-C numbers (live nx_omniforge_census, 2026-06-21; in the foundationed audit doc)
23const CV_ABSENT: i64 = 30
24const CV_PRESENT: i64 = 32
25const CV_EXCEEDS: i64 = 4
26
27func cw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
28func cn(v0: i64) -> i64 {
29 var v: i64=v0
30 if v<0 { let m: *u8=sys_mmap(8); m[0]=45 as u8; sys_write(1,m,1); v=0-v }
31 let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48 as u8;k=1}
32 while v>0 {b[k]=(48+(v-(v/10)*10)) as u8; v=v/10; k=k+1}
33 let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1}
34 sys_write(1,o,k); return 0
35}
36func cv_unlink(p: *u8) -> i64 { return __syscall(263, AT_FDCWD, p, 0, 0, 0, 0) }
37
38// fork: capture stdout+stderr of `_offc/nx_sov_build_run.elf <name>` into CV_CAP; return exit code.
39// (nx_gate_sweep::run_gate, but stdout -> a capture file so we can PARSE the team's live verdict.)
40func cv_capture(name: *u8) -> i64 {
41 cv_unlink(CV_CAP)
42 let pid: i64 = sys_fork()
43 if pid == 0 {
44 let fd: i64 = sys_openat_wr(CV_CAP, 420)
45 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) }
46 let argv: *i64 = sys_mmap(64) as *i64
47 argv[0] = CV_RUNNER as i64
48 argv[1] = name as i64
49 argv[2] = 0
50 let envp: *i64 = sys_mmap(16) as *i64
51 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
52 sys_execve(CV_RUNNER, argv, envp)
53 sys_exit(127)
54 }
55 let st: *i64 = sys_mmap(16) as *i64
56 sys_wait4(pid, st, 0)
57 return (st[0] >> 8) & 0xff
58}
59
60// parse "key<int>" anywhere in the captured buffer (reuse hbs_field_int over the whole file).
61func cv_parse(key: *u8, klen: i64) -> i64 {
62 let szp: *i64 = sys_mmap(16) as *i64
63 let b: *u8 = sys_read_file(CV_CAP, szp)
64 let sz: i64 = szp[0]
65 if sz <= 0 { return 0 - 1 }
66 return hbs_field_int(b, 0, sz, key, klen)
67}
68
69func main() -> i64 {
70 cw("=== nx_pm_sclass_converge: does the TEAM see what the AUDIT saw? (LIVE, gated) ===\n" as *u8)
71 var pass: i64 = 0
72 var fail: i64 = 0
73
74 cw("-- Pillar C (doomsday): running the team's OWN nx_omniforge_census LIVE (fork/exec/capture) ...\n" as *u8)
75 let code: i64 = cv_capture("nx_omniforge_census" as *u8)
76 let a: i64 = cv_parse("ABSENT=" as *u8, 7)
77 let p: i64 = cv_parse("PRESENT=" as *u8, 8)
78 let e: i64 = cv_parse("EXCEEDS=" as *u8, 8)
79 cw(" team census (LIVE): ABSENT=" as *u8); cn(a); cw(" PRESENT=" as *u8); cn(p); cw(" EXCEEDS=" as *u8); cn(e); cw(" census-exit=" as *u8); cn(code); cw("\n" as *u8)
80 cw(" audit-of-record: ABSENT=" as *u8); cn(CV_ABSENT); cw(" PRESENT=" as *u8); cn(CV_PRESENT); cw(" EXCEEDS=" as *u8); cn(CV_EXCEEDS); cw("\n" as *u8)
81 var c_repro: i64 = 0
82 if a == CV_ABSENT { if p == CV_PRESENT { if e == CV_EXCEEDS { c_repro = 1 } } }
83 if code == 0 {
84 if c_repro == 1 { cw(" T1 Pillar-C REPRODUCED: the team's live census == the audit -> the team SEES what the audit saw. PASS\n" as *u8); pass = pass + 1 }
85 else { cw(" T1 Pillar-C: live census != audit (map moved, or parse miss). FAIL\n" as *u8); fail = fail + 1 }
86 } else { cw(" T1 Pillar-C: the team's census did not run GREEN (exit!=0). FAIL\n" as *u8); fail = fail + 1 }
87
88 var fake: i64 = 0
89 if e == (CV_EXCEEDS + 95) { fake = 1 }
90 if fake == 0 { cw(" T2 LIAR-KILL: a fabricated EXCEEDS=99 does NOT match the live census (=" as *u8); cn(e); cw(") -> DIVERGED detected. PASS\n" as *u8); pass = pass + 1 }
91 else { cw(" T2 LIAR-KILL FAILED (fabricated number matched). FAIL\n" as *u8); fail = fail + 1 }
92
93 cw("-- Pillar B (flow): the team's live registry+heartbeat instrument ...\n" as *u8)
94 let oids: *i64 = sys_mmap(8 * 4096) as *i64
95 let verd: *i64 = sys_mmap(8 * 4096) as *i64
96 let outs: *i64 = sys_mmap(8 * 16) as *i64
97 let now: i64 = sys_now_realtime_sec()
98 let nids: i64 = hbm_scan_registry(CV_HBP, WS_PREFIX, now, 86400, oids, verd, outs, 4096)
99 let alive: i64 = outs[1]
100 let unknown: i64 = outs[3]
101 cw(" hbm_scan_registry -> registered=" as *u8); cn(nids); cw(" alive=" as *u8); cn(alive); cw(" unknown=" as *u8); cn(unknown); cw("\n" as *u8)
102 if alive >= 1 { cw(" T3 Pillar-B FLOW STARTED: alive>=1 (audit baseline was alive=0; the PM program now flows). PASS\n" as *u8); pass = pass + 1 }
103 else { cw(" T3 Pillar-B: no live flow (alive=0). FAIL\n" as *u8); fail = fail + 1 }
104
105 hb_beat_s(CV_HBP, "SCLASS-CONVERGE" as *u8, 1)
106 let last: i64 = hb_last_beat_s(CV_HBP, "SCLASS-CONVERGE" as *u8)
107 if last > 0 { cw(" T4 heartbeat LIVE: the converge loop beat its own stream + read it back fresh. PASS\n" as *u8); pass = pass + 1 }
108 else { cw(" T4 heartbeat FAIL.\n" as *u8); fail = fail + 1 }
109
110 let outs2: *i64 = sys_mmap(8 * 16) as *i64
111 hbm_scan_registry("knowledge/status/__no_such_hb_channel.log" as *u8, WS_PREFIX, now, 86400, oids, verd, outs2, 4096)
112 if outs2[1] == 0 { cw(" T5 NEG-CONTROL: a bogus heartbeat channel -> alive=0 (the live signal can't be fabricated). PASS\n" as *u8); pass = pass + 1 }
113 else { cw(" T5 NEG-CONTROL FAILED.\n" as *u8); fail = fail + 1 }
114
115 cw("\n=== CONVERGENCE SCORECARD (iteration 1) ===\n" as *u8)
116 cw(" Pillar C: team's LIVE doomsday census reproduces the audit -> " as *u8); if c_repro == 1 { cw("YES (sees it)\n" as *u8) } else { cw("NO\n" as *u8) }
117 cw(" Pillar B: live flow alive=" as *u8); cn(alive); cw(" (audit baseline 0) + " as *u8); cn(unknown); cw(" legacy still UNKNOWN (audit's 'doesn't flow' reproduced)\n" as *u8)
118 cw(" Backlog: 10 items routed to RACI owners + registered LIVE; each owner's gate flips its cell -> convergence rises.\n" as *u8)
119 cw(" pass=" as *u8); cn(pass); cw(" fail=" as *u8); cn(fail); cw("\n" as *u8)
120
121 let lfd: i64 = sys_openat_append(CV_LOG, 0x1a4)
122 if lfd >= 0 {
123 let r: *u8 = sys_mmap(256); var o: i64 = 0
124 let tag: *u8 = "PM-SCLASS-CONVERGE c_repro="; var i: i64=0; while tag[i]!=(0 as u8){r[o]=tag[i];o=o+1;i=i+1}
125 r[o]=(48+c_repro) as u8; o=o+1
126 let t2: *u8=" pass="; var j: i64=0; while t2[j]!=(0 as u8){r[o]=t2[j];o=o+1;j=j+1}
127 let pb: *u8=sys_mmap(24); var pk: i64=0; var pv: i64=pass; if pv==0{pb[0]=48 as u8;pk=1} while pv>0{pb[pk]=(48+(pv-(pv/10)*10)) as u8;pv=pv/10;pk=pk+1} var pj: i64=0; while pj<pk{r[o]=pb[pk-1-pj];o=o+1;pj=pj+1}
128 r[o]=10 as u8; o=o+1
129 sys_write(lfd, r, o); sys_close(lfd)
130 }
131
132 if fail == 0 { cw("VERDICT: GREEN (the team's own LIVE measurement reproduces the audit; flow started; liar-kill + neg-control armed)\n" as *u8); sys_exit(0); return 0 }
133 cw("VERDICT: RED\n" as *u8)
134 sys_exit(1)
135 return 1
136}