code wiki / _hdl_build / nx_ws_cas.nx

nx_ws_cas.nx

buildroot/runtime/_hdl_build/nx_ws_cas.nx

3195 B55 linesdepth 4pulls 4 transitivereach 10 importersview sourcekind librarytopic ws
docsdependenciesstructsconstsfunctions

about

nx_ws_cas.nx -- WMS-R8: CONCURRENT-SSOT-SAFE registry write (advisory-lock serialized). module: nishi-core.wms.ws_cas capability: CORE_COMPUTE (the registry's concurrent-writer durability floor) ROOT CAUSE this closes: ws_put_p (nx_workstream_store) is an UNGUARDED read-modify-write -- ss_get (idempotency probe) -> ss_begin/ss_add -> ws_seg_next (= 1 + ss_manifest line count) -> ss_commit (writes the seg files, then RMW-appends "seg-<id>" to manifest.txt via tmp+rename). TWO concurrent ws_put_p calls race on BOTH the segid AND manifest.txt: each reads the SAME manifest line count -> computes the SAME segid -> ss_write_seg clobbers the other's segment; and each reads the SAME old manifest.txt, appends ITS one line, renames -> last-writer-wins, so all but one concurrent manifest append is LOST. Net: committed records become UNRETRIEVABLE (the classic lost update) even though each ss_commit's own tmp+rename is atomic. ss_commit gives crash-atomicity, NOT inter-writer mutual exclusion -- the registry RMW needs a lock the substrate never applied to it (the audit said the locking primitive was ABSENT; R0b added sys_flock). THE FIX (one capability): serialize the WHOLE ws_put_p RMW under an EXCLUSIVE advisory lock (flock LOCK_EX) on a per-prefix lock file <prefix>wlock -- mirroring the WMS-R0b framed-append lock frame. Two writers can no longer both be inside the manifest RMW window -> every commit gets a distinct increasing segid and a non-clobbered manifest line -> ZERO lost updates. REUSE (rule 15): the lock frame is the proven nx_framed_append pattern (sys_flock LOCK_EX/UN from nx_syscalls); the write itself REUSES ws_put_p UNCHANGED (additive -- the unlocked path stays for genuine single-writer callers). Sovereign: nx_workstream_store + nx_syscalls only. license_tier: ORIGINAL

dependencies 2 imports · 10 importers

nx_workstream_store.nx nx_syscalls.nx nx_ws_cas.nx nx_media_ws_register.nx nx_pm_sclass.nx nx_pm_sclass_loop.nx nx_project_ws_register.nx nx_sclass_dispatch_gate.nx nx_survey_ws_register.nx nx_ws_cas_gate.nx nx_ws_crash_gate.nx nx_ws_exceed_gate.nx nx_ws_exceed_git_live_gate.nx

imports: nx_workstream_store.nxnx_syscalls.nx

imported by: nx_media_ws_register.nxnx_pm_sclass.nxnx_pm_sclass_loop.nxnx_project_ws_register.nxnx_sclass_dispatch_gate.nxnx_survey_ws_register.nxnx_ws_cas_gate.nxnx_ws_crash_gate.nxnx_ws_exceed_gate.nxnx_ws_exceed_git_live_gate.nx

structs

none

consts

none

functions

31func wc_lockpath(prefix: *u8, out: *u8) -> i64
called by 1: ws_put_locked
45func ws_put_locked(prefix: *u8, key: *u8, val: *u8) -> i64