code wiki / _hdl_build / nx_hang_resolve_test.nx

nx_hang_resolve_test.nx source

↩ module page · 42 lines · 3316 B

1// nx_hang_resolve_test.nx -- the team solves problems within the operator's SLA (<=3 steps/30s; Engineer 2// optimal 1 step/<10s). The codegen hang is a KNOWN pattern, so the Engineer resolves it in 1 step 3// (apply the known fix = SPLIT the offending function) -> OPTIMAL. An unknown issue costs 3 steps but 4// stays within SLA. A sloppy 5-step/45s resolution VIOLATES the principle and is flagged. Exit 0 on 7/7. 5// license_tier: ORIGINAL 6 7import "nx_hang_resolve.nx" 8import "nx_syscalls.nx" 9 10func ht_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func ht_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 } 12 13func main() -> i64 { 14 ht_puts("=== ENGINEER hang-resolution under the <=3-step/30s SLA (optimal 1 step/<10s) ===\n" as *u8) 15 // codegen hang = KNOWN pattern -> Engineer applies the known fix in 1 step (~5s) 16 let cg_steps: i64 = hr_resolution_steps(1) 17 let cg_grade: i64 = hr_grade(cg_steps, 5) 18 let cg_fix: i64 = hr_fix_for(1) 19 // an unknown issue -> 3 steps (isolate+fix+verify), ~25s -> within SLA 20 let unk_steps: i64 = hr_resolution_steps(0) 21 let unk_grade: i64 = hr_grade(unk_steps, 25) 22 // a sloppy resolution -> over the principle 23 let bad_grade: i64 = hr_grade(5, 45) 24 25 ht_puts(" codegen hang (KNOWN): steps=" as *u8); ht_num(cg_steps); ht_puts(" grade=" as *u8); ht_num(cg_grade); ht_puts(" (2=OPTIMAL) fix=" as *u8); ht_num(cg_fix); ht_puts(" (1=SPLIT the offending fn)\n" as *u8) 26 ht_puts(" unknown issue: steps=" as *u8); ht_num(unk_steps); ht_puts(" grade=" as *u8); ht_num(unk_grade); ht_puts(" (1=within SLA)\n" as *u8) 27 ht_puts(" sloppy 5-step/45s: grade=" as *u8); ht_num(bad_grade); ht_puts(" (0=OVER, violates the principle)\n" as *u8) 28 29 let r: *i64 = sys_mmap(8*8) as *i64 30 r[0] = 0; if cg_steps == 1 { r[0] = 1 } // Engineer resolves the known hang in 1 step 31 r[1] = 0; if cg_grade == HR_OPTIMAL { r[1] = 1 } // ...OPTIMAL (1 step <10s) 32 r[2] = 0; if cg_fix == HR_FIX_SPLIT_FN { r[2] = 1 } // the known fix = split the offending function 33 r[3] = 0; if unk_steps == 3 { if unk_grade == HR_SLA { r[3] = 1 } } // unknown -> 3 steps, within SLA 34 r[4] = 0; if bad_grade == HR_OVER { r[4] = 1 } // >3 steps/30s flagged as over 35 r[5] = 0; if hr_codegen_hang_optimal() == 1 { r[5] = 1 } // the daemon-hang resolution IS optimal 36 r[6] = 0; if hr_within_sla(3, 30) == 1 { if hr_within_sla(4, 10) == 0 { if hr_within_sla(1, 31) == 0 { r[6] = 1 } } } // SLA boundaries 37 var pass: i64 = 0; var i: i64 = 0 38 while i < 7 { pass = pass + r[i]; i = i + 1 } 39 ht_puts("----\n passed " as *u8); ht_num(pass); ht_puts("/7\n" as *u8) 40 if pass == 7 { ht_puts(" SLA-BOUND PROBLEM-SOLVING: the Engineer resolves the codegen hang in 1 step / <10s (recognize fat-fn pattern -> SPLIT the offending function), unknowns in <=3 steps / 30s -- the operator's decision-fatigue rule applied to the team itself.\n" as *u8); sys_exit(0); return 0 } 41 ht_puts(" FAIL\n" as *u8); sys_exit(1); return 1 42}