nx_msg_sync.nx
buildroot/runtime/nx_msg_sync.nx
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
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
structs
| none |
consts
| 31 | const MSY_EXIT_OK: i64 = 0 |
| 32 | const MSY_EXIT_USAGE: i64 = 2 |
| 33 | const MSY_EXIT_REFUSED: i64 = 3 |
| 34 | const MSY_EXIT_RETRY: i64 = 4 |
| 35 | const MSY_EXIT_DIVERGED: i64 = 5 |
| 37 | const MSY_NAME_MAX: i64 = 64 |
| 38 | const MSY_PFX_CAP: i64 = 256 |
| 39 | const MSY_CONF_CAP: i64 = 192 |
| 40 | const MSY_WSLACK: i64 = 65536 // writer slack, the seed lib's own margin |
| 41 | const MSY_NL: i64 = 10 |
| 42 | const MSY_PIPE: i64 = 124 |
functions
| 44 | func 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 } |
| 45 | func msy_n(v: i64) -> i64 { nxi_out(v); return 0 } |
| 46 | func 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 |
| 47 | func msy_eq(a: *u8, b: *u8) -> i64 called by 1: main |
| 53 | func msy_tok_ok(s: *u8) -> i64 called by 1: msy_prefix_at |
| 69 | func msy_confs(confpath: *u8, key: *u8, out: *u8, cap: i64) -> i64 |
| 105 | func msy_prefix_at(root: *u8, room: *u8, out: *u8) -> i64 |
| 114 | func msy_delkey(seq: i64, out: *u8) -> i64 |
| 122 | func msy_cmp_overlap(sh: *i64, dh: *i64, upto: i64) -> i64 |
| 149 | func msy_devsync(room: *u8, devroot: *u8, confpath: *u8) -> i64 |
| 312 | func msy_verify(room: *u8, devroot: *u8, confpath: *u8) -> i64 |
| 376 | func msy_usage() -> i64 |
| 380 | func msy_confpick(argc: i64, argv: *i64, idx: i64) -> *u8 called by 1: main |
| 384 | func main(argc: i64, argv: *i64) -> i64 |