code wiki / (root) / nx_msg_sync.nx

nx_msg_sync.nx

buildroot/runtime/nx_msg_sync.nx

16129 B400 linesdepth 5pulls 7 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_msg_sync.nx -- C2 of the comms lane: MULTI-DEVICE SYNC for nx_chat_store rooms. Contract symbol msy_devsync == the /compare/comms C2 watch contract. DONE-RULE (pre-declared in comms.plan before this organ existed): "The same history converges on a second device; a partition-printed reconcile measures zero divergence." REFEREE: nx_msg_sync_gate. MODEL: the SERVER plane (store_root from the shared chatstore.conf) is authoritative; a DEVICE holds a replica plane under its own root with the SAME layout, readable by nx_chat_store itself via a conf whose store_root names the device root -- one format, one ruler, no translation layer. The gate exploits exactly that: convergence is verified through the CONSUMER (nx_chat_store fetch on both roots, byte-compared), never self-certified by this syncer. SYNC IS A PULL (Telegram-cloud-sync class): devices SEND by appending at the server (C1); devices RECEIVE by pulling. Overlap rows are BYTE-COMPARED before anything is written: a replica that disagrees with the server on a row it already holds is SPLIT-BRAIN and the sync REFUSES LOUDLY -- it never merges, never overwrites, wrong in the direction of doing nothing. A replica holding MORE rows than the server likewise REFUSES (device-ahead). Missing rows land in ONE commit -- O(missing), the sts_append_fast shape batched -- never a whole-plane rewrite (the seq724 amplification law), and reads go through ss_open_cached + ss_hget (the seq356 law). SCOPE, stated so the next reader trusts nothing by accident: messages and del:<seq> tombstones sync; cur:<member> cursors are DEVICE-LOCAL BY DESIGN (each device owns its read state -- syncing them would make two phones share one unread badge); meta:bytes copies from the server. The full population is always reconciled: NO batch cap, NO sampling -- sync has no tunable numbers at all, and the only conf it reads is C1's store_root. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_store_seed_lib.nx nx_seg_store.nx nx_msg_sync.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_store_seed_lib.nxnx_seg_store.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main msy_usage msy_w sys_write sys_exit msy_eq msy_devsync sts_mm sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sts_werr sys_write ↻ sys_exit ↻ msy_confs sts_mm ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close msy_len msy_w ↻ msy_prefix_at msy_tok_ok ss_cat

structs

none

consts

31const MSY_EXIT_OK: i64 = 0
32const MSY_EXIT_USAGE: i64 = 2
33const MSY_EXIT_REFUSED: i64 = 3
34const MSY_EXIT_RETRY: i64 = 4
35const MSY_EXIT_DIVERGED: i64 = 5
37const MSY_NAME_MAX: i64 = 64
38const MSY_PFX_CAP: i64 = 256
39const MSY_CONF_CAP: i64 = 192
40const MSY_WSLACK: i64 = 65536 // writer slack, the seed lib's own margin
41const MSY_NL: i64 = 10
42const MSY_PIPE: i64 = 124

functions

44func msy_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
45func msy_n(v: i64) -> i64 { nxi_out(v); return 0 }
called by 2: msy_devsyncmsy_verify calls 1: nxi_out
46func msy_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: msy_confs
47func msy_eq(a: *u8, b: *u8) -> i64
called by 1: main
53func msy_tok_ok(s: *u8) -> i64
called by 1: msy_prefix_at
69func msy_confs(confpath: *u8, key: *u8, out: *u8, cap: i64) -> i64
105func msy_prefix_at(root: *u8, room: *u8, out: *u8) -> i64
114func msy_delkey(seq: i64, out: *u8) -> i64
called by 2: msy_devsyncmsy_verify calls 2: ss_catss_catn
122func msy_cmp_overlap(sh: *i64, dh: *i64, upto: i64) -> i64
149func msy_devsync(room: *u8, devroot: *u8, confpath: *u8) -> i64
312func msy_verify(room: *u8, devroot: *u8, confpath: *u8) -> i64
376func msy_usage() -> i64
called by 1: main calls 1: msy_w
380func msy_confpick(argc: i64, argv: *i64, idx: i64) -> *u8
called by 1: main
384func main(argc: i64, argv: *i64) -> i64