code wiki / _hdl_build / nx_orchestrate.nx
nx_orchestrate.nx source
↩ module page · 421 lines · 24799 B
1// nx_orchestrate.nx -- auto lane (eats debt seq163). WAIT-FOR-OPENING QUEUE: sessions QUEUE actions blocked
2// by a sibling's in-flight work instead of colliding. Each knowledge/store/deployq- row =
3// id | title | precondition | status | planid | note
4// precondition = a CHECKABLE predicate, now COMPOUND-capable (v2, 2026-07-20 -- for safe mgmt deploys that
5// must fire only when the fix is STAGED *and* mgmt is CALM):
6// exists:<path> | contains:<path>:<needle> -- single, OR
7// headroom:[<floor_mb>[:<max_centiload>]] -- the box has build headroom NOW (2026-08-18): forks
8// nx_build_admit check [floor] [max]; satisfied iff it GRANTS (exit 0). QUEUE/DENY-MEM/
9// unreadable-proc all WAIT -- a guard that cannot measure must not fire (fail-closed). This is
10// the wait-for-opening absorber nx_build_admit's own header says its QUEUE verdict was designed
11// for, and that /api/build's REFUSED-LOAD ("nothing is queued for you anywhere") had never
12// been given: a queued build row `headroom: -> plan build-<target>` now fires on the poller
13// pass after the opening appears, instead of a human re-issuing it by hand.
14// <pred> && <pred> -- AND of two (BOTH must hold to fire)
15// (e.g. exists:nx_mgmt_api.elf.new && contains:knowledge/status/api_contract.log:VERDICT=GREEN).
16// This POLLER (cron */5, non-blocking) evaluates every `queued` row: satisfied -> FIRE the row's plan via
17// nx_plan_run (reusing its allowlist+pinned-arg security WHOLESALE -- an action is a pre-seeded plan-
18// workflow, never arbitrary exec) and re-put the row status=fired-rc<N>; unsatisfied -> WAIT (logged, no
19// dead thread, no clobber). SOTA: Temporal durable await-condition, sovereign. Never-brick: fires only plans.
20// nx_orchestrate run [qprefix] [outlog]
21// ENVELOPE v4 (2026-08-29): scan UNCAPPED -- the v3 cap counted SCANNED lines, so 63 dead history rows
22// at the plane head exhausted it and every queued row past index 63 was silently unreachable (measured
23// live: 135 queued rows, fired=0 on every pass, first queued row at plane index exactly 64). A CAP MUST
24// BOUND WORK, NOT SCAN: evaluations of queued rows cap at OC_EVAL_CAP, fires at OC_FIRE_CAP, overflow is
25// COUNTED AND PRINTED (deferred= / fire_deferred=), never dropped in silence. ONE pass at a time (flock;
26// a slow pass makes the next refuse rather than double-fire rows still marked queued).
27// exit: 0 ran (counts printed, or PASS-ALREADY-RUNNING) | 4 queue unreadable | 2 usage.
28// license_tier: ORIGINAL expect_exit: 0
29import "nx_tool_run.nx"
30const K_MAGIC_30000: i64 = 30000
31const K_MAGIC_262144: i64 = 262144
32const K_MAGIC_262160: i64 = 262160
33const K_MAGIC_65536: i64 = 65536
34const K_MAGIC_32768: i64 = 32768
35const K_MAGIC_65535: i64 = 65535
36// v4 work caps (see ENVELOPE above). OC_EVAL_CAP keeps the incumbent 64-per-pass envelope but counts
37// EVALUATIONS of queued rows (each may fork the admit check), never scanned lines. OC_FIRE_CAP: a fire
38// is a sequential nx_plan_run build measured ~40 s at load1_centi=1060; 4 keeps a typical pass inside
39// one */5 cron interval while draining 48+ rows/hour -- pacing, not correctness (the flock owns
40// correctness). OC_FIRE_TIMEOUT_MS: a wedged plan_run must not hold the pass lock forever; ~15x the
41// measured loaded build time.
42const OC_EVAL_CAP: i64 = 64
43const OC_FIRE_CAP: i64 = 4
44const OC_FIRE_TIMEOUT_MS: i64 = 600000
45const OC_LOCK: *u8 = "knowledge/status/orchestrate.lock"
46
47func oc_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 }
48func oc_b(rep: *u8, pos: i64, s: *u8) -> i64 { var p: i64 = pos; var i: i64 = 0; while s[i] != (0 as u8) { if p < K_MAGIC_30000 { rep[p] = s[i]; p = p + 1 } i = i + 1 } return p }
49func oc_bn(rep: *u8, pos: i64, v: i64) -> i64 { var p: i64 = pos; var m: i64 = v; if m < 0 { if p < K_MAGIC_30000 { rep[p] = 45 as u8; p = p + 1 } m = 0 - m } let t: *u8 = sys_mmap(28); var k: i64 = 0; if m == 0 { t[0] = 48 as u8; k = 1 } while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } var i: i64 = 0; while i < k { if p < K_MAGIC_30000 { rep[p] = t[k - 1 - i]; p = p + 1 } i = i + 1 } return p }
50func oc_reads(path: *u8, buf: *u8, cap: i64) -> i64 {
51 let fd: i64 = sys_openat_rd(path)
52 if fd < 0 { return 0 - 1 }
53 var n: i64 = 0
54 var go: i64 = 1
55 while go == 1 { let r: i64 = sys_read(fd, (buf as i64 + n) as *u8, cap - n); if r <= 0 { go = 0 } else { n = n + r } if n >= cap { go = 0 } }
56 sys_close(fd)
57 return n
58}
59func oc_has(buf: *u8, s: i64, e: i64, pat: *u8) -> i64 {
60 var pl: i64 = 0
61 while pat[pl] != (0 as u8) { pl = pl + 1 }
62 if pl == 0 { return 0 }
63 var i: i64 = s
64 var hit: i64 = 0
65 while i + pl <= e {
66 var k: i64 = 0
67 var m: i64 = 1
68 while k < pl { if buf[i + k] != pat[k] { m = 0; k = pl } else { k = k + 1 } }
69 if m == 1 { hit = 1; i = e } else { i = i + 1 }
70 }
71 return hit
72}
73func oc_cpz(dst: *u8, cap: i64, buf: *u8, s: i64, e: i64) -> i64 {
74 var d: i64 = 0
75 var i: i64 = s
76 while i < e { if d < cap - 1 { dst[d] = buf[i]; d = d + 1 } i = i + 1 }
77 dst[d] = 0 as u8
78 return d
79}
80// nx_build_admit is the ONE ruler for "does the box have headroom" (the same binary nx_sov_build_run
81// consults before every compile) -- composed, never re-derived. Bounded: a stuck admit cannot stall
82// the poller past OC_ADMIT_TIMEOUT_MS (it reads /proc; measured well under 100 ms).
83const OC_ADMIT: *u8 = "/volume1/homes/elderwesto/nishihost/nx_build_admit.elf"
84const OC_ADMIT_TIMEOUT_MS: i64 = 10000
85func oc_pre(s: *u8, pre: *u8) -> i64 {
86 var i: i64 = 0
87 while pre[i] != (0 as u8) { if s[i] != pre[i] { return 0 - 1 } i = i + 1 }
88 return i
89}
90// evaluate ONE predicate (null-term): 1 satisfied, 0 unsatisfied, -2 malformed. fbuf = scratch 256KB.
91func oc_eval(pred: *u8, fpath: *u8, fneedle: *u8, fbuf: *u8) -> i64 {
92 let ex: i64 = oc_pre(pred, "exists:" as *u8)
93 if ex > 0 {
94 var d2: i64 = 0
95 var s2: i64 = ex
96 while pred[s2] != (0 as u8) { if d2 < 598 { fpath[d2] = pred[s2]; d2 = d2 + 1 } s2 = s2 + 1 }
97 fpath[d2] = 0 as u8
98 let tfd: i64 = sys_openat_rd(fpath)
99 if tfd >= 0 { sys_close(tfd); return 1 }
100 return 0
101 }
102 let hr: i64 = oc_pre(pred, "headroom:" as *u8)
103 if hr > 0 {
104 // optional "<floor_mb>[:<max_centiload>]" -- passed through as the admit organ's own argv,
105 // so its parsing (and its refusal of malformed numbers) stays the single source of truth.
106 var d5: i64 = 0
107 var s5: i64 = hr
108 var seg: i64 = 0
109 var stop5: i64 = 0
110 while stop5 == 0 {
111 let c: i64 = pred[s5]
112 if c == 0 { stop5 = 1 } else {
113 if c == 58 { seg = 1; s5 = s5 + 1; d5 = 0 } else {
114 if seg == 0 { if d5 < 62 { fpath[d5] = c as u8; d5 = d5 + 1; fpath[d5] = 0 as u8 } }
115 if seg == 1 { if d5 < 62 { fneedle[d5] = c as u8; d5 = d5 + 1; fneedle[d5] = 0 as u8 } }
116 s5 = s5 + 1
117 }
118 }
119 }
120 if seg == 0 { fneedle[0] = 0 as u8 }
121 if hr == s5 { fpath[0] = 0 as u8 } // bare "headroom:" -> defaults
122 let av: *i64 = sys_mmap(8 * 5) as *i64
123 av[0] = OC_ADMIT as i64
124 av[1] = "check" as *u8 as i64
125 var na: i64 = 2
126 if fpath[0] != (0 as u8) { av[na] = fpath as i64; na = na + 1 }
127 if fneedle[0] != (0 as u8) { av[na] = fneedle as i64; na = na + 1 }
128 av[na] = 0
129 let olen: *i64 = sys_mmap(16) as *i64
130 let arc: i64 = tr_run_capture_to(OC_ADMIT, av, fbuf, K_MAGIC_262144, olen, OC_ADMIT_TIMEOUT_MS)
131 if arc == 0 { return 1 }
132 return 0
133 }
134 let co: i64 = oc_pre(pred, "contains:" as *u8)
135 if co > 0 {
136 var d3: i64 = 0
137 var s3: i64 = co
138 var stop: i64 = 0
139 while stop == 0 { let c: i64 = pred[s3]; if c == 0 { stop = 1 } else { if c == 58 { stop = 2 } else { if d3 < 598 { fpath[d3] = c as u8; d3 = d3 + 1 } s3 = s3 + 1 } } }
140 fpath[d3] = 0 as u8
141 if stop != 2 { return 0 - 2 }
142 var d4: i64 = 0
143 var s4: i64 = s3 + 1
144 while pred[s4] != (0 as u8) { if d4 < 598 { fneedle[d4] = pred[s4]; d4 = d4 + 1 } s4 = s4 + 1 }
145 fneedle[d4] = 0 as u8
146 let fn2: i64 = oc_reads(fpath, fbuf, K_MAGIC_262144)
147 if fn2 < 0 { return 0 }
148 return oc_has(fbuf, 0, fn2, fneedle)
149 }
150 return 0 - 2
151}
152// evaluate a (possibly compound A && B) precondition string.
153func oc_eval_pre(fpre: *u8, fpath: *u8, fneedle: *u8, fbuf: *u8, lbuf: *u8, rbuf: *u8) -> i64 {
154 // find "&&"
155 var amp: i64 = 0 - 1
156 var i: i64 = 0
157 while fpre[i] != (0 as u8) { if fpre[i] == (38 as u8) { if fpre[i+1] == (38 as u8) { amp = i; } } if amp >= 0 { i = i } i = i + 1 }
158 if amp < 0 { return oc_eval(fpre, fpath, fneedle, fbuf) }
159 // left = [0, amp) trimmed of trailing spaces; right = after amp+2, skipping leading spaces
160 var le: i64 = amp
161 while le > 0 { if fpre[le-1] == (32 as u8) { le = le - 1 } else { let z: i64 = le; le = 0 - 2 - z } }
162 if le < 0 { le = 0 - 2 - le }
163 var d: i64 = 0
164 var j: i64 = 0
165 while j < le { if d < 700 { lbuf[d] = fpre[j]; d = d + 1 } j = j + 1 }
166 lbuf[d] = 0 as u8
167 var rs: i64 = amp + 2
168 var sk: i64 = 1
169 while sk == 1 { if fpre[rs] == (32 as u8) { rs = rs + 1 } else { sk = 0 } }
170 var d2: i64 = 0
171 while fpre[rs] != (0 as u8) { if d2 < 700 { rbuf[d2] = fpre[rs]; d2 = d2 + 1 } rs = rs + 1 }
172 rbuf[d2] = 0 as u8
173 let l: i64 = oc_eval(lbuf, fpath, fneedle, fbuf)
174 if l == (0 - 2) { return 0 - 2 }
175 let r: i64 = oc_eval(rbuf, fpath, fneedle, fbuf)
176 if r == (0 - 2) { return 0 - 2 }
177 if l == 1 { if r == 1 { return 1 } }
178 return 0
179}
180// THE RUNNER'S OWN ADMISSION REFUSAL, RECOGNISED IN THE FIRE CAPTURE (2026-09-02). nx_plan_run relays
181// nx_sov_build_run's stdout, and the runner prints the ONE literal `REFUSED-BUILD-ADMIT` when its admission
182// check (the same nx_build_admit ruler this poller consulted a moment earlier) says QUEUE. Keyed on the
183// runner's own verdict token rather than on the plan_run rc, because rc=5 is also what a genuine compile
184// failure returns -- and those two need OPPOSITE remedies (re-fire later vs fix the source). Composes
185// oc_has, the file's one substring scanner. Returns 1 iff the capture carries the refusal.
186func oc_runner_refused(cap: *u8, n: i64) -> i64 {
187 if n <= 0 { return 0 }
188 return oc_has(cap, 0, n, "REFUSED-BUILD-ADMIT" as *u8)
189}
190
191// ---- LIVE LINES (2026-09-02). A pass used to print NOTHING until it finished: its whole report sat in `rep`
192// and was written at the end, so a pass stalled inside a fire, a plane load or a plane put was indistinguishable
193// from one that had not started, and later cron passes could only say PASS-ALREADY-RUNNING (measured that day:
194// 25+ minutes of silence while the box was I/O-bound). A PROCESS THAT SAYS NOTHING UNTIL IT IS DONE CANNOT BE
195// TOLD FROM ONE THAT IS STUCK. These lines go straight to stdout AND the pass log BEFORE the step they announce,
196// so the last line of the log names the step a stalled pass is inside. The plane load, the one unbounded call
197// left in the pass, is now deadline-bounded like every fire.
198const OC_LOAD_TIMEOUT_MS: i64 = 120000 // nx_store_put load: 2x the worst fsync convoy measured (~60 s), well under one cron interval
199const OC_LIVE_CAP: i64 = 4096
200func oc_dec(v: i64, out: *u8) -> i64 {
201 var m: i64 = v
202 var o: i64 = 0
203 if m < 0 { out[0] = 45 as u8; o = 1; m = 0 - m }
204 if m == 0 { out[o] = 48 as u8; out[o + 1] = 0 as u8; return o + 1 }
205 var nd: i64 = 0
206 var mm: i64 = m
207 while mm > 0 { nd = nd + 1; mm = mm / 10 }
208 var i: i64 = nd - 1
209 while m > 0 { out[o + i] = (48 + (m % 10)) as u8; m = m / 10; i = i - 1 }
210 out[o + nd] = 0 as u8
211 return o + nd
212}
213func oc_live(outlog: *u8, a: *u8, b: *u8, c: *u8, d: *u8) -> i64 {
214 let ln: *u8 = sys_mmap(OC_LIVE_CAP)
215 var o: i64 = 0
216 var i: i64 = 0
217 while a[i] != (0 as u8) { if o < OC_LIVE_CAP - 2 { ln[o] = a[i]; o = o + 1 } i = i + 1 }
218 i = 0
219 while b[i] != (0 as u8) { if o < OC_LIVE_CAP - 2 { ln[o] = b[i]; o = o + 1 } i = i + 1 }
220 i = 0
221 while c[i] != (0 as u8) { if o < OC_LIVE_CAP - 2 { ln[o] = c[i]; o = o + 1 } i = i + 1 }
222 i = 0
223 while d[i] != (0 as u8) { if o < OC_LIVE_CAP - 2 { ln[o] = d[i]; o = o + 1 } i = i + 1 }
224 ln[o] = 10 as u8
225 o = o + 1
226 sys_write(1, ln, o)
227 let fd: i64 = sys_openat_append(outlog, 420)
228 if fd >= 0 { sys_write(fd, ln, o); sys_close(fd) }
229 sys_munmap(ln, OC_LIVE_CAP)
230 return 0
231}
232
233func main(argc: i64, argv: *i64) -> i64 {
234 if argc < 2 { oc_w(2, "usage: nx_orchestrate run [qprefix] [outlog]\n" as *u8); sys_exit(2); return 2 }
235 var qprefix: *u8 = "knowledge/store/deployq-" as *u8
236 var outlog: *u8 = "knowledge/status/orchestrate.log" as *u8
237 if argc >= 3 { qprefix = argv[2] as *u8 }
238 if argc >= 4 { outlog = argv[3] as *u8 }
239 // ONE PASS AT A TIME (v4): fires are sequential child builds, so a slow pass can outlive the cron
240 // interval; the next pass must REFUSE, not double-fire rows still marked queued. flock releases on
241 // process death by construction, so a crashed pass can never wedge the queue closed. The fd is held
242 // open for the whole pass ON PURPOSE -- closing it would release the lock.
243 let lkfd: i64 = sys_openat_wr(OC_LOCK, 420)
244 if lkfd >= 0 {
245 if sys_flock(lkfd, SYS_LOCK_EX + SYS_LOCK_NB) != 0 {
246 oc_w(1, "ORCHESTRATE verdict=PASS-ALREADY-RUNNING (pass lock held by a live pass; not an error)\n" as *u8)
247 sys_exit(0)
248 }
249 } else {
250 oc_w(1, "ORCHESTRATE note=LOCK-UNAVAILABLE (cannot open lockfile; proceeding UNGUARDED -- overlap possible)\n" as *u8)
251 }
252 let ep: *u8 = sys_mmap(32)
253 oc_dec(sys_now_realtime_sec(), ep)
254 oc_live(outlog, "PASS-START epoch=", ep, " step=plane-load (bounded 120s; every fire bounded 600s; a pass that goes silent after this line is inside the step it last named)", "" as *u8)
255 let SP: *u8 = "/volume1/homes/elderwesto/nishihost/nx_store_put.elf" as *u8
256 let PR: *u8 = "/volume1/homes/elderwesto/nishihost/nx_plan_run.elf" as *u8
257 let qcap: i64 = K_MAGIC_262144
258 let qbuf: *u8 = sys_mmap(qcap + 16)
259 let olen: *i64 = sys_mmap(16) as *i64
260 let av: *i64 = sys_mmap(16 * 8) as *i64
261 av[0] = SP as i64
262 av[1] = qprefix as i64
263 av[2] = "load" as *u8 as i64
264 av[3] = 0
265 let lrc: i64 = tr_run_capture_to(SP, av, qbuf, qcap, olen, OC_LOAD_TIMEOUT_MS) // BOUNDED (2026-09-02): the one call in this pass that could stall forever
266 if lrc == (0 - 5) { oc_live(outlog, "ORCHESTRATE verdict=QUEUE-LOAD-TIMEOUT (nx_store_put load exceeded the 120 s bound -- the plane is fsync-bound; nothing fired, nothing changed; the next cron pass re-tries)", "" as *u8, "" as *u8, "" as *u8); sys_exit(4); return 4 }
267 let qn: i64 = olen[0]
268 if lrc == 127 { oc_w(1, "ORCHESTRATE verdict=QUEUE-UNREADABLE exec-127\n" as *u8); sys_exit(4); return 4 }
269 if lrc < 0 { oc_w(1, "ORCHESTRATE verdict=QUEUE-UNREADABLE harness\n" as *u8); sys_exit(4); return 4 }
270 let fid: *u8 = sys_mmap(128)
271 let ftitle: *u8 = sys_mmap(800)
272 let fpre: *u8 = sys_mmap(800)
273 let fstat: *u8 = sys_mmap(64)
274 let fplan: *u8 = sys_mmap(128)
275 let fnote: *u8 = sys_mmap(800)
276 let fpath: *u8 = sys_mmap(700)
277 let fneedle: *u8 = sys_mmap(700)
278 let lbuf: *u8 = sys_mmap(800)
279 let rbuf: *u8 = sys_mmap(800)
280 let stat2: *u8 = sys_mmap(64)
281 let fbuf: *u8 = sys_mmap(K_MAGIC_262160)
282 let cbuf: *u8 = sys_mmap(K_MAGIC_65536)
283 let rep: *u8 = sys_mmap(K_MAGIC_32768)
284 var p: i64 = 0
285 p = oc_b(rep, p, "ORCHESTRATE run queue_bytes=" as *u8); p = oc_bn(rep, p, qn)
286 p = oc_b(rep, p, " (v4 work-capped: scan uncapped, evals<=64, fires<=4/pass, overflow COUNTED as deferred; 256KB precond; predicates exists:/contains:/headroom: [&&]; fire=nx_plan_run timeout-bounded; pass flock)\n" as *u8)
287 if qn >= qcap { p = oc_b(rep, p, "QUEUE-AT-CAPTURE-CAP: the plane load filled the 256KB buffer -- the TAIL (newest rows) may be MISSING from this pass; compact the plane or raise the cap DELIBERATELY\n" as *u8) }
288 var fired: i64 = 0
289 var waiting: i64 = 0
290 var skipped: i64 = 0
291 var malformed: i64 = 0
292 var rows: i64 = 0
293 var evald: i64 = 0
294 var deferred: i64 = 0
295 var fdeferred: i64 = 0
296 var requeued: i64 = 0 // fires the RUNNER refused on its own admission -- the row stays queued (2026-09-02)
297 var i: i64 = 0
298 var ls: i64 = 0
299 while i <= qn {
300 var isend: i64 = 0
301 if i == qn { isend = 1 } else { if qbuf[i] == (10 as u8) { isend = 1 } }
302 if isend == 1 {
303 if i > ls { if rows > (0 - 1) {
304 rows = rows + 1
305 let fs2: *i64 = sys_mmap(64) as *i64
306 let fe2: *i64 = sys_mmap(64) as *i64
307 var nf: i64 = 1
308 fs2[0] = ls
309 var q: i64 = ls
310 while q < i { if qbuf[q] == (9 as u8) { if nf < 6 { fe2[nf-1] = q; fs2[nf] = q + 1; nf = nf + 1 } } q = q + 1 }
311 fe2[nf-1] = i
312 if nf >= 4 {
313 oc_cpz(fid, 128, qbuf, fs2[0], fe2[0])
314 oc_cpz(ftitle, 800, qbuf, fs2[1], fe2[1])
315 oc_cpz(fpre, 800, qbuf, fs2[2], fe2[2])
316 oc_cpz(fstat, 64, qbuf, fs2[3], fe2[3])
317 fplan[0] = 0 as u8
318 fnote[0] = 0 as u8
319 if nf >= 5 { oc_cpz(fplan, 128, qbuf, fs2[4], fe2[4]) }
320 if nf >= 6 { oc_cpz(fnote, 800, qbuf, fs2[5], fe2[5]) }
321 var isq: i64 = 0
322 if fstat[0] == 113 { if fstat[1] == 117 { if fstat[2] == 101 { if fstat[3] == 117 { if fstat[4] == 101 { if fstat[5] == 100 { if fstat[6] == (0 as u8) { isq = 1 } } } } } } }
323 if isq == 0 { skipped = skipped + 1 } else { if evald >= OC_EVAL_CAP { deferred = deferred + 1 } else {
324 evald = evald + 1
325 let sat: i64 = oc_eval_pre(fpre, fpath, fneedle, fbuf, lbuf, rbuf)
326 if sat == (0 - 2) {
327 malformed = malformed + 1
328 p = oc_b(rep, p, "MALFORMED-PRED id=" as *u8); p = oc_b(rep, p, fid); p = oc_b(rep, p, "\n" as *u8)
329 } else { if sat == 1 {
330 if fired >= OC_FIRE_CAP {
331 fdeferred = fdeferred + 1
332 p = oc_b(rep, p, "FIRE-DEFERRED id=" as *u8); p = oc_b(rep, p, fid); p = oc_b(rep, p, " (fire cap reached this pass; row stays queued)\n" as *u8)
333 } else {
334 if fplan[0] == (0 as u8) {
335 malformed = malformed + 1
336 p = oc_b(rep, p, "NO-PLANID id=" as *u8); p = oc_b(rep, p, fid); p = oc_b(rep, p, "\n" as *u8)
337 } else {
338 let av2: *i64 = sys_mmap(16 * 8) as *i64
339 av2[0] = PR as i64
340 av2[1] = fplan as i64
341 av2[2] = 0
342 let olen2: *i64 = sys_mmap(16) as *i64
343 oc_live(outlog, "FIRING id=", fid, " plan=", fplan) // announced BEFORE the fire (bounded 600 s), so a silent pass names the fire it is inside
344 let prc: i64 = tr_run_capture_to(PR, av2, cbuf, K_MAGIC_65535, olen2, OC_FIRE_TIMEOUT_MS)
345 // A FIRE THE RUNNER REFUSED IS NOT A FIRE (2026-09-02). This pass's headroom: check GRANTed,
346 // then nx_sov_build_run consulted the SAME ruler milliseconds later and said QUEUE (the D-state
347 // count is volatile: MEASURED live this day, BQ-nx_mgmt_api fired rc=5 at procs_blocked=10 of 8
348 // right after a sibling fire loaded the box). The row used to be re-put as fired-rc5 and the
349 // build was FORGOTTEN by the very queue that exists to remember it -- 13 fired-rc5 rows sat on
350 // the plane that day, every one a build nobody re-issued. A QUEUE THAT MARKS A REFUSED BUILD
351 // AS FIRED IS DECORATION. Now: the row STAYS queued, the pass fires nothing further (the box
352 // just said no), and the report names it so a reader can tell a refusal from a compile failure.
353 if oc_runner_refused(cbuf, olen2[0]) == 1 {
354 requeued = requeued + 1
355 p = oc_b(rep, p, "ADMIT-REFUSED-AT-FIRE id=" as *u8); p = oc_b(rep, p, fid)
356 p = oc_b(rep, p, " plan=" as *u8); p = oc_b(rep, p, fplan)
357 p = oc_b(rep, p, " (the runner's own admission said QUEUE after this pass's headroom check GRANTed; row STAYS queued, no further fires this pass)\n" as *u8)
358 fired = OC_FIRE_CAP
359 } else {
360 fired = fired + 1
361 var sp2: i64 = 0
362 let sfx: *u8 = "fired-rc" as *u8
363 while sfx[sp2] != (0 as u8) { stat2[sp2] = sfx[sp2]; sp2 = sp2 + 1 }
364 var m2: i64 = prc
365 if m2 < 0 { m2 = 99 }
366 if m2 >= 100 { m2 = 99 }
367 if m2 >= 10 { stat2[sp2] = (48 + (m2 / 10)) as u8; sp2 = sp2 + 1 }
368 stat2[sp2] = (48 + (m2 % 10)) as u8
369 stat2[sp2 + 1] = 0 as u8
370 let av3: *i64 = sys_mmap(16 * 8) as *i64
371 av3[0] = SP as i64
372 av3[1] = qprefix as i64
373 av3[2] = "put" as *u8 as i64
374 av3[3] = "nx_orchestrate" as *u8 as i64
375 av3[4] = fid as i64
376 av3[5] = ftitle as i64
377 av3[6] = fpre as i64
378 av3[7] = stat2 as i64
379 av3[8] = fplan as i64
380 av3[9] = fnote as i64
381 av3[10] = 0
382 let olen3: *i64 = sys_mmap(16) as *i64
383 tr_run_capture(SP, av3, cbuf, K_MAGIC_65535, olen3)
384 p = oc_b(rep, p, "FIRED id=" as *u8); p = oc_b(rep, p, fid)
385 p = oc_b(rep, p, " plan=" as *u8); p = oc_b(rep, p, fplan)
386 p = oc_b(rep, p, " rc=" as *u8); p = oc_bn(rep, p, prc)
387 p = oc_b(rep, p, "\n" as *u8)
388 } // end of the not-refused branch (2026-09-02)
389 }
390 }
391 } else {
392 waiting = waiting + 1
393 p = oc_b(rep, p, "WAITING id=" as *u8); p = oc_b(rep, p, fid)
394 p = oc_b(rep, p, " precond=" as *u8); p = oc_b(rep, p, fpre)
395 p = oc_b(rep, p, "\n" as *u8)
396 } }
397 } }
398 }
399 } }
400 ls = i + 1
401 }
402 i = i + 1
403 }
404 p = oc_b(rep, p, "SUMMARY rows=" as *u8); p = oc_bn(rep, p, rows)
405 p = oc_b(rep, p, " fired=" as *u8); p = oc_bn(rep, p, fired)
406 p = oc_b(rep, p, " waiting=" as *u8); p = oc_bn(rep, p, waiting)
407 p = oc_b(rep, p, " skipped=" as *u8); p = oc_bn(rep, p, skipped)
408 p = oc_b(rep, p, " malformed=" as *u8); p = oc_bn(rep, p, malformed)
409 p = oc_b(rep, p, " evaluated=" as *u8); p = oc_bn(rep, p, evald)
410 p = oc_b(rep, p, " deferred=" as *u8); p = oc_bn(rep, p, deferred)
411 p = oc_b(rep, p, " fire_deferred=" as *u8); p = oc_bn(rep, p, fdeferred)
412 p = oc_b(rep, p, " requeued=" as *u8); p = oc_bn(rep, p, requeued)
413 p = oc_b(rep, p, "\n" as *u8)
414 sys_write(1, rep, p)
415 let lfd: i64 = sys_openat_append(outlog, 420)
416 if lfd >= 0 { sys_write(lfd, rep, p); sys_close(lfd) }
417 let tfd2: i64 = sys_openat_wr("knowledge/status/orchestrate.out.tmp" as *u8, 420)
418 if tfd2 >= 0 { sys_write(tfd2, rep, p); sys_close(tfd2); sys_renameat("knowledge/status/orchestrate.out.tmp" as *u8, "knowledge/status/orchestrate.out" as *u8) }
419 sys_exit(0)
420 return 0
421}