nx_exec_engine.nx source
↩ module page · 76 lines · 6505 B
1// nx_exec_engine.nx -- AUTONOMY BOOTSTRAP (tutor-authored SEED, the mechanism the team lacks): an autonomous
2// execution loop that picks a workstream with a MACHINE-READABLE target, forks the team's evo-synth tool, and
3// ADVANCES the workstream ONLY IF the tool VERIFIES it generalized (exit 0 = held-out pass). This is the missing
4// piece behind the 0-alive board: monitoring+practice existed, execution did not. Honestly gated: a neg-control
5// (a run that exits non-zero) proves advancement is VERIFY-GATED, not always-on -- the engine never fakes work.
6// HONEST SCOPE: only advances targets the evo tools can hit (arithmetic/branch/loop). Novel capability (a neural
7// forward) has NO machine-executable path -> stays NEEDS_TUTOR. Composes _offc/nx_evo_cf + nx_evo_loop. license_tier: ORIGINAL expect_exit: 0
8import "nx_syscalls.nx"
9import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
10
11func ee_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
13// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
15// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
16func ee_putn(v: i64) -> i64 { nxi_out(v); return 0 }
17
18// fork+exec ./_offc/<tool> <a1> <a2> <a3>, silent; return WEXITSTATUS (0=GENERALIZES) or 128+sig on crash / 127 on exec-fail.
19func run_tool(path: *u8, a1: *u8, a2: *u8, a3: *u8) -> i64 {
20 let pid: i64 = sys_fork()
21 if pid == 0 {
22 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 420); if dn>=0 { sys_dup3(dn,1,0); sys_dup3(dn,2,0) }
23 let argv: *i64 = sys_mmap(64) as *i64
24 argv[0]=path as i64; argv[1]=a1 as i64; argv[2]=a2 as i64; argv[3]=a3 as i64; argv[4]=0
25 let envp: *i64 = sys_mmap(16) as *i64; envp[0]="PATH=/usr/bin:/bin" as *u8 as i64; envp[1]=0
26 sys_execve(path, argv, envp); sys_exit(127)
27 }
28 let st: *i64 = sys_mmap(16) as *i64; sys_wait4(pid, st, 0)
29 let sig: i64 = st[0] & 0x7f; if sig != 0 { return 128 + sig }
30 return (st[0] >> 8) & 0xff
31}
32
33func main() -> i64 {
34 ee_puts("=== nx_exec_engine -- AUTONOMY SEED: pick machine-target workstream -> run team tool -> VERIFY -> advance ===\n" as *u8)
35 var advanced: i64=0; var attempted: i64=0
36
37 // COVERED workstream 1: target expressed as an evo_cf branch program (|x|). The engine runs the TEAM's tool.
38 ee_puts("[covered] WS EXEC-ABS -> nx_evo_cf(|x|): running the team tool ... " as *u8)
39 attempted=attempted+1
40 let r1: i64 = run_tool("_offc/nx_evo_cf.elf" as *u8, "ee_abs" as *u8, "0" as *u8, "12345" as *u8)
41 if r1==0 { ee_puts("exit 0 = GENERALIZES (held-out) -> WORKSTREAM ADVANCED\n" as *u8); advanced=advanced+1 } else { ee_puts("exit="); ee_putn(r1); ee_puts(" (not generalized) -> NOT advanced\n" as *u8) }
42
43 // COVERED workstream 2: target expressed as an evo_loop iterative program (n!).
44 ee_puts("[covered] WS EXEC-FACT -> nx_evo_loop(n!): running the team tool ... " as *u8)
45 attempted=attempted+1
46 let r2: i64 = run_tool("_offc/nx_evo_loop.elf" as *u8, "ee_fact" as *u8, "0" as *u8, "12345" as *u8)
47 if r2==0 { ee_puts("exit 0 = GENERALIZES (held-out) -> WORKSTREAM ADVANCED\n" as *u8); advanced=advanced+1 } else { ee_puts("exit="); ee_putn(r2); ee_puts(" (not generalized) -> NOT advanced\n" as *u8) }
48
49 // COVERED workstream 3: SELF-HEALING COMPILER HEALTH (the integration -- the compiler self-heal loop wired INTO
50 // the autonomy engine). nx_cc_health generate->build->runs a known-good shape; exit 0 = nx_cc healthy at scale.
51 ee_puts("[covered] WS CC-HEALTH -> nx_cc_health (self-healing compiler witness): running ... " as *u8)
52 attempted=attempted+1
53 let r3: i64 = run_tool("_offc/nx_cc_health.elf" as *u8, "x" as *u8, "x" as *u8, "x" as *u8)
54 if r3==0 { ee_puts("exit 0 = nx_cc HEALTHY -> WORKSTREAM ADVANCED\n" as *u8); advanced=advanced+1 } else { ee_puts("exit="); ee_putn(r3); ee_puts(" = COMPILER REGRESSION -> NOT advanced (self-healing alarm)\n" as *u8) }
55
56 // NEG-CONTROL: a run that CANNOT succeed (non-existent tool -> execve fails -> exit 127). The engine must NOT
57 // advance on a non-zero exit -> proves advancement is VERIFY-GATED (not always-on). This is also what happens
58 // to a NOVEL workstream (e.g. a neural forward): no tool can hit it -> exit!=0 -> honest NEEDS_TUTOR, never faked.
59 ee_puts("[neg-control] WS VOICE-NEURAL-FORWARD -> no machine-executable tool: " as *u8)
60 let rn: i64 = run_tool("_offc/nx_no_such_tool.elf" as *u8, "x" as *u8, "0" as *u8, "0" as *u8)
61 var neg_advanced: i64=0
62 if rn==0 { neg_advanced=1; ee_puts("exit 0?! (would advance -- BAD)\n" as *u8) } else { ee_puts("exit="); ee_putn(rn); ee_puts(" != 0 -> REFUSED (stays NEEDS_TUTOR; engine never fakes novel work)\n" as *u8) }
63
64 ee_puts("\nexec-engine: advanced="); ee_putn(advanced); ee_puts("/"); ee_putn(attempted); ee_puts(" covered ; neg_advanced="); ee_putn(neg_advanced); ee_puts("\n" as *u8)
65 var pass: i64=0; var tot: i64=2
66 if advanced==3 { pass=pass+1; ee_puts("PASS the engine AUTONOMOUSLY ran + VERIFIED 3 machine-target workstreams (2 evo-synth held-out + 1 SELF-HEALING COMPILER-HEALTH witness)\n" as *u8) } else { ee_puts("FAIL not all covered advanced ("); ee_putn(advanced); ee_puts("/3)\n" as *u8) }
67 if neg_advanced==0 { pass=pass+1; ee_puts("PASS neg-control: a non-zero exit did NOT advance -> advancement is VERIFY-GATED; novel work is refused, not faked\n" as *u8) } else { ee_puts("FAIL faked a non-verified advance\n" as *u8) }
68
69 ee_puts("nx_exec_engine pass="); ee_putn(pass); ee_puts("/"); ee_putn(tot)
70 if pass==tot {
71 ee_puts(" GREEN -- the AUTONOMY EXECUTION-ENGINE mechanism works (the piece behind the 0-alive board).\n" as *u8)
72 ee_puts("★HONEST COVERAGE: 0 of the 104 registered STALLED workstreams currently declare a machine-executable target, so this seed's real-board impact today = these demos. THE bottleneck (rung 2): (a) give real workstreams machine-readable targets + heartbeat-on-advance to wake the board, (b) grow the synthesizer PAST toy arithmetic to real capability. Mechanism proven; coverage is the next tutor+team arc, NOT a claim the team can build novel neural capability yet.\n" as *u8)
73 sys_exit(0); return 0
74 }
75 ee_puts(" RED\n" as *u8); sys_exit(1); return 1
76}