nx_segsweep.nx source
↩ module page · 354 lines · 21013 B
1// nx_segsweep.nx -- SOVEREIGN seg-store sweeper. The organ that retires nx_segguard.sh (2026-08-06).
2//
3// OPERATOR DOCTRINE: ".sh are not nishi ecosystem". nx_segguard.sh was a SHELL WRAPPER around an organ
4// that already existed -- it parsed segguard.conf with sed+head, enumerated the planes, and forked
5// nx_seg_compact_cli.elf ONCE PER PLANE under a lock. The real work is ss_compact_cap in nx_seg_store.nx,
6// a LIBRARY function callable in-process. With ~1087 manifests under knowledge/store that wrapper paid a
7// SUBSHELL PLUS A CLI FORK PER PLANE, plus date/sed/head/mkdir every tick.
8// MEASURED COST OF THE WRAPPER: 717s per run against a DECLARED 600s period (three independent
9// measurements: 655s, 700s+, 717s), and a sibling seat measured it consuming 1399s of an 1800s clock
10// window = 78pct, starving 31 of 45 jobs. It is also the direct source of the RED forks_per_sec=57 in
11// nx_procchurn. This organ replaces ~2x1087 forks with ZERO.
12// (STAR)A SHELL SCRIPT THAT WRAPS A SOVEREIGN ORGAN PAYS A PROCESS PER ITEM TO DO WORK THE LIBRARY WOULD
13// DO PER CALL -- THE COST IS NOT THE ALGORITHM, IT IS THE WRAPPER.
14// (STAR)THE SLOWEST THING ON A SOVEREIGN BOX IS THE PART THAT IS NOT SOVEREIGN YET.
15//
16// THE ONE THING THIS MUST NOT INHERIT: nx_seg_compact_cli.elf takes a BLOCKING flock(LOCK_EX) and holds
17// it until PROCESS EXIT. Its own header records what that cost: "48 nx_segguard.sh + 24 nx_seg_compact_cli
18// stacked, all State=S, oldest ~6h, thread count climbing ~260/hr on a box already 92pct into swap."
19// A blocking lock is survivable in a fork-per-plane design because the process dies; in a SINGLE
20// long-lived sweeper it would wedge the whole sweep forever. So this organ takes LOCK_EX|LOCK_NB and
21// SKIPS a contended plane, and CLOSES the fd every iteration so locks can never accumulate.
22// (STAR)A LOCK DISCIPLINE THAT IS SAFE ONLY BECAUSE THE PROCESS EXITS IS NOT SAFE IN A PROCESS THAT DOES NOT.
23//
24// BOUNDED + RESUMABLE (rule 10, idempotent): a wall-clock budget caps one run, and a persisted CURSOR
25// makes the next run continue where this one stopped. A budget WITHOUT a cursor would re-scan the same
26// alphabetical head forever and never reach the tail -- silent permanent blindness for whatever sorts last.
27// nx_segsweep [threshold] [budget_secs]
28// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
29import "nx_syscalls.nx"
30import "nx_seg_store.nx"
31
32const SW_STORE: *u8 = "knowledge/store"
33const SW_CONF: *u8 = "knowledge/status/segguard.conf"
34const SW_LOG: *u8 = "knowledge/status/segsweep.log"
35const SW_CURSOR: *u8 = "knowledge/status/segsweep.cursor"
36const SW_SUFFIX: *u8 = "-manifest.txt"
37const SW_DIRBUF: i64 = 262144
38const SW_NAMEW: i64 = 256
39const SW_MAXPLANES: i64 = 4096
40const SW_LOCK_NB: i64 = 6 // LOCK_EX(2) | LOCK_NB(4) -- NEVER plain LOCK_EX here, see header
41const SW_MODE: i64 = 0x1a4
42const SW_DEF_THRESH: i64 = 8
43const SW_DEF_BUDGET: i64 = 120
44const SW_COMPACT_CAP: i64 = 100000
45// The CLI is addressed ABSOLUTELY: its own header warns it resolves <prefix> relative to the nishihost
46// CWD, and the .sh notes getting that wrong makes it see 0 live segments and fail closed silently.
47const SW_CLI: *u8 = "/volume1/homes/elderwesto/nishihost/nx_seg_compact_cli.elf"
48// 300 = compact-timeout-seconds from segguard.conf (rule 11: the number lives in config, not here --
49// this const is the FALLBACK when the conf cannot be read, matching the conf's own documented value).
50const SW_CLI_TIMEOUT: i64 = 300
51// FOLDABILITY CEILING (2026-08-07). MEASURED THE HARD WAY: the first live run walked to idx=1087 and
52// found knowledge/store/dp-web-pub- with 913 LIVE SEGMENTS, forked the CLI at it, and never came back.
53// segguard.conf carries exclude-prefixes for exactly this ("scale-shard exclusion, seq1266: planes the
54// CLI structurally cannot fold in time") -- I READ that key, wrote "my organ IGNORES exclusions" in my
55// own notes, and then shipped without it. A numeric ceiling is the DATA-DRIVEN form of that exclusion:
56// it needs no prefix list, it cannot go stale as planes are added, and it states the real property
57// (too many segments to fold inside the timeout) rather than naming today's offenders.
58// (STAR)A GAP YOU NOTICED AND DID NOT CLOSE IS INDISTINGUISHABLE FROM ONE YOU NEVER SAW.
59const SW_MAXFOLD: i64 = 256
60// Bounded reap after SIGKILL. nx_hostctl's galxidxkick records that a SIGKILL on a D-STATE process does
61// NOT land until its I/O completes -- and a heavy compaction is exactly that. A BLOCKING wait4 after the
62// kill therefore hangs the sweeper forever on the one plane it was trying to escape. Matches the proven
63// nx_tools_canary_gate idiom: WNOHANG poll, bounded attempts, SIGKILL re-sent, then report honestly.
64// (STAR)A KILL YOU CANNOT VERIFY IS A WISH -- NEVER BLOCK ON REAPING SOMETHING YOU JUST FAILED TO KILL.
65const SW_REAP_TRIES: i64 = 20
66// LEARNED EXCLUSION -- THE MEASURED FORM OF segguard.conf's exclude-prefixes (2026-08-07).
67// MEASURED: at the real threshold (8) exactly ONE plane of 940 was over -- knowledge/store/mvaultpath-,
68// with only 12 LIVE SEGMENTS -- and it burned the FULL 300s timeout. dp-web-pub- did the same with 913.
69// So the cost is NOT the segment count: 12 huge segments cost more than 900 small ones.
70// (STAR)A COUNT IS NOT A SIZE -- A CEILING ON THE WRONG DIMENSION PROTECTS NOTHING.
71// My SW_MAXFOLD ceiling is count-based and structurally cannot see mvaultpath-. Worse, WITHOUT memory
72// the sweep re-attempts the same unfoldable plane EVERY RUN and pays 300s EVERY TIME, forever.
73// (STAR)A TIMEOUT WITHOUT MEMORY IS A TAX YOU PAY ON EVERY RUN FOR THE SAME LESSON.
74// The .sh answers this with a HAND-MAINTAINED prefix list, which goes stale as planes are added. This
75// LEARNS instead: any plane that hits the timeout is appended to a poison file and skipped thereafter.
76// Deleting the file is the deliberate re-test, so nothing is permanently invisible.
77const SW_POISON: *u8 = "knowledge/status/segsweep_poison.txt"
78const SW_POISONCAP: i64 = 65536
79
80func sw_o(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
81func sw_cat(d: *u8, o: i64, s: *u8) -> i64 { var x: i64=o; var i: i64=0; while s[i]!=(0 as u8){d[x]=s[i];x=x+1;i=i+1} return x }
82func sw_num(d: *u8, o: i64, v: i64) -> i64 { var x: i64=o; var mm: i64=v; if mm<0{d[x]=45 as u8;x=x+1;mm=0-mm} if mm==0{d[x]=48 as u8;return x+1} let t:*u8=sys_mmap(24); var k:i64=0; while mm>0{t[k]=(48+(mm%10)) as u8;mm=mm/10;k=k+1} var j:i64=0; while j<k{d[x]=t[k-1-j];x=x+1;j=j+1} return x }
83func sw_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
84// openat(AT_FDCWD, path, O_RDONLY|O_DIRECTORY) -- the PROVEN idiom copied from nx_pub_reader_handoff.nx:79.
85// 257 is the raw x86_64 openat number and passes through the rv64->x86 swap table untouched, the same
86// precedent nx_syscalls.nx records for unlinkat 263 / fsync 74 / fstatat 262. There is no sys_openat_dir.
87func sw_opendir(p: *u8) -> i64 { return __syscall(257, 0-100, p as i64, 0x10000, 0, 0, 0) }
88func sw_slot(base: *u8, i: i64) -> *u8 { return ((base as i64) + i*SW_NAMEW) as *u8 }
89// PER-PLANE IN-FLIGHT BEAT (2026-08-07). v1 of this organ wrote its log line ONLY at the END of the
90// sweep, so when the compaction branch faulted the whole run left ZERO trace: no stdout, no log line,
91// nothing to point at. That is the SAME blind spot I had fixed in the clock hours earlier -- a window
92// that cannot finish cannot write its window-end report -- rebuilt from scratch in a brand new organ.
93// (STAR)AN ORGAN THAT REPORTS ONLY AT COMPLETION IS INDISTINGUISHABLE FROM ONE THAT NEVER RAN.
94// Written to the DOCROOT so it stays readable over plain HTTP even when the tools daemon is 503 under
95// load -- the same property that made the clock's in-flight beat usable during the worst of the outage.
96// is `pfx` listed in the poison file? substring match on a newline-delimited list.
97func sw_poisoned(pois: *u8, pn: i64, pfx: *u8) -> i64 {
98 if pn <= 0 { return 0 }
99 let fl: i64 = sw_len(pfx)
100 if fl <= 0 { return 0 }
101 var i: i64 = 0
102 while i + fl <= pn {
103 var k: i64 = 0
104 var same: i64 = 1
105 while k < fl { if pois[i+k] != pfx[k] { same = 0; k = fl } else { k = k + 1 } }
106 if same == 1 { if i + fl >= pn { return 1 } else { if pois[i+fl] == (10 as u8) { return 1 } } }
107 i = i + 1
108 }
109 return 0
110}
111
112// append a plane to the poison list -- called ONLY after a real measured timeout.
113func sw_poison_add(pfx: *u8) -> i64 {
114 let b: *u8 = sys_mmap(1024); var o: i64 = 0
115 o = sw_cat(b, o, pfx); b[o] = 10 as u8; o = o + 1
116 let fd: i64 = sys_openat_append(SW_POISON, SW_MODE)
117 if fd >= 0 { sys_write(fd, b, o); sys_close(fd) }
118 return 0
119}
120
121func sw_beat(tag: *u8, pfx: *u8, idx: i64, live: i64) -> i64 {
122 let b: *u8 = sys_mmap(1024); var o: i64 = 0
123 o = sw_cat(b, o, "SEGSWEEP-INFLIGHT " as *u8); o = sw_cat(b, o, tag)
124 o = sw_cat(b, o, " idx=" as *u8); o = sw_num(b, o, idx)
125 o = sw_cat(b, o, " live=" as *u8); o = sw_num(b, o, live)
126 o = sw_cat(b, o, " plane=" as *u8); o = sw_cat(b, o, pfx)
127 o = sw_cat(b, o, " t=" as *u8); o = sw_num(b, o, sys_now_realtime_sec())
128 b[o] = 10 as u8; o = o + 1; b[o] = 0 as u8
129 let fd: i64 = sys_openat_wr("sites/nishifamily/segsweep_inflight.txt" as *u8, SW_MODE)
130 if fd >= 0 { sys_write(fd, b, o); sys_close(fd) }
131 return 0
132}
133func sw_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ if s[i]<(48 as u8){return v} if s[i]>(57 as u8){return v} v=v*10+((s[i]-(48 as u8)) as i64); i=i+1 } return v }
134
135// does name end with "-manifest.txt"?
136func sw_is_manifest(nm: *u8) -> i64 {
137 let nl: i64 = sw_len(nm)
138 let sl: i64 = sw_len(SW_SUFFIX)
139 if nl <= sl { return 0 }
140 var i: i64 = 0
141 while i < sl { if nm[nl-sl+i] != SW_SUFFIX[i] { return 0 } i = i + 1 }
142 return 1
143}
144
145// read an integer key from segguard.conf: "<key> = <int>"; returns dflt when absent.
146func sw_conf_int(key: *u8, dflt: i64) -> i64 {
147 let lp: *i64 = sys_mmap(8) as *i64
148 let d: *u8 = sys_read_file(SW_CONF, lp)
149 if (d as i64) == 0 { return dflt }
150 let n: i64 = lp[0]
151 let kl: i64 = sw_len(key)
152 var i: i64 = 0
153 while i < n {
154 var m: i64 = 1
155 var j: i64 = 0
156 while j < kl { if i+j >= n { m = 0; j = kl } else { if d[i+j] != key[j] { m = 0; j = kl } else { j = j + 1 } } }
157 if m == 1 {
158 var p: i64 = i + kl
159 while p < n { if d[p]==(32 as u8) { p=p+1 } else { if d[p]==(9 as u8) { p=p+1 } else { if d[p]==(61 as u8) { p=p+1 } else { p = n + 1 } } } }
160 if p <= n {
161 var v: i64 = 0; var got: i64 = 0
162 var q: i64 = i + kl
163 while q < n { if d[q]==(61 as u8) { q = q + 1; q = n + 1 } else { q = q + 1 } }
164 // simple scan: find '=' after the key, then the first integer run
165 var r: i64 = i + kl
166 var seen: i64 = 0
167 while r < n {
168 if d[r] == (10 as u8) { r = n }
169 else {
170 if d[r] == (61 as u8) { seen = 1; r = r + 1 }
171 else {
172 if seen == 1 { if d[r] >= (48 as u8) { if d[r] <= (57 as u8) { v = v*10 + ((d[r]-(48 as u8)) as i64); got = 1 } else { if got == 1 { r = n } } } else { if got == 1 { r = n } } }
173 r = r + 1
174 }
175 }
176 }
177 if got == 1 { return v }
178 }
179 }
180 // advance to next line
181 while i < n { if d[i] == (10 as u8) { i = i + 1; i = i } else { i = i + 1 } if i > 0 { if d[i-1] == (10 as u8) { i = i } }
182 if i >= n { i = n } else { if d[i-1] == (10 as u8) { i = i } }
183 if i < n { if d[i-1] == (10 as u8) { break } } }
184 }
185 return dflt
186}
187
188func main(argc: i64, argv: *i64) -> i64 {
189 let t0: i64 = sys_now_realtime_sec()
190 var thresh: i64 = sw_conf_int("max-live-segments" as *u8, SW_DEF_THRESH)
191 var budget: i64 = SW_DEF_BUDGET
192 if argc >= 2 { let a: i64 = sw_atoi(argv[1] as *u8); if a > 0 { thresh = a } }
193 if argc >= 3 { let b: i64 = sw_atoi(argv[2] as *u8); if b > 0 { budget = b } }
194 if thresh < 1 { thresh = SW_DEF_THRESH }
195
196 // ---- enumerate planes: ONE getdents64 walk, ZERO forks ----
197 let names: *u8 = sys_mmap(SW_MAXPLANES * SW_NAMEW)
198 var np: i64 = 0
199 var truncated: i64 = 0
200 let dfd: i64 = sw_opendir(SW_STORE)
201 if dfd < 0 { sw_o("SEGSWEEP FAIL cannot open knowledge/store\\n" as *u8); sys_exit(1); return 1 }
202 let dbuf: *u8 = sys_mmap(SW_DIRBUF)
203 var more: i64 = 1
204 while more == 1 {
205 let nb: i64 = sys_getdents64(dfd, dbuf, SW_DIRBUF)
206 if nb <= 0 { more = 0 } else {
207 var p: i64 = 0
208 while p < nb {
209 let reclen: i64 = (dbuf[p+16] as i64) + ((dbuf[p+17] as i64) * 256)
210 if reclen <= 0 { p = nb } else {
211 let nmp: *u8 = ((dbuf as i64) + p + 19) as *u8
212 if sw_is_manifest(nmp) == 1 {
213 if np < SW_MAXPLANES {
214 let dst: *u8 = sw_slot(names, np)
215 var c: i64 = 0
216 while c < SW_NAMEW-1 { if nmp[c]==(0 as u8) { dst[c]=0 as u8; c=SW_NAMEW } else { dst[c]=nmp[c]; c=c+1 } }
217 if c == SW_NAMEW-1 { dst[c] = 0 as u8 }
218 np = np + 1
219 } else { truncated = 1 }
220 }
221 p = p + reclen
222 }
223 }
224 }
225 }
226 sys_close(dfd)
227
228 // ---- resume cursor: a budget WITHOUT a cursor never reaches the tail ----
229 let clp: *i64 = sys_mmap(8) as *i64
230 var cursor: i64 = 0
231 let cd: *u8 = sys_read_file(SW_CURSOR, clp)
232 if (cd as i64) != 0 { cursor = sw_atoi(cd) }
233 if cursor >= np { cursor = 0 }
234
235 let plp: *i64 = sys_mmap(8) as *i64
236 var pn: i64 = 0
237 var pois: *u8 = sys_read_file(SW_POISON, plp)
238 if (pois as i64) != 0 { pn = plp[0] } else { pois = sys_mmap(16); pn = 0 }
239 var poison_skip: i64 = 0
240 var scanned: i64 = 0
241 var acted: i64 = 0
242 var skipped_lock: i64 = 0
243 var killed: i64 = 0
244 var too_big: i64 = 0
245 var wedged: i64 = 0
246 var failed: i64 = 0
247 var over: i64 = 0
248 let sp: *i64 = sys_mmap(16) as *i64
249 let lkp: *u8 = sys_mmap(512)
250 var idx: i64 = cursor
251 var budget_hit: i64 = 0
252 var steps: i64 = 0
253 while steps < np {
254 if sys_now_realtime_sec() - t0 >= budget { budget_hit = 1; steps = np } else {
255 let nm: *u8 = sw_slot(names, idx)
256 // prefix = "knowledge/store/" + name minus "manifest.txt" (the plane prefix ends with '-')
257 var lo: i64 = 0
258 lo = sw_cat(lkp, lo, "knowledge/store/" as *u8)
259 let nl: i64 = sw_len(nm)
260 var k: i64 = 0
261 while k < nl - 12 { lkp[lo] = nm[k]; lo = lo + 1; k = k + 1 } // strip "manifest.txt" (12 chars)
262 lkp[lo] = 0 as u8
263 let plen: i64 = lo
264 let live: i64 = ss_manifest_dyn(lkp, sp)
265 scanned = scanned + 1
266 if live > thresh { if sw_poisoned(pois, pn, lkp) == 1 { poison_skip = poison_skip + 1 } else { if live > SW_MAXFOLD { too_big = too_big + 1; sw_beat("skip-too-big" as *u8, lkp, idx, live) } else {
267 over = over + 1
268 // COMPACT BY FORKING THE PROVEN CLI, BOUNDED BY A DEADLINE -- deliberately NOT an
269 // in-process ss_compact_cap, for two reasons discovered by reading segguard.conf:
270 // (1) TIMEOUT. The conf carries compact-timeout-seconds=300 precisely because a single
271 // pathological plane must be KILLABLE, and the CLI is fail-closed BEFORE its atomic
272 // manifest swap so a kill leaves the manifest untouched. An IN-PROCESS call cannot be
273 // timed out -- this organ would have to kill itself. The scan is where the win is
274 // (1096 planes, 0 forks, <1s); compaction forks only for planes actually over
275 // threshold, which is a handful.
276 // (2) SELF-DEADLOCK. The CLI takes its OWN blocking flock(LOCK_EX) on <prefix>plock. An
277 // earlier draft of this organ held a NON-BLOCKING lock on that same file and then
278 // forked the CLI -- the child would have blocked on the parent's lock FOREVER, with
279 // the deadline as the only thing that ever ended it. Locks are per open-file-
280 // description, so parent and child contend even inside one program.
281 // (STAR)IF YOU HOLD A LOCK AND THEN FORK SOMETHING THAT TAKES THE SAME LOCK, YOU HAVE
282 // WRITTEN A DEADLOCK -- THE CHILD CANNOT WAIT FOR A PARENT THAT IS WAITING FOR THE CHILD.
283 sw_beat("pre-segid" as *u8, lkp, idx, live)
284 let sid: i64 = ss_next_segid(lkp)
285 let sidb: *u8 = sys_mmap(32)
286 let sidn: i64 = sw_num(sidb, 0, sid)
287 sidb[sidn] = 0 as u8
288 let pfxb: *u8 = sys_mmap(512)
289 var pc: i64 = 0
290 while pc < plen { pfxb[pc] = lkp[pc]; pc = pc + 1 }
291 pfxb[plen] = 0 as u8
292 sw_beat("pre-fork" as *u8, pfxb, idx, live)
293 let pid: i64 = sys_fork()
294 if pid == 0 {
295 let av: *i64 = sys_mmap(64) as *i64
296 av[0] = SW_CLI as i64; av[1] = pfxb as i64; av[2] = sidb as i64; av[3] = 0
297 let ev: *i64 = sys_mmap(32) as *i64
298 ev[0] = "PATH=/usr/bin:/bin" as *u8 as i64; ev[1] = 0
299 sys_execve(SW_CLI, av, ev)
300 sys_exit(127)
301 }
302 if pid < 0 { failed = failed + 1 } else {
303 let stb: *i64 = sys_mmap(16) as *i64
304 let cs: i64 = sys_now_realtime_sec()
305 var done: i64 = 0
306 while done == 0 {
307 let w: i64 = sys_wait4(pid, stb, 1)
308 if w == pid { done = 1 }
309 else { if w < 0 { done = 1; failed = failed + 1 }
310 else { if sys_now_realtime_sec() - cs >= SW_CLI_TIMEOUT { nx_kill(pid, 9); var tries: i64 = 0; var got: i64 = 0; while tries < SW_REAP_TRIES { let w2: i64 = sys_wait4(pid, stb, 1); if w2 == pid { got = 1; tries = SW_REAP_TRIES } else { nx_kill(pid, 9); sys_sleep_ms(250); tries = tries + 1 } } if got == 0 { wedged = wedged + 1 } sw_poison_add(pfxb); killed = killed + 1; done = 1 } else { sys_sleep_ms(200) } } }
311 }
312 if done == 1 { acted = acted + 1 }
313 sw_beat("reaped" as *u8, pfxb, idx, live)
314 }
315 } } }
316 idx = idx + 1
317 if idx >= np { idx = 0 }
318 steps = steps + 1
319 }
320 }
321
322 // persist the cursor so the next run continues past where this one stopped
323 let cb: *u8 = sys_mmap(32)
324 var co: i64 = sw_num(cb, 0, idx)
325 cb[co] = 10 as u8; co = co + 1
326 let cfd: i64 = sys_openat_wr(SW_CURSOR, SW_MODE)
327 if cfd >= 0 { sys_write(cfd, cb, co); sys_close(cfd) }
328
329 let now: i64 = sys_now_realtime_sec()
330 let msg: *u8 = sys_mmap(1024)
331 var mo: i64 = 0
332 mo = sw_cat(msg, mo, "SEGSWEEP planes=" as *u8); mo = sw_num(msg, mo, np)
333 mo = sw_cat(msg, mo, " scanned=" as *u8); mo = sw_num(msg, mo, scanned)
334 mo = sw_cat(msg, mo, " over_threshold=" as *u8); mo = sw_num(msg, mo, over)
335 mo = sw_cat(msg, mo, " compacted=" as *u8); mo = sw_num(msg, mo, acted)
336 mo = sw_cat(msg, mo, " killed_on_timeout=" as *u8); mo = sw_num(msg, mo, killed)
337 mo = sw_cat(msg, mo, " skipped_too_big=" as *u8); mo = sw_num(msg, mo, too_big)
338 mo = sw_cat(msg, mo, " skipped_poison=" as *u8); mo = sw_num(msg, mo, poison_skip)
339 mo = sw_cat(msg, mo, " WEDGED_UNKILLABLE=" as *u8); mo = sw_num(msg, mo, wedged)
340 mo = sw_cat(msg, mo, " failed=" as *u8); mo = sw_num(msg, mo, failed)
341 mo = sw_cat(msg, mo, " threshold=" as *u8); mo = sw_num(msg, mo, thresh)
342 mo = sw_cat(msg, mo, " budget_s=" as *u8); mo = sw_num(msg, mo, budget)
343 mo = sw_cat(msg, mo, " elapsed_s=" as *u8); mo = sw_num(msg, mo, now - t0)
344 mo = sw_cat(msg, mo, " budget_hit=" as *u8); mo = sw_num(msg, mo, budget_hit)
345 mo = sw_cat(msg, mo, " truncated=" as *u8); mo = sw_num(msg, mo, truncated)
346 mo = sw_cat(msg, mo, " next_cursor=" as *u8); mo = sw_num(msg, mo, idx)
347 mo = sw_cat(msg, mo, " forks=0 verdict=GREEN ts=" as *u8); mo = sw_num(msg, mo, now)
348 msg[mo] = 10 as u8; mo = mo + 1
349 msg[mo] = 0 as u8
350 sys_write(1, msg, mo)
351 let lfd2: i64 = sys_openat_append(SW_LOG, SW_MODE)
352 if lfd2 >= 0 { sys_write(lfd2, msg, mo); sys_close(lfd2) }
353 sys_exit(0)
354 return 0
355}