code wiki / _hdl_build / nx_dora.nx
nx_dora.nx source
↩ module page · 549 lines · 31088 B
1// nx_dora.nx -- DORA-analogue delivery metrics derived from SOVEREIGN event planes (F740).
2// Operator ask: beyond-SOTA, evidence-driven, no manual instrumentation. Incumbents (Jellyfish/LinearB/
3// Swarmia/DX) POLL git/Jira; we DERIVE the DORA keys from our own event stream -- the sovereign exceed
4// /compare/pmdash flagged as GAP F740:
5// - DEPLOY FREQUENCY = DONE frames in knowledge/status/ws_sync.jrnl (each shipped ws = a delivery event)
6// - LEAD TIME (cycle) = DONE_epoch - most-recent-prior KICKOFF_epoch of the same ws, median across pairs
7// - CHANGE-FAIL proxy = incident-class OPEN debts / deploys (debt- plane; declared heuristic, labeled)
8// - MTTR proxy = median debt filed->eaten span is NOT in the row (needs debthist join) -> declared PENDING
9// Honest by construction: 2 keys MEASURED, 2 PROXY/PENDING, each labeled; DORA elite/high/medium/low bands.
10// argv[1] = mode: json(default -> stdout) | html [argv[2]=out path, default sites/nishifamily/dora.html]
11// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
12import "nx_store_seed_lib.nx"
13import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
14import "nx_syscalls.nx"
15
16const DJPATH: *u8 = "knowledge/status/ws_sync.jrnl"
17const DEBTPFX: *u8 = "knowledge/store/debt-"
18const DNL: i64 = 10
19const DTAB: i64 = 9
20const DHASH: i64 = 35
21const DZERO: i64 = 48
22const DNINE: i64 = 57
23const DCAP: i64 = 33554432 // 2026-08-06 MEASURED by nx_planefit: knowledge/store/debt- loads to 4,396,892B. At the old 1 MiB this organ silently lost 3,348,316B = 76% of the board, and because AN APPEND-ONLY PLANE PAST A PREFIX CAP LOSES ITS NEWEST ROWS FIRST it was reporting on the OLDEST quarter -- degrading exactly as new work arrived. 32 MiB matches nx_debt DB_CAP sizing. Re-verify: nx_planefit knowledge/store/debt- 33554432
24const DMAXEV: i64 = 6000
25const DSECDAY: i64 = 86400
26const DSECHR: i64 = 3600
27const DSECWK: i64 = 604800
28const DHTMLH: i64 = 104 // 'h'
29const DOUTCAP: i64 = 262144
30const DI64: i64 = 8
31
32func d_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
33func d_p(s: *u8) -> i64 { sys_write(1, s, d_len(s)); return 0 }
34func d_read(path: *u8, buf: *u8, cap: i64) -> i64 {
35 let fd: i64 = sys_openat_rd(path)
36 if fd < 0 { return 0 }
37 var n: i64 = 0
38 var go: i64 = 1
39 while go == 1 {
40 let base: i64 = buf as i64
41 let r: i64 = sys_read(fd, (base + n) as *u8, cap - n)
42 if r <= 0 { go = 0 } else { n = n + r }
43 if n >= cap { go = 0 }
44 }
45 sys_close(fd)
46 return n
47}
48// integer at [a,b)
49func d_int(buf: *u8, a: i64, b: i64) -> i64 {
50 var v: i64 = 0
51 var i: i64 = a
52 while i < b { let c: i64 = buf[i]; if c >= DZERO { if c <= DNINE { v = v*10 + (c-DZERO) } } i = i + 1 }
53 return v
54}
55// bytes [a,b) equal [c,d) ?
56func d_span_eq(buf: *u8, a: i64, b: i64, c: i64, d: i64) -> i64 {
57 if b - a != d - c { return 0 }
58 var i: i64 = 0
59 while a + i < b { if buf[a+i] != buf[c+i] { return 0 } i = i + 1 }
60 return 1
61}
62// does [a,b) start with lit?
63func d_starts(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
64 let l: i64 = d_len(lit)
65 if b - a < l { return 0 }
66 var i: i64 = 0
67 while i < l { if buf[a+i] != lit[i] { return 0 } i = i + 1 }
68 return 1
69}
70// substring lit inside [a,b) (case-sensitive)
71func d_has(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
72 let l: i64 = d_len(lit)
73 if l == 0 { return 0 }
74 var i: i64 = a
75 while i + l <= b { if d_starts(buf, i, b, lit) == 1 { return 1 } i = i + 1 }
76 return 0
77}
78// number -> decimal into fd via buffer
79// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
80// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
81// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
82// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
83func d_num(v: i64) -> i64 { nxi_out(v); return 0 }
84
85// DORA band codes: 4=ELITE 3=HIGH 2=MEDIUM 1=LOW
86func d_band_deploy(per_week: i64) -> i64 { // per_week*100 (fixed-point x100 to keep integer)
87 if per_week >= 700 { return 4 } // >=7/wk (~1+/day) = elite
88 if per_week >= 100 { return 3 } // >=1/wk = high
89 if per_week >= 23 { return 2 } // >=~1/mo = medium
90 return 1
91}
92func d_band_lead(hrs: i64) -> i64 {
93 if hrs < 24 { return 4 }
94 if hrs < 168 { return 3 }
95 if hrs < 720 { return 2 }
96 return 1
97}
98func d_band_cfr(pct: i64) -> i64 {
99 if pct <= 15 { return 4 }
100 if pct <= 30 { return 2 }
101 return 1
102}
103func d_band_label(b: i64) -> *u8 {
104 if b == 4 { return "ELITE" as *u8 }
105 if b == 3 { return "HIGH" as *u8 }
106 if b == 2 { return "MEDIUM" as *u8 }
107 return "LOW" as *u8
108}
109
110// ============ DM6 (devmgmt rung): d_ship_join -- DORA FED BY SHIP RECEIPTS ============
111// The four keys already ride ws_sync.jrnl (a DONE = a shipped workstream). That is the WORKSTREAM
112// event stream; knowledge/status/organ_ship.jrnl is the ARTIFACT one -- nx_organ_ship appends a row
113// per stage of every ship it runs, so BUILD->SHIPPED is a real, per-organ build-to-deploy interval
114// that nothing was reading. Same organ, same bands, second source: rule 15 says extend the ruler.
115//
116// Row grammar (measured from the live journal, not assumed): epoch TAB target TAB STAGE TAB OUTCOME
117// TAB detail, with STAGE in {BUILD, PROVE, ADOPT, SHIPPED}.
118// DEPLOY FREQUENCY = SHIPPED rows in the window (each is one artifact promoted and verified).
119// LEAD TIME = SHIPPED epoch minus the NEAREST PRECEDING BUILD epoch FOR THE SAME TARGET.
120//
121// THREE THINGS IT REFUSES TO CONFLATE:
122// * A SHIPPED row with no preceding BUILD for its target is UNMATCHED -- its own bucket, excluded
123// from the lead-time statistics and COUNTED beside them, because averaging over a set you cannot
124// reconstruct is how a lead-time number stops being auditable.
125// * Ship-loop REFUSALS ARE NOT THE DORA CHANGE-FAILURE RATE. A refusal is a change that never
126// reached production -- the guard working. Reporting it under a name that means "we broke prod"
127// would invert the sign of the only metric an operator reads as bad news.
128// * The window is anchored on the JOURNAL'S NEWEST ROW, not on wall clock, so the same journal
129// always yields the same answer and a hand count can be reproduced tomorrow. The anchor is
130// printed; days<=0 means the whole journal.
131// EVERY joined row is printed. The accept rule for this rung is a HAND COUNT over one week, and a
132// hand count is impossible against a summary that only publishes an average.
133const DSJ_ST_OTHER: i64 = 0
134const DSJ_ST_BUILD: i64 = 1
135const DSJ_ST_SHIPPED: i64 = 2
136const DSJ_ST_PROVE: i64 = 3
137const DSJ_ST_ADOPT: i64 = 4
138const DSJ_PCT: i64 = 100 // the x100 fixed point d_band_deploy already speaks
139
140func d_sj_col(buf: *u8, ls: i64, le: i64, k: i64, sp: *i64) -> i64 {
141 var c: i64 = 0
142 var s: i64 = ls
143 while c < k {
144 var e: i64 = s
145 var g: i64 = 1
146 while g == 1 { if e >= le { g = 0 } else { if buf[e] == (DTAB as u8) { g = 0 } else { e = e + 1 } } }
147 if e >= le { return 0 }
148 s = e + 1
149 c = c + 1
150 }
151 var e2: i64 = s
152 var g2: i64 = 1
153 while g2 == 1 { if e2 >= le { g2 = 0 } else { if buf[e2] == (DTAB as u8) { g2 = 0 } else { e2 = e2 + 1 } } }
154 sp[0] = s
155 sp[1] = e2
156 return 1
157}
158func d_sj_eq(buf: *u8, a: i64, b: i64, lit: *u8) -> i64 {
159 let l: i64 = d_len(lit)
160 if b - a != l { return 0 }
161 var i: i64 = 0
162 var ok: i64 = 1
163 while i < l { if buf[a+i] != lit[i] { ok = 0; i = l } else { i = i + 1 } }
164 return ok
165}
166func d_sj_emit(buf: *u8, a: i64, b: i64) -> i64 { sys_write(1, ((buf as i64) + a) as *u8, b - a); return 0 }
167// returns 0 ok, 3 refused (unreadable / empty / row table filled)
168func d_ship_join(path: *u8, days: i64) -> i64 {
169 let buf: *u8 = sys_mmap(DCAP)
170 let n: i64 = d_read(path, buf, DCAP - 16)
171 if n <= 0 { d_p("REFUSED ship journal unreadable or empty -- an unread journal is UNPROVEN, never zero deploys\n" as *u8); return 3 }
172 let ep: *i64 = sys_mmap(DMAXEV*DI64) as *i64
173 let ta: *i64 = sys_mmap(DMAXEV*DI64) as *i64
174 let tb: *i64 = sys_mmap(DMAXEV*DI64) as *i64
175 let st: *i64 = sys_mmap(DMAXEV*DI64) as *i64
176 let oa: *i64 = sys_mmap(DMAXEV*DI64) as *i64
177 let ob: *i64 = sys_mmap(DMAXEV*DI64) as *i64
178 let sp: *i64 = sys_mmap(4*DI64) as *i64
179 var nev: i64 = 0
180 var capped: i64 = 0
181 var skipped: i64 = 0
182 var i: i64 = 0
183 while i < n {
184 var le: i64 = i
185 var g: i64 = 1
186 while g == 1 { if le >= n { g = 0 } else { if buf[le] == (DNL as u8) { g = 0 } else { le = le + 1 } } }
187 if le > i {
188 var cmt: i64 = 0
189 if buf[i] == (DHASH as u8) { cmt = 1 }
190 if cmt == 0 {
191 if nev >= DMAXEV { capped = 1 } else {
192 var ok: i64 = 0
193 if d_sj_col(buf, i, le, 0, sp) == 1 {
194 let e0: i64 = d_int(buf, sp[0], sp[1])
195 if e0 > 0 {
196 if d_sj_col(buf, i, le, 1, sp) == 1 {
197 let t0: i64 = sp[0]
198 let t1: i64 = sp[1]
199 if d_sj_col(buf, i, le, 2, sp) == 1 {
200 var sc: i64 = DSJ_ST_OTHER
201 if d_sj_eq(buf, sp[0], sp[1], "BUILD" as *u8) == 1 { sc = DSJ_ST_BUILD }
202 if d_sj_eq(buf, sp[0], sp[1], "SHIPPED" as *u8) == 1 { sc = DSJ_ST_SHIPPED }
203 if d_sj_eq(buf, sp[0], sp[1], "PROVE" as *u8) == 1 { sc = DSJ_ST_PROVE }
204 if d_sj_eq(buf, sp[0], sp[1], "ADOPT" as *u8) == 1 { sc = DSJ_ST_ADOPT }
205 var o0: i64 = 0
206 var o1: i64 = 0
207 if d_sj_col(buf, i, le, 3, sp) == 1 { o0 = sp[0]; o1 = sp[1] }
208 ep[nev] = e0
209 ta[nev] = t0
210 tb[nev] = t1
211 st[nev] = sc
212 oa[nev] = o0
213 ob[nev] = o1
214 nev = nev + 1
215 ok = 1
216 }
217 }
218 }
219 }
220 if ok == 0 { skipped = skipped + 1 }
221 }
222 }
223 }
224 i = le + 1
225 }
226 if capped == 1 { d_p("REFUSED row table filled: this would be a FLOOR, not a window\n" as *u8); return 3 }
227 if nev == 0 { d_p("REFUSED no parseable ship rows -- a zero-subject run cannot report a deploy rate\n" as *u8); return 3 }
228 var latest: i64 = 0
229 var k: i64 = 0
230 while k < nev { if ep[k] > latest { latest = ep[k] } k = k + 1 }
231 var wstart: i64 = 0
232 if days > 0 { wstart = latest - days * DSECDAY }
233 if wstart < 0 { wstart = 0 }
234 var earliest: i64 = latest
235 k = 0
236 while k < nev { if ep[k] >= wstart { if ep[k] < earliest { earliest = ep[k] } } k = k + 1 }
237 var window_s: i64 = latest - earliest
238 d_p("# NX-DORA-SHIPJOIN v=1 tool=nx_dora averb=shipjoin source=" as *u8)
239 d_p(path)
240 d_p(" journal_bytes=" as *u8); d_num(n)
241 d_p(" rows_parsed=" as *u8); d_num(nev)
242 d_p(" rows_unparsed=" as *u8); d_num(skipped)
243 d_p("\n# WINDOW anchor=journal-newest-row window_end=" as *u8); d_num(latest)
244 d_p(" window_start=" as *u8); d_num(wstart)
245 d_p(" first_row_in_window=" as *u8); d_num(earliest)
246 d_p(" span_s=" as *u8); d_num(window_s)
247 d_p(" days_requested=" as *u8); d_num(days)
248 d_p("\n" as *u8)
249 var ships: i64 = 0
250 var matched: i64 = 0
251 var unmatched: i64 = 0
252 var leadsum: i64 = 0
253 var leadmin: i64 = 0 - 1
254 var leadmax: i64 = 0 - 1
255 var refusals: i64 = 0
256 var builds: i64 = 0
257 k = 0
258 while k < nev {
259 if ep[k] >= wstart {
260 if st[k] == DSJ_ST_BUILD { builds = builds + 1 }
261 if st[k] == DSJ_ST_PROVE { if d_sj_eq(buf, oa[k], ob[k], "RED" as *u8) == 1 { refusals = refusals + 1 } }
262 if st[k] == DSJ_ST_ADOPT { if d_sj_eq(buf, oa[k], ob[k], "REFUSED-OR-MISSING" as *u8) == 1 { refusals = refusals + 1 } }
263 if st[k] == DSJ_ST_SHIPPED {
264 ships = ships + 1
265 var bi: i64 = 0 - 1
266 var j: i64 = k - 1
267 var gg: i64 = 1
268 while gg == 1 {
269 if j < 0 { gg = 0 } else {
270 if st[j] == DSJ_ST_BUILD {
271 if tb[j] - ta[j] == tb[k] - ta[k] {
272 var m: i64 = 0
273 var eq: i64 = 1
274 let ln: i64 = tb[k] - ta[k]
275 while m < ln { if buf[ta[j]+m] != buf[ta[k]+m] { eq = 0; m = ln } else { m = m + 1 } }
276 if eq == 1 { bi = j; gg = 0 }
277 }
278 }
279 if gg == 1 { j = j - 1 }
280 }
281 }
282 d_p("SHIP " as *u8)
283 d_sj_emit(buf, ta[k], tb[k])
284 d_p(" shipped=" as *u8); d_num(ep[k])
285 if bi < 0 {
286 unmatched = unmatched + 1
287 d_p(" build=NONE lead_s=UNMATCHED (excluded from the lead-time statistics, counted beside them)\n" as *u8)
288 } else {
289 let lead: i64 = ep[k] - ep[bi]
290 matched = matched + 1
291 leadsum = leadsum + lead
292 if leadmin < 0 { leadmin = lead }
293 if lead < leadmin { leadmin = lead }
294 if lead > leadmax { leadmax = lead }
295 d_p(" build=" as *u8); d_num(ep[bi])
296 d_p(" lead_s=" as *u8); d_num(lead)
297 d_p("\n" as *u8)
298 }
299 }
300 }
301 k = k + 1
302 }
303 var perweek: i64 = 0
304 if window_s > 0 { perweek = ships * DSECWK * DSJ_PCT / window_s }
305 var leadmean: i64 = 0 - 1
306 if matched > 0 { leadmean = leadsum / matched }
307 var leadhrs: i64 = 0 - 1
308 if leadmean >= 0 { leadhrs = leadmean / DSECHR }
309 d_p("# DEPLOY ships=" as *u8); d_num(ships)
310 d_p(" builds=" as *u8); d_num(builds)
311 d_p(" per_week_x100=" as *u8); d_num(perweek)
312 d_p(" band=" as *u8); d_p(d_band_label(d_band_deploy(perweek)))
313 d_p("\n# LEAD matched=" as *u8); d_num(matched)
314 d_p(" unmatched=" as *u8); d_num(unmatched)
315 d_p(" sum=" as *u8); d_num(matched + unmatched)
316 d_p(" sum_ok=" as *u8)
317 if matched + unmatched == ships { d_num(1) } else { d_num(0) }
318 d_p(" mean_s=" as *u8); d_num(leadmean)
319 d_p(" min_s=" as *u8); d_num(leadmin)
320 d_p(" max_s=" as *u8); d_num(leadmax)
321 d_p(" mean_h=" as *u8); d_num(leadhrs)
322 d_p(" band=" as *u8)
323 if leadhrs < 0 { d_p("UNMEASURED" as *u8) } else { d_p(d_band_label(d_band_lead(leadhrs))) }
324 d_p("\n# SHIP-REFUSALS n=" as *u8); d_num(refusals)
325 d_p(" NOTE this is NOT the DORA change-failure rate: a refused ship never reached production, so it is the guard working, not an incident\n" as *u8)
326 d_p("SHIPJOIN ships=" as *u8); d_num(ships)
327 d_p(" matched=" as *u8); d_num(matched)
328 d_p(" per_week_x100=" as *u8); d_num(perweek)
329 d_p(" sum_ok=" as *u8)
330 if matched + unmatched == ships { d_num(1) } else { d_num(0) }
331 d_p("\n" as *u8)
332 return 0
333}
334
335func main(argc: i64, argv: *i64) -> i64 {
336 // DM6 verb, checked BEFORE the ws_sync read so the ship-receipt lane costs nothing extra
337 if argc >= 2 {
338 let v: *u8 = argv[1] as *u8
339 if d_sj_eq(v, 0, d_len(v), "shipjoin" as *u8) == 1 {
340 var jp: *u8 = "knowledge/status/organ_ship.jrnl" as *u8
341 if argc >= 3 { jp = argv[2] as *u8 }
342 var dys: i64 = 7
343 if argc >= 4 { dys = d_int(argv[3] as *u8, 0, d_len(argv[3] as *u8)) }
344 let rc: i64 = d_ship_join(jp, dys)
345 sys_exit(rc)
346 return rc
347 }
348 }
349 var html: i64 = 0
350 var outp: *u8 = "sites/nishifamily/dora.html" as *u8
351 if argc >= 2 { let a1: *u8 = argv[1] as *u8; if a1[0] == (DHTMLH as u8) { html = 1 } }
352 if argc >= 3 { outp = argv[2] as *u8 }
353
354 let buf: *u8 = sys_mmap(DCAP)
355 let n: i64 = d_read(DJPATH, buf, DCAP - 16)
356
357 // parse frames into arrays
358 let ep: *i64 = sys_mmap(DMAXEV*DI64) as *i64
359 let vb: *i64 = sys_mmap(DMAXEV*DI64) as *i64 // 1=KICKOFF 2=DONE 0=other
360 let wa: *i64 = sys_mmap(DMAXEV*DI64) as *i64
361 let wbb: *i64 = sys_mmap(DMAXEV*DI64) as *i64
362 var nev: i64 = 0
363 var i: i64 = 0
364 while i < n {
365 var le: i64 = i
366 var s: i64 = 1
367 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (DNL as u8) { s = 0 } else { le = le + 1 } } }
368 if le > i { if buf[i] != (DHASH as u8) {
369 // col0 = epoch [i, t0)
370 var t0: i64 = i
371 while t0 < le { if buf[t0] == (DTAB as u8) { t0 = le + 1 } else { t0 = t0 + 1 } }
372 // recover c0 end
373 var c0e: i64 = i
374 var f: i64 = 1
375 while f == 1 { if c0e >= le { f = 0 } else { if buf[c0e] == (DTAB as u8) { f = 0 } else { c0e = c0e + 1 } } }
376 if c0e < le {
377 let epoch: i64 = d_int(buf, i, c0e)
378 // col1 = verb
379 let v1a: i64 = c0e + 1
380 var v1b: i64 = v1a
381 var g: i64 = 1
382 while g == 1 { if v1b >= le { g = 0 } else { if buf[v1b] == (DTAB as u8) { g = 0 } else { v1b = v1b + 1 } } }
383 // col2 = ws
384 let w2a: i64 = v1b + 1
385 var w2b: i64 = w2a
386 var h: i64 = 1
387 while h == 1 { if w2b >= le { h = 0 } else { if buf[w2b] == (DTAB as u8) { h = 0 } else { w2b = w2b + 1 } } }
388 var verb: i64 = 0
389 if d_starts(buf, v1a, v1b, "KICKOFF" as *u8) == 1 { verb = 1 }
390 if d_starts(buf, v1a, v1b, "DONE" as *u8) == 1 { verb = 2 }
391 if nev < DMAXEV {
392 ep[nev] = epoch; vb[nev] = verb; wa[nev] = w2a; wbb[nev] = w2b
393 nev = nev + 1
394 }
395 }
396 } }
397 i = le + 1
398 }
399
400 // deploys = DONE count; window from min/max epoch
401 var deploys: i64 = 0
402 var mn: i64 = 0
403 var mx: i64 = 0
404 var have: i64 = 0
405 i = 0
406 while i < nev {
407 if have == 0 { mn = ep[i]; mx = ep[i]; have = 1 } else { if ep[i] < mn { mn = ep[i] } if ep[i] > mx { mx = ep[i] } }
408 if vb[i] == 2 { deploys = deploys + 1 }
409 i = i + 1
410 }
411 var window_s: i64 = mx - mn
412 if window_s < 1 { window_s = 1 }
413 // per_week x100 (fixed point)
414 let per_week: i64 = (deploys * DSECWK * 100) / window_s
415
416 // lead times: for each DONE, latest prior KICKOFF same ws
417 let leads: *i64 = sys_mmap(DMAXEV*DI64) as *i64
418 var nlead: i64 = 0
419 i = 0
420 while i < nev {
421 if vb[i] == 2 {
422 var best: i64 = 0 - 1
423 var j: i64 = 0
424 while j < i {
425 if vb[j] == 1 {
426 if d_span_eq(buf, wa[j], wbb[j], wa[i], wbb[i]) == 1 {
427 if ep[j] <= ep[i] { if best < 0 { best = ep[j] } else { if ep[j] > best { best = ep[j] } } }
428 }
429 }
430 j = j + 1
431 }
432 if best >= 0 { let cyc: i64 = ep[i] - best; if cyc >= 0 { leads[nlead] = cyc; nlead = nlead + 1 } }
433 }
434 i = i + 1
435 }
436 // median lead (insertion sort)
437 var a: i64 = 1
438 while a < nlead {
439 let key: i64 = leads[a]
440 var b: i64 = a - 1
441 var mv: i64 = 1
442 while mv == 1 { if b < 0 { mv = 0 } else { if leads[b] > key { leads[b+1] = leads[b]; b = b - 1 } else { mv = 0 } } }
443 leads[b+1] = key
444 a = a + 1
445 }
446 var lead_med_s: i64 = 0
447 if nlead > 0 { lead_med_s = leads[nlead/2] }
448 let lead_med_hr: i64 = lead_med_s / DSECHR
449
450 // change-fail proxy from debt- plane: incident-class open debts / deploys
451 // SELF-SIZING READ (2026-08-06). This was sys_mmap(DCAP) + sts_load(..., DCAP - 16) with DCAP a
452 // fixed 1 MiB, while knowledge/store/debt- measured 4,419,932B -- so this organ was silently
453 // reading 24% of the board and, because an append-only plane past a prefix cap loses its NEWEST
454 // rows first, its change-fail proxy was computed from the OLDEST quarter and degraded exactly as
455 // new incidents arrived. Raising DCAP to 32 MiB fixed today's number; sts_load_fit removes the
456 // number, growing until the read comes back STRICTLY SHORT, which is what proves completeness.
457 // ★A CAP THAT CAN BE CROSSED IN SILENCE WILL BE CROSSED AGAIN (nx_debt DB_CAP, third raise).
458 // FAIL-CLOSED: a refusal returns null / -1 and is treated as NO DATA rather than a partial board.
459 let dlen: *i64 = sys_mmap(16) as *i64
460 let dbuf: *u8 = sts_load_fit(DEBTPFX, dlen)
461 var dn: i64 = dlen[0]
462 if (dbuf as i64) == 0 { dn = 0 }
463 if dn < 0 { dn = 0 }
464 var incident: i64 = 0
465 var dtot: i64 = 0
466 var i2: i64 = 0
467 while i2 < dn {
468 var le2: i64 = i2
469 var s2: i64 = 1
470 while s2 == 1 { if le2 >= dn { s2 = 0 } else { if dbuf[le2] == (DNL as u8) { s2 = 0 } else { le2 = le2 + 1 } } }
471 if le2 > i2 { if dbuf[i2] != (DHASH as u8) {
472 dtot = dtot + 1
473 var isopen: i64 = 0
474 if d_has(dbuf, i2, le2, "open" as *u8) == 1 { isopen = 1 }
475 if isopen == 1 {
476 if d_has(dbuf, i2, le2, "regress" as *u8) == 1 { incident = incident + 1 }
477 else { if d_has(dbuf, i2, le2, "rollback" as *u8) == 1 { incident = incident + 1 }
478 else { if d_has(dbuf, i2, le2, "revert" as *u8) == 1 { incident = incident + 1 }
479 else { if d_has(dbuf, i2, le2, "outage" as *u8) == 1 { incident = incident + 1 }
480 else { if d_has(dbuf, i2, le2, "brick" as *u8) == 1 { incident = incident + 1 } } } } }
481 }
482 } }
483 i2 = le2 + 1
484 }
485 var cfr: i64 = 0
486 if deploys > 0 { cfr = (incident * 100) / deploys }
487 if cfr > 100 { cfr = 100 }
488
489 let bd: i64 = d_band_deploy(per_week)
490 let bl: i64 = d_band_lead(lead_med_hr)
491 let bc: i64 = d_band_cfr(cfr)
492
493 if html == 0 {
494 d_p("{\"tool\":\"nx_dora\",\"epoch\":" as *u8); d_num(sys_now_realtime_sec())
495 d_p(",\"source\":\"knowledge/status/ws_sync.jrnl (DONE=deploy, KICKOFF->DONE=lead) + debt- plane (change-fail proxy) -- sovereign, zero git-poll\"" as *u8)
496 d_p(",\"window_days\":" as *u8); d_num(window_s / DSECDAY)
497 d_p(",\"deploy_frequency\":{\"deploys\":" as *u8); d_num(deploys)
498 d_p(",\"per_week_x100\":" as *u8); d_num(per_week)
499 d_p(",\"band\":\"" as *u8); d_p(d_band_label(bd)); d_p("\",\"kind\":\"MEASURED\"}" as *u8)
500 d_p(",\"lead_time\":{\"matched_pairs\":" as *u8); d_num(nlead)
501 d_p(",\"median_hours\":" as *u8); d_num(lead_med_hr)
502 d_p(",\"median_seconds\":" as *u8); d_num(lead_med_s)
503 d_p(",\"band\":\"" as *u8); d_p(d_band_label(bl)); d_p("\",\"kind\":\"MEASURED\"}" as *u8)
504 d_p(",\"change_fail_rate\":{\"pct\":" as *u8); d_num(cfr)
505 d_p(",\"incident_open_debts\":" as *u8); d_num(incident)
506 d_p(",\"band\":\"" as *u8); d_p(d_band_label(bc)); d_p("\",\"kind\":\"PROXY\"}" as *u8)
507 d_p(",\"mttr\":{\"kind\":\"PENDING\",\"note\":\"filed->eaten span needs the debthist- join (F740b); not asserted\"}" as *u8)
508 d_p(",\"bands_legend\":\"ELITE/HIGH/MEDIUM/LOW per DORA 2023-24 thresholds; deploy elite>=1/day, lead elite<24h, CFR elite<=15pct\"" as *u8)
509 d_p(",\"caveat\":\"DORA-ANALOGUE from our delivery event stream (shipped work items), not git-commit-instrumented; a DONE frame = a delivered capability. Honest: 2 keys MEASURED, change-fail PROXY (incident-class open debts), MTTR PENDING.\"}" as *u8)
510 d_p("\n" as *u8)
511 sys_exit(0)
512 return 0
513 }
514
515 // ---- HTML /dora ----
516 let out: *u8 = sys_mmap(DOUTCAP)
517 var o: i64 = 0
518 o = ss_cat(out, o, "<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content='width=device-width,initial-scale=1'><title>Nishi DORA (sovereign)</title><style>body{margin:0;font:15px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;background:#0e1116;color:#e6edf3}header{padding:28px 24px;background:linear-gradient(135deg,#161b22,#0e1116);border-bottom:1px solid #30363d}h1{margin:0 0 6px;font-size:22px}.sub{color:#8b949e;font-size:14px}h2{margin:24px 24px 8px;font-size:13px;text-transform:uppercase;letter-spacing:.08em;color:#8b949e}table{border-collapse:collapse;margin:0 24px 8px;max-width:1000px}td,th{padding:8px 10px;border-bottom:1px solid #21262d;text-align:left;font-size:14px}th{color:#8b949e;font-size:12px;text-transform:uppercase}.m{color:#8b949e;font-size:12px}.tile{display:inline-block;background:#161b22;border:1px solid #30363d;border-radius:10px;padding:14px 18px;margin:10px 8px 0 0;min-width:150px}.tile .n{font-size:24px;font-weight:700}.tile .l{color:#8b949e;font-size:12px}.e{color:#3fb950}.h{color:#58a6ff}.md{color:#d29922}.lo{color:#f85149}a{color:#58a6ff;text-decoration:none}footer{padding:18px 24px;color:#6e7681;font-size:12px;border-top:1px solid #21262d;margin-top:22px}</style></head><body><header><h1>Nishi DORA — sovereign delivery metrics (F740)</h1><div class=sub>the four keys DERIVED from our own event stream (ws_sync.jrnl + debt plane) — zero git-poll, zero manual entry · measured, never asserted</div></header>" as *u8)
519 o = ss_cat(out, o, "<div style='padding:0 16px'>" as *u8)
520 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, deploys); o = ss_cat(out, o, "</div><div class=l>deploys (DONE frames) · <span class=" as *u8)
521 if bd == 4 { o = ss_cat(out, o, "e>ELITE" as *u8) } else { if bd == 3 { o = ss_cat(out, o, "h>HIGH" as *u8) } else { if bd == 2 { o = ss_cat(out, o, "md>MEDIUM" as *u8) } else { o = ss_cat(out, o, "lo>LOW" as *u8) } } }
522 o = ss_cat(out, o, "</span></div></span>" as *u8)
523 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, lead_med_hr); o = ss_cat(out, o, "h</div><div class=l>median lead time · <span class=" as *u8)
524 if bl == 4 { o = ss_cat(out, o, "e>ELITE" as *u8) } else { if bl == 3 { o = ss_cat(out, o, "h>HIGH" as *u8) } else { if bl == 2 { o = ss_cat(out, o, "md>MEDIUM" as *u8) } else { o = ss_cat(out, o, "lo>LOW" as *u8) } } }
525 o = ss_cat(out, o, "</span></div></span>" as *u8)
526 o = ss_cat(out, o, "<span class=tile><div class=n>" as *u8); o = ss_catn(out, o, cfr); o = ss_cat(out, o, "%</div><div class=l>change-fail (proxy) · <span class=" as *u8)
527 if bc == 4 { o = ss_cat(out, o, "e>ELITE" as *u8) } else { if bc == 2 { o = ss_cat(out, o, "md>MEDIUM" as *u8) } else { o = ss_cat(out, o, "lo>LOW" as *u8) } }
528 o = ss_cat(out, o, "</span></div></span></div>" as *u8)
529 o = ss_cat(out, o, "<h2>The four keys — measured from sovereign planes</h2><table><tr><th>key</th><th>value</th><th>band</th><th>kind</th><th>how it is derived</th></tr>" as *u8)
530 o = ss_cat(out, o, "<tr><td>Deployment frequency</td><td>" as *u8); o = ss_catn(out, o, deploys); o = ss_cat(out, o, " over " as *u8); o = ss_catn(out, o, window_s/DSECDAY); o = ss_cat(out, o, "d (" as *u8); o = ss_catn(out, o, per_week/100); o = ss_cat(out, o, "/wk)</td><td>" as *u8); o = ss_cat(out, o, d_band_label(bd)); o = ss_cat(out, o, "</td><td class=m>MEASURED</td><td class=m>count of DONE frames in ws_sync.jrnl (each = a delivered capability)</td></tr>" as *u8)
531 o = ss_cat(out, o, "<tr><td>Lead time for changes</td><td>median " as *u8); o = ss_catn(out, o, lead_med_hr); o = ss_cat(out, o, "h (" as *u8); o = ss_catn(out, o, nlead); o = ss_cat(out, o, " matched pairs)</td><td>" as *u8); o = ss_cat(out, o, d_band_label(bl)); o = ss_cat(out, o, "</td><td class=m>MEASURED</td><td class=m>DONE_epoch - most-recent prior KICKOFF of the same workstream</td></tr>" as *u8)
532 o = ss_cat(out, o, "<tr><td>Change failure rate</td><td>" as *u8); o = ss_catn(out, o, cfr); o = ss_cat(out, o, "% (" as *u8); o = ss_catn(out, o, incident); o = ss_cat(out, o, " incident-class open debts)</td><td>" as *u8); o = ss_cat(out, o, d_band_label(bc)); o = ss_cat(out, o, "</td><td class=md>PROXY</td><td class=m>deploy-failure open debts (regression/rollback/revert/outage/brick) / deploys (declared coarse-upper-bound heuristic; broad coordination/stale debts EXCLUDED)</td></tr>" as *u8)
533 o = ss_cat(out, o, "<tr><td>Time to restore (MTTR)</td><td>—</td><td>—</td><td class=lo>PENDING</td><td class=m>filed→eaten span needs the debthist- join (F740b); NOT asserted rather than faked</td></tr></table>" as *u8)
534 o = ss_cat(out, o, "<h2>Why this is beyond SOTA</h2><table><tr><th>axis</th><th>Nishi</th><th>Jellyfish / LinearB / Swarmia / DX</th></tr>" as *u8)
535 o = ss_cat(out, o, "<tr><td>instrumentation</td><td class=e>ZERO manual + ZERO git-poll: derived from the native delivery event stream</td><td class=m>poll git/CI/Jira webhooks; batch ETL</td></tr>" as *u8)
536 o = ss_cat(out, o, "<tr><td>honesty</td><td class=e>each key tagged MEASURED / PROXY / PENDING; a key it cannot ground is shown PENDING, never faked</td><td class=m>single confident numbers</td></tr>" as *u8)
537 o = ss_cat(out, o, "<tr><td>agents as workers</td><td class=e>autonomous zero-Claude DONE frames counted as first-class deliveries</td><td class=m>humans-only</td></tr></table>" as *u8)
538 o = ss_cat(out, o, "<h2>Fetch spec (what to ingest to harden this)</h2><table><tr><th>target</th><th>why</th></tr>" as *u8)
539 o = ss_cat(out, o, "<tr><td>dora.dev 2024 State of DevOps</td><td class=m>the canonical thresholds + the AI-impact findings to re-band against</td></tr>" as *u8)
540 o = ss_cat(out, o, "<tr><td>DX Core 4 (getdx.com)</td><td class=m>unify DORA+SPACE+DevEx; the 4-dim model to extend these keys with effectiveness/quality</td></tr>" as *u8)
541 o = ss_cat(out, o, "<tr><td>debthist- join (F740b)</td><td class=m>filed→eaten timestamps to turn MTTR from PENDING into MEASURED</td></tr></table>" as *u8)
542 o = ss_cat(out, o, "<footer>source knowledge/status/ws_sync.jrnl + knowledge/store/debt- · DORA-analogue from the delivery event stream (a DONE = a shipped capability), not git-commit-instrumented · bands per DORA 2023-24 · generated epoch " as *u8)
543 o = ss_catn(out, o, sys_now_realtime_sec())
544 o = ss_cat(out, o, " · measured, never asserted · oversight: <a href=/pmcockpit>/pmcockpit</a> · bench: <a href=/compare/pmdash>/compare/pmdash</a> · hub: <a href=/compare>/compare</a></footer></body></html>\n" as *u8)
545 ss_writefile(outp, out, o)
546 d_p("wrote " as *u8); d_p(outp); d_p(" bytes=" as *u8); d_num(o); d_p("\n" as *u8)
547 sys_exit(0)
548 return 0
549}