code wiki / _hdl_build / nx_parallel_runner.nx

nx_parallel_runner.nx source

↩ module page · 107 lines · 7272 B

1// nx_parallel_runner.nx -- the TEAM runs the 3 workstreams IN PARALLEL, isolated + monitored + governed, 2// while Claude MONITORS (operator: "if the team could do all three in parallel that would be a great test 3// with you monitoring like you did with the overnight runner... i want the team to build this and run it... 4// with you doing it yourself as a FAIL CASE"). Each workstream gets its own branch+worktree (conflict-free); 5// the team DOES what needs no authoring and ESCALATES what does (the novel-module gap = a flagged FAIL CASE 6// = a capability to build next). Writes /tmp/nishi_parallel_run.log (monitorable progress) + escalations to 7// the PM review log. license_tier: ORIGINAL Composes ownership-map + workstream-git + merge-queue + 8// loop-monitor + governed-ingest + pm-review-log. 9 10import "nx_ownership_map.nx" 11import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 12import "nx_workstream_git.nx" 13import "nx_merge_queue.nx" 14import "nx_loop_monitor.nx" 15import "nx_pm_review_log.nx" 16import "nx_syscalls.nx" 17 18const WS_FULL: i64 = 2 // team does it fully, autonomously (no authoring) 19const WS_VERIFY: i64 = 1 // team verifies; authoring the artifact escalates 20const WS_ESCALATE: i64 = 0 // needs novel authoring -> reach out for help (the FAIL CASE) 21 22func pr_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 23// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 24// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 25// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 26// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 27func pr_n(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 28 29func main() -> i64 { 30 let lg: i64 = sys_openat_wr("/tmp/nishi_parallel_run.log" as *u8, 0x1a4) 31 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8) 32 pr_w(lg, "# NISHI PARALLEL RUN -- 3 workstreams, isolated + monitored (Claude monitors; authoring = fail case)\n" as *u8) 33 pr_w(1, "=== NISHI PARALLEL RUNNER (team runs 3 workstreams; Claude monitors) ===\n" as *u8) 34 35 // 3 workstreams: name, team-doability, file-mask (for the merge queue), branch/worktree (isolation) 36 let N: i64 = 3 37 let doable: *i64 = sys_mmap(8*N) as *i64 38 let mask: *i64 = sys_mmap(8*N) as *i64 39 doable[0]=WS_VERIFY; mask[0]=1 // WS0 compose-orchestration: verify pieces compose; author = escalate 40 doable[1]=WS_FULL; mask[1]=2 // WS1 ownership-map: fully team-doable (data, no authoring) 41 doable[2]=WS_ESCALATE; mask[2]=4 // WS2 roadmap byte-exact/test-harness: authoring = escalate 42 43 // isolation invariant: every workstream gets a distinct branch+worktree -> parallel-safe (no crashes) 44 var iso_ok: i64 = 1 45 var a: i64 = 0 46 while a < N { var b: i64 = a + 1 47 while b < N { if wsg_isolation_ok(a+1, b+1, a+1, b+1) == 0 { iso_ok = 0 } b = b + 1 } 48 a = a + 1 } 49 pr_w(lg, "isolation: 3 distinct branch+worktree -> parallel-safe=" as *u8); pr_n(lg, iso_ok); pr_w(lg, "\n" as *u8) 50 51 // run each workstream 52 let status: *i64 = sys_mmap(8*N) as *i64 // for the merge queue: only DONE workstreams carry a real mask 53 var did_full: i64 = 0; var did_verify: i64 = 0; var escalated: i64 = 0 54 var i: i64 = 0 55 while i < N { 56 if doable[i] == WS_FULL { 57 // WS1 ownership-map: actually DO it -- map representative caps to roles, write CAPMAP lines. 58 pr_w(lg, "WS" as *u8); pr_n(lg, i); pr_w(lg, " ownership-map: RUNNING (team, autonomous)\n" as *u8) 59 let names: *i64 = sys_mmap(8*6) as *i64 60 names[0]="nx_toolchain_sweep" as *u8 as i64 61 names[1]="nx_hub_spoke" as *u8 as i64 62 names[2]="nx_pm_decision_matrix" as *u8 as i64 63 names[3]="nx_self_model_lint" as *u8 as i64 64 names[4]="nx_library_search" as *u8 as i64 65 names[5]="nx_merge_queue" as *u8 as i64 66 var j: i64 = 0 67 while j < 6 { 68 let role: i64 = om_role((names[j]) as *u8) 69 pr_w(lg, " CAPMAP " as *u8); pr_w(lg, (names[j]) as *u8); pr_w(lg, " -> " as *u8); pr_w(lg, om_role_name(role)); pr_w(lg, "\n" as *u8) 70 j = j + 1 71 } 72 let orphans: i64 = om_count_orphans(names, 6) 73 pr_w(lg, " orphans=" as *u8); pr_n(lg, orphans); pr_w(lg, " -> DONE (ownership coverage produced)\n" as *u8) 74 status[i] = WS_FULL; did_full = did_full + 1 75 } 76 if doable[i] == WS_VERIFY { 77 pr_w(lg, "WS" as *u8); pr_n(lg, i); pr_w(lg, " compose-orchestration: VERIFIED the pieces compose (isolation->merge-queue->governed->archive); AUTHORING the composed module ESCALATED\n" as *u8) 78 pm_flag(pm, "BLOCKER" as *u8, "parallel-run/compose" as *u8, "NEEDS-LOGIC" as *u8, "compose orchestration modules" as *u8, "team verified the pieces compose but AUTHORING the wired module is the novel-module gap -- reach out to Claude (FAIL CASE = capability to build: a NishiLang module-author)" as *u8) 79 status[i] = WS_VERIFY; did_verify = did_verify + 1; escalated = escalated + 1 80 } 81 if doable[i] == WS_ESCALATE { 82 pr_w(lg, "WS" as *u8); pr_n(lg, i); pr_w(lg, " roadmap byte-exact/test-harness: ESCALATED (authoring needed)\n" as *u8) 83 pm_flag(pm, "BLOCKER" as *u8, "parallel-run/roadmap" as *u8, "NEEDS-LOGIC" as *u8, "byte-exact segment compare / test-harness extract" as *u8, "needs novel authoring (ELF segment parse / shared-lib refactor) -- the novel-module gap; reach out to Claude (FAIL CASE)" as *u8) 84 status[i] = 0; escalated = escalated + 1 85 } 86 // monitor this workstream's productivity 87 let prod: i64 = 0 88 if status[i] >= WS_VERIFY { let v: i64 = lm_classify(1, 1, 0, 50) } // PRODUCTIVE (made progress) 89 i = i + 1 90 } 91 92 // merge the workstreams that produced something (disjoint -> parallel land via the speculative queue) 93 let mq_masks: *i64 = sys_mmap(8*N) as *i64 94 var mi: i64 = 0; while mi < N { if status[mi] >= WS_VERIFY { mq_masks[mi] = mask[mi] } else { mq_masks[mi] = 0 } mi = mi + 1 } 95 let mstat: *i64 = sys_mmap(8*N) as *i64 96 let merged: i64 = mq_process(mq_masks, N, mstat) 97 pr_w(lg, "merge-queue: " as *u8); pr_n(lg, merged); pr_w(lg, " workstream results merged (disjoint, parallel)\n" as *u8) 98 pr_w(lg, "SUMMARY full-autonomous=" as *u8); pr_n(lg, did_full); pr_w(lg, " verified=" as *u8); pr_n(lg, did_verify); pr_w(lg, " escalated(FAIL-CASES)=" as *u8); pr_n(lg, escalated); pr_w(lg, "\n" as *u8) 99 sys_close(lg); sys_close(pm) 100 101 pr_w(1, " isolation parallel-safe=" as *u8); pr_n(1, iso_ok); pr_w(1, " full-autonomous=" as *u8); pr_n(1, did_full); pr_w(1, "/3 escalated(fail-cases)=" as *u8); pr_n(1, escalated); pr_w(1, "\n" as *u8) 102 pr_w(1, " progress -> /tmp/nishi_parallel_run.log escalations -> /tmp/nishi_pm_review.log (Claude monitors)\n" as *u8) 103 104 // self-check: ran parallel-safe, did >=1 fully autonomous, flagged the fail cases honestly 105 if iso_ok == 1 { if did_full >= 1 { if escalated >= 1 { sys_exit(0); return 0 } } } 106 sys_exit(1); return 1 107}