nx_crdt_seq.nx
buildroot/runtime/nx_crdt_seq.nx
about
nx_crdt_seq.nx -- SOVEREIGN SEQUENCE CRDT (RGA: Replicated Growable Array, Roh et al. 2011). The V-COLLAB rung-1
fix for the recurring multi-agent EDIT COLLISION (two Claude sessions "file modified since read" = the git/gitea
collision the operator asked to KILL 2026-05-27). Each element has a unique id (lamport clock, actor) + the id of
the element it was inserted AFTER (its RGA reference/parent). Concurrent inserts after the same reference are
ordered by a DETERMINISTIC total order on ids (descending) that every replica computes identically -> ALL replicas
converge to the SAME sequence regardless of op arrival order, and NO concurrent edit is ever lost (unlike a lock/
last-writer-wins, which drops one). 100% integer, deterministic. license_tier: ORIGINAL
dependencies 1 imports · 3 importers
imports: nx_syscalls.nx
imported by: nx_crdt_seq_gate.nxnx_crdt_sync.nxnx_crdt_sync_gate.nx
structs
| none |
consts
| 10 | const SEQ_MAX: i64 = 512 // max elements |
| 11 | const SEQ_INF: i64 = 1000000000 // id-ceiling sentinel (> any real clock) |
functions
| 14 | func seq_item(doc: *i64, i: i64) -> *i64 { return (doc as i64 + (1 + i*6)*8) as *i64 } |
| 16 | func seq_new() -> *i64 |
| 21 | func seq_count(doc: *i64) -> i64 { return doc[0] } |
| 24 | func id_lt(ac: i64, aa: i64, bc: i64, ba: i64) -> i64 called by 1: seq_emit_children |
| 31 | func seq_find(doc: *i64, idc: i64, ida: i64) -> i64 |
| 44 | func seq_add(doc: *i64, idc: i64, ida: i64, value: i64, refc: i64, refa: i64) -> i64 |
| 56 | func seq_delete(doc: *i64, idc: i64, ida: i64) -> i64 |
| 64 | func seq_emit_children(doc: *i64, refc: i64, refa: i64, out: *u8, olen: *i64, prevc: i64, preva: i64) -> i64 |
| 101 | func seq_materialize(doc: *i64, out: *u8) -> i64 |