code wiki / _hdl_build / nx_engineer_deliver.nx

nx_engineer_deliver.nx source

↩ module page · 53 lines · 3114 B

1// nx_engineer_deliver.nx -- close the DELIVERY loop for a SECOND section (the engineer) with a 2// DIFFERENT kind of real work, proving the loop generalizes (not researcher-specific). The 3// engineer's accountability includes `verify`; here it does real verify work -- fork/exec a real 4// gate and key on its exit code -- and ONLY if the gate is GREEN does it record an APPLIED delivery 5// in engineerq (real verification completed, not a flag flip). Internal + deterministic + safe (no 6// outward action, unlike the publisher's live ship). Reuses the verified sd_run_gate fork/exec idiom. 7// Sovereign. license_tier: ORIGINAL 8import "nx_role_store.nx" 9import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 10import "nx_syscalls.nx" 11 12const ED_CHAN: *u8 = "engineerq" 13const ED_GATE: *u8 = "nx_pipeline_gate" // a real GREEN capability for the engineer to verify 14const ED_RUNNER: *u8 = "_offc/nx_sov_build_run.elf" 15 16func ed_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 17// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 18// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 19// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 20// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 21func ed_n(v: i64) -> i64 { nxi_out(v); return 0 } 22func ed_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != (0 as u8) { dst[o] = s[i]; o = o + 1; i = i + 1 } return o } 23 24// fork/exec the sovereign runner on `gate`; stdout/stderr -> /dev/null; return exit code (0=GREEN). 25func ed_run_gate(gate: *u8) -> i64 { 26 let pid: i64 = sys_fork() 27 if pid == 0 { 28 let dn: i64 = sys_openat_wr("/dev/null\x00" as *u8, 420) 29 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) } 30 let argv: *i64 = sys_mmap(64) as *i64 31 argv[0] = ED_RUNNER as i64; argv[1] = gate as i64; argv[2] = 0 32 let envp: *i64 = sys_mmap(16) as *i64 33 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 34 sys_execve(ED_RUNNER, argv, envp) 35 sys_exit(127) 36 } 37 let st: *i64 = sys_mmap(16) as *i64 38 sys_wait4(pid, st, 0) 39 return (st[0] >> 8) & 0xff 40} 41 42func main(argc: i64, argv: *i64) -> i64 { 43 ed_w("=== ENGINEER delivers: verify a real capability (" as *u8); ed_w(ED_GATE); ed_w(") ===\n" as *u8) 44 let ex: i64 = ed_run_gate(ED_GATE) 45 ed_w(" verify done: gate exit=" as *u8); ed_n(ex); ed_w("\n" as *u8) 46 if ex != 0 { ed_w(" gate NOT green -> nothing to deliver (honest -- no APPLIED).\n" as *u8); sys_exit(1); return 1 } 47 let row: *u8 = sys_mmap(256); var o: i64 = 0 48 o = ed_cat(row, o, "engineer\tAPPLIED\tverified:" as *u8); o = ed_cat(row, o, ED_GATE) 49 o = ed_cat(row, o, " GREEN\tby=engineer" as *u8); row[o] = 0 as u8 50 rs_append(ED_CHAN, row, o) 51 ed_w(" DELIVERED: engineerq APPLIED (verified " as *u8); ed_w(ED_GATE); ed_w(" GREEN -- real verification recorded).\n" as *u8) 52 sys_exit(0); return 0 53}