code wiki / _hdl_build / nx_doctor_heal_test.nx

nx_doctor_heal_test.nx source

↩ module page · 76 lines · 4050 B

1// nx_doctor_heal_test.nx -- the AUTO-FIX leg: the Doctor heals the loop UNDER 2// GOVERNANCE. Detect a problem -> propose a fix -> the crew gauntlet (the WARDEN 3// derives safety from the fix's target PATH; the ENGINEER requires the fix to 4// re-verify) -> APPLY only if cleared. So the loop heals itself but can never 5// clobber a canonical asset and never ships an unverified patch. 6// 7// This closes the last [next] autonomy item (auto-FIX in the governed tick), 8// composing nx_warden_paths (path safety) + nx_crew_council (3->2->1) + verify. 9// 10// APPLY additive + re-verified fix (e.g. ADD a missing regression gate) 11// DENY a fix that would OVERWRITE the known-good compiler (Warden hard-no) 12// ESCALATE a fix that does not re-verify sound (Engineer -> operator) 13// 14// Known answer: 3 detected problems -> 1 APPLIED, 1 DENIED, 1 ESCALATED. exit 0. 15 16import "nx_crew_council.nx" 17import "nx_warden_paths.nx" 18 19const DH_N: i64 = 3 20 21func main() -> i64 { 22 // each heal: problem + proposed fix {action_kind, target path, re-verifies?} 23 let prob: *i64 = sys_mmap(8 * DH_N) as *i64 24 let act: *i64 = sys_mmap(8 * DH_N) as *i64 25 let path: *i64 = sys_mmap(8 * DH_N) as *i64 26 let rv: *i64 = sys_mmap(8 * DH_N) as *i64 27 28 prob[0]=("print-stack regression gate missing" as *u8) as i64 29 act[0]=WP_CREATE; path[0]=("runtime/_hdl_build/nx_print_fix_test.nx" as *u8) as i64; rv[0]=1 // additive, re-verified 30 prob[1]=("compiler drift detected" as *u8) as i64 31 act[1]=WP_OVERWRITE; path[1]=("_offc/nx_cc_known_good.elf" as *u8) as i64; rv[1]=1 // would clobber canonical 32 prob[2]=("a miscompile -- speculative patch" as *u8) as i64 33 act[2]=WP_OVERWRITE; path[2]=("runtime/nx_opt.nx" as *u8) as i64; rv[2]=0 // does not re-verify 34 35 cc_puts("================================================================\n" as *u8) 36 cc_puts(" DOCTOR HEAL (auto-FIX), GOVERNED -- detect -> propose -> 3->2->1\n" as *u8) 37 cc_puts(" -> apply only if SAFE (path) + RE-VERIFIED. canonical untouchable.\n" as *u8) 38 cc_puts("================================================================\n" as *u8) 39 40 let a: *CrewAction = sys_mmap(64) as *CrewAction 41 let why: *i64 = sys_mmap(8) as *i64 42 var applied: i64 = 0 43 var denied: i64 = 0 44 var escalated: i64 = 0 45 46 var i: i64 = 0 47 while i < DH_N { 48 // WARDEN derives safety from the fix's target path + action. 49 let safe: i64 = nx_warden_path_safe(act[i], path[i] as *u8) 50 cc_set(a, path[i] as *u8, rv[i], 1, 1, safe, 1) // verifies=re-verifies, safe=warden(path) 51 let vd: i64 = cc_council(a, why) 52 cc_puts(" detect: " as *u8); cc_puts(prob[i] as *u8) 53 cc_puts("\n fix: " as *u8); cc_puts(path[i] as *u8) 54 cc_puts("\n -> [" as *u8); cc_puts(cc_verdict_name(vd)); cc_puts("] " as *u8); cc_puts(why[0] as *u8); cc_puts("\n" as *u8) 55 if vd == CC_ACT { applied = applied + 1 } 56 if vd == CC_DENY { denied = denied + 1 } 57 if vd == CC_ESCALATE { escalated = escalated + 1 } 58 i = i + 1 59 } 60 61 cc_puts("----------------------------------------------------------------\n" as *u8) 62 cc_puts(" healed: APPLIED " as *u8) 63 let ap: *u8 = sys_mmap(2); ap[0] = 48 + applied; sys_write(1, ap, 1) 64 cc_puts(" | DENIED " as *u8); let dn: *u8 = sys_mmap(2); dn[0] = 48 + denied; sys_write(1, dn, 1) 65 cc_puts(" | ESCALATED " as *u8); let es: *u8 = sys_mmap(2); es[0] = 48 + escalated; sys_write(1, es, 1) 66 cc_puts("\n the loop SELF-HEALS: additive verified fixes land; a fix that would\n" as *u8) 67 cc_puts(" clobber the known-good compiler is hard-denied; an unverified patch\n" as *u8) 68 cc_puts(" escalates to the operator. auto-FIX, M0->M2, safely.\n" as *u8) 69 cc_puts("----------------------------------------------------------------\n" as *u8) 70 71 if applied != 1 { sys_exit(1); return 1 } 72 if denied != 1 { sys_exit(2); return 2 } 73 if escalated != 1 { sys_exit(3); return 3 } 74 sys_exit(0) 75 return 0 76}