code wiki / _hdl_build / nx_doctor_apply.nx
nx_doctor_apply.nx
buildroot/runtime/_hdl_build/nx_doctor_apply.nx
about
nx_doctor_apply.nx -- THE NISHI DOCTOR's "graceful apply WITHOUT competition" core rung.
Operator: route a fix through the Doctor so it is applied gracefully without racing a workstream that is
concurrently editing the same shared organ. Synthesized from the Nishi Researcher's S-class corpus
(knowledge/fetched/doc_*.raw): LOCK (mutual exclusion, axis A: nx_arbiter fl_acquire) + EXACT-CONTEXT-MATCH
apply (axes B optimistic/CAS + C 3-way-merge/patch context: apply ONLY where the target region still matches
the CURRENT file exactly-once -> a concurrent edit that touched my region makes the match FAIL = REFUSE, never
clobber; an edit elsewhere leaves the match intact = apply = a clean merge for non-overlapping edits) +
ATOMIC tmp+rename (axis F: no torn write). Fail-closed: any ambiguity (no match / multi-match) -> REFUSE.
This does NOT verify or admit its own work (RACI: the Engineer re-verifies, the Warden admits) -- it is the
safe APPLY primitive the Doctor's fix queue (next rung) drives one-at-a-time.
usage: nx_doctor_apply <target> <oldstr-file> <newstr-file> [requester]
reads oldstr/newstr from files so multi-line patches work (NUL-free byte spans).
license_tier: ORIGINAL
dependencies 2 imports · 5 importers
imports: nx_syscalls.nxnx_arbiter.nx
imported by: nx_doctor_apply_gate.nxnx_doctor_queue.nxnx_doctor_queue_gate.nxnx_doctor_serve.nxnx_role_queue.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 19 | const DA_MAGIC_100000: i64 = 100000 |
| 20 | const DA_MAGIC_1024: i64 = 1024 |
| 22 | const DA_APPLIED: i64 = 0 |
| 23 | const DA_CONFLICT: i64 = 1 // target region not found -> already-applied OR changed by another -> NOT clobbered |
| 24 | const DA_AMBIG: i64 = 2 // oldstr matches >1 -> refuse (will not guess which) |
| 25 | const DA_ERR: i64 = 3 |
| 26 | const DA_CAP: i64 = 8388608 // 8 MiB bound -- source files are small; NEVER sys_read_file's 4 GiB (fork-hazard) |
| 27 | const DA_LOCK: *u8 = "doctor_apply" |
functions
| 29 | func da_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 30 | func da_w(s: *u8) -> i64 { return sys_write(1, s, da_slen(s)) } |
| 33 | func da_read(path: *u8, buf: *u8, cap: i64) -> i64 called by 8: doc_apply_memmaingt_file_eqdoc_pumpgq_containsgq_file_eq+2 calls 3: sys_openat_rdsys_readsys_close |
| 40 | func da_match_at(hay: *u8, i: i64, needle: *u8, nlen: i64) -> i64 |
| 44 | func da_count(hay: *u8, hn: i64, needle: *u8, nlen: i64) -> i64 |
| 50 | func da_find(hay: *u8, hn: i64, needle: *u8, nlen: i64) -> i64 |
| 58 | func doc_apply_mem(target: *u8, oldstr: *u8, oldlen: i64, newstr: *u8, newlen: i64) -> i64 |
| 86 | func main(argc: i64, argv: *i64) -> i64 |