nx_treaty.nx
buildroot/runtime/nx_treaty.nx
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
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
| 92 | struct NxTreaty |
consts
| 61 | const NX_MAGIC_1024: i64 = 1024 |
| 65 | const NX_TR_PROPOSED: nx_int = 0 // a proposed; b has not accepted |
| 66 | const NX_TR_ACTIVE: nx_int = 1 // both parties agreed; in force |
| 67 | const NX_TR_BREACHED: nx_int = 2 // one party violated; need renegotiate |
| 68 | const NX_TR_RELEASED: nx_int = 3 // mutually dissolved |
| 69 | const NX_TR_N_STATES: nx_int = 4 |
| 73 | const NX_TREATY_OK: nx_int = 0 |
| 74 | const NX_TREATY_ERR_PRIORITY_INVERT: nx_int = 1 // can't agree to yield down-priority |
| 75 | const NX_TREATY_ERR_NOT_PROPOSED: nx_int = 2 |
| 76 | const NX_TREATY_ERR_NOT_ACTIVE: nx_int = 3 |
| 77 | const NX_TREATY_ERR_SHARES_INVALID: nx_int = 4 // a + b != 1024 (Q10 unity) |
| 78 | const NX_TREATY_ERR_BREACHED: nx_int = 5 |
| 79 | const NX_TREATY_ERR_RELEASED: nx_int = 6 |
| 107 | const NX_TREATY_DEFAULT_BREACH_Q10: nx_int = 1126 |
functions
| 111 | func nx_tr_state_is_valid(s: nx_int) -> nx_int called by 1: main |
| 125 | func nx_treaty_propose(treaty_id: nx_int, |
| 165 | func nx_treaty_accept(t: *NxTreaty, now_us: nx_size) -> nx_int |
| 177 | func nx_treaty_party_share_q10(t: *NxTreaty, party_id: nx_int, kind: nx_int) -> nx_int called by 1: main |
| 200 | func nx_treaty_check_breach(t: *NxTreaty, |
| 247 | func nx_treaty_release(t: *NxTreaty, now_us: nx_size) -> nx_int called by 1: main |
| 262 | func nx_treaty_renegotiate_shares(t: *NxTreaty, |
| 280 | func nx_treaty_is_active(t: *NxTreaty) -> nx_int |