code wiki / (root) / nx_treaty.nx

nx_treaty.nx

buildroot/runtime/nx_treaty.nx

11879 B283 linesdepth 3pulls 5 transitivereach 2 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_treaty.nx -- bilateral cooperative resource agreement. THE PARTNERSHIP PRIMITIVE. Per user 2026-05-19: "partnering with steam to improve things like vram usage, disk space usage." A treaty is a declarative, breachable agreement between two parties to share a contested resource on agreed terms. Parties may be: - native cell + native cell (intra-Nishi negotiation) - native cell + foreign symbiote (Nishi + Steam-hosted NMS) - organism + symbiote (whole-Nishi-ecosystem + foreign-program) The structural EXCEED-axis vs OS-level resource limits (cgroups, Job Objects, RLIMIT_AS): those are UNILATERAL ceilings imposed by the host. A treaty is BILATERAL -- both parties consent to share terms and either can renegotiate when conditions change. This is the only structurally honest way to integrate a foreground game with a foreground background-inference workload on the same RTX 5080: they negotiate VRAM share dynamically, not fight over it. Composes: nx_budget -- party budgets supply the negotiation basis nx_attention_class -- treaty priority cap (treaty can only require yield UP the priority hierarchy, never down -- a foreground party can't agree to yield to a background party) nx_symbiote -- foreign-party state + observed consumption nx_evict_journal -- proposals, acceptances, breaches logged nx_organism -- container that holds N treaties across all member pairs V1 ships pairwise treaties only. Multi-party treaties (e.g., {organism, Steam-NMS, OBS-recorder} all agreeing to share 12 GB VRAM with weights 60/30/10) are decomposable into pairwise treaties for V1; a multi-party primitive is queued. Gap list (V1 honest perf verdict): - bilateral only (multi-party decomposes) - no expiration time (treaties last until breach or release) - no automatic renegotiation when budgets change - breach detection is observation-window only (caller invokes nx_treaty_check_breach; no background monitor in V1)

dependencies 5 imports · 2 importers

nx_syscalls.nx nx_tier.nx nx_budget.nx nx_attention_class.nx nx_evict_journal.nx nx_treaty.nx nx_ecosystem_compose_test.nx nx_treaty_test.nx

imports: nx_syscalls.nxnx_tier.nxnx_budget.nxnx_attention_class.nxnx_evict_journal.nx

imported by: nx_ecosystem_compose_test.nxnx_treaty_test.nx

structs

92struct NxTreaty

consts

61const NX_MAGIC_1024: i64 = 1024
65const NX_TR_PROPOSED: nx_int = 0 // a proposed; b has not accepted
66const NX_TR_ACTIVE: nx_int = 1 // both parties agreed; in force
67const NX_TR_BREACHED: nx_int = 2 // one party violated; need renegotiate
68const NX_TR_RELEASED: nx_int = 3 // mutually dissolved
69const NX_TR_N_STATES: nx_int = 4
73const NX_TREATY_OK: nx_int = 0
74const NX_TREATY_ERR_PRIORITY_INVERT: nx_int = 1 // can't agree to yield down-priority
75const NX_TREATY_ERR_NOT_PROPOSED: nx_int = 2
76const NX_TREATY_ERR_NOT_ACTIVE: nx_int = 3
77const NX_TREATY_ERR_SHARES_INVALID: nx_int = 4 // a + b != 1024 (Q10 unity)
78const NX_TREATY_ERR_BREACHED: nx_int = 5
79const NX_TREATY_ERR_RELEASED: nx_int = 6
107const NX_TREATY_DEFAULT_BREACH_Q10: nx_int = 1126

functions

111func nx_tr_state_is_valid(s: nx_int) -> nx_int
called by 1: main
125func nx_treaty_propose(treaty_id: nx_int,
called by 2: mainmain calls 2: nx_ac_prioritysys_mmap
165func nx_treaty_accept(t: *NxTreaty, now_us: nx_size) -> nx_int
called by 2: mainmain
177func nx_treaty_party_share_q10(t: *NxTreaty, party_id: nx_int, kind: nx_int) -> nx_int
called by 1: main
200func nx_treaty_check_breach(t: *NxTreaty,
called by 2: mainmain
247func nx_treaty_release(t: *NxTreaty, now_us: nx_size) -> nx_int
called by 1: main
262func nx_treaty_renegotiate_shares(t: *NxTreaty,
called by 2: mainmain
280func nx_treaty_is_active(t: *NxTreaty) -> nx_int
called by 2: mainmain