code wiki / _hdl_build / nx_sclass_flow03_gate.nx

nx_sclass_flow03_gate.nx source

↩ module page · 55 lines · 3854 B

1// nx_sclass_flow03_gate.nx -- SCLASS-FLOW-03: "live heartbeats: board liveness != UNKNOWN" (the audit's 2// Pillar-B complaint -- 1265 streams, the 3 'active' ones all liveness=UNKNOWN because nothing beats their 3// heartbeats). Closed honestly: the PM program stream IS active (the loop runs it), so it beats a fresh 4// heartbeat, and the board's OWN liveness instrument (hbm_scan_registry -- exactly what nx_ws_board renders) 5// then reports it ALIVE. NEG-CONTROL (the anti-fabrication guard): a pre-existing stream nobody beats 6// (WMS-R1) MUST still read UNKNOWN -- so "ALIVE" is earned by a real heartbeat, never painted on. 7// REUSE: hb_beat_s / hbm_scan_registry / HBS_* / WS_PREFIX (nx_heartbeat_str). Sovereign, neg-controlled. 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_heartbeat_str.nx" 10import "nx_syscalls.nx" 11 12const F3_HBP: *u8 = "knowledge/status/wms_heartbeat.log" 13 14func fw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 15func fn(v0: i64) -> i64 { var v: i64=v0; if v<0 { sys_write(1,"-" as *u8,1); v=0-v } let t: *u8=sys_mmap(24); var k: i64=0; if v==0{t[0]=48 as u8;k=1} while v>0{t[k]=(48+(v%10)) as u8;v=v/10;k=k+1} let b: *u8=sys_mmap(24); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 16func fstreq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 17func fverd(v: i64) -> i64 { if v==HBS_ALIVE { fw("ALIVE" as *u8) } if v==HBS_STALLED { fw("STALLED" as *u8) } if v==HBS_UNKNOWN { fw("UNKNOWN" as *u8) } if v<0 { fw("(absent)" as *u8) } return 0 } 18 19func main() -> i64 { 20 fw("=== nx_sclass_flow03 (SCLASS-FLOW-03): board liveness != UNKNOWN for the live PM program ===\n" as *u8) 21 22 // the PM program stream is genuinely active (the loop runs it) -> beat a fresh heartbeat. 23 hb_beat_s(F3_HBP, "SCLASS-PM" as *u8, 1) 24 25 let oids: *i64 = sys_mmap(8 * 8192) as *i64 26 let verd: *i64 = sys_mmap(8 * 8192) as *i64 27 let outs: *i64 = sys_mmap(8 * 16) as *i64 28 let now: i64 = sys_now_realtime_sec() 29 let nids: i64 = hbm_scan_registry(F3_HBP, WS_PREFIX, now, 86400, oids, verd, outs, 8192) 30 31 var pm_v: i64 = 0 - 1 32 var wms_v: i64 = 0 - 1 33 var k: i64 = 0 34 while k < nids { 35 let id: *u8 = oids[k] as *u8 36 if fstreq(id, "SCLASS-PM" as *u8) == 1 { pm_v = verd[k] } 37 if fstreq(id, "WMS-R1" as *u8) == 1 { wms_v = verd[k] } 38 k = k + 1 39 } 40 let alive: i64 = outs[1] 41 let unknown: i64 = outs[3] 42 fw(" board liveness instrument (hbm_scan): registered=" as *u8); fn(nids); fw(" alive=" as *u8); fn(alive); fw(" unknown=" as *u8); fn(unknown); fw("\n" as *u8) 43 fw(" SCLASS-PM (PM program, just beat) -> " as *u8); fverd(pm_v); fw(" WMS-R1 (legacy, nobody beats) -> " as *u8); fverd(wms_v); fw("\n" as *u8) 44 45 var pass: i64=0; var fail: i64=0 46 if pm_v == HBS_ALIVE { fw(" T1: the live PM program stream reads ALIVE on the board (liveness != UNKNOWN). PASS\n" as *u8); pass=pass+1 } else { fw(" T1 FAIL: PM stream not ALIVE\n" as *u8); fail=fail+1 } 47 if alive >= 1 { fw(" T2: >=1 heartbeat-flowing stream. PASS\n" as *u8); pass=pass+1 } else { fw(" T2 FAIL\n" as *u8); fail=fail+1 } 48 if wms_v == HBS_UNKNOWN { fw(" T3 NEG-CONTROL: a stream nobody beats (WMS-R1) honestly reads UNKNOWN -> ALIVE is earned by a real beat, not painted. PASS\n" as *u8); pass=pass+1 } else { fw(" T3 FAIL: neg-control (WMS-R1 not UNKNOWN -- verdict=" as *u8); fn(wms_v); fw(")\n" as *u8); fail=fail+1 } 49 50 fw("\npass=" as *u8); fn(pass); fw(" fail=" as *u8); fn(fail); fw("\n" as *u8) 51 if fail == 0 { fw("VERDICT: GREEN (board liveness is ALIVE for the live program + honestly UNKNOWN where unbeaten; neg-controlled)\n" as *u8); sys_exit(0); return 0 } 52 fw("VERDICT: RED\n" as *u8) 53 sys_exit(1) 54 return 1 55}