code wiki / (root) / nx_engine_dispatch.nx

nx_engine_dispatch.nx

buildroot/runtime/nx_engine_dispatch.nx

43023 B768 linesdepth 6pulls 12 transitivereach 0 importersview sourcekind tooltopic engine
docsdependenciesstructsconstsfunctions

about

nx_engine_dispatch.nx -- ES3 of /compare/engineshift: THE DISPATCHER. ONE verb sends a task to the cheapest engine whose terms permit its class, stops at the first engine whose output the task's declared judge passes, returns the verdict with the engine named, and appends a shift-ledger row so the engine-shift scoreboard's local column can move (ES0 nx_seat shift; ES1 nx_seat_meter_beat writes the Claude column, this organ writes the local one). MEASURED 2026-09-02 before building: three routers existed and none was wired (nx_llm_provider 0 production importers, llm_routes.conf 0 active rows, nx_clawf_route registered-dark), and the local column had read ZERO since 2026-07-20 because nothing ever wrote it. THE LADDER (the operator's order: sovereign first, rent the frontier seat only for what only it can do): 1 LOCAL the sovereign no-float seat (nx_nofloat_serve, POST /gen on --local, default 127.0.0.1:8032); any class -- the bytes never leave the machine 2 EXTERNAL a free external worker through the estate's warden (nx_extllm_call over the sovereign MCP client); class U ONLY -- a C task is SKIPPED BY NAME here and the warden re-checks at the door (extllm XL2) 3 FRONTIER the rented seat. NOT an engine this organ can call: it exits NEEDS-FRONTIER with the task summary and the seat that reads it decides. Escalation is on a RED judge, never on a budget. THE JUDGE is declared in the task, never chosen here: `judge|kat|<expected-file>` (byte-exact after trimming outer whitespace) or `judge|contains|<literal>`. An engine's answer that the judge cannot read is UNOBSERVABLE, never GREEN and never RED. ES16 (operator 2026-09-02, "minimise token use autonomously without my engagement"): WHICH engines a task may try, its clearance and its token ceiling are DATA -- knowledge/engine_classes.conf rows `class|<name>|<U or C>|<engine order>|<max_new ceiling>`, named by the task's `tclass|<name>` row. A task with neither tclass nor class is REFUSED by name; it never defaults its way onto the frontier seat. A C row that lists external is refused at load, before any task runs. nx_engine_dispatch run <task.conf> <state-dir> [--local a.b.c.d:port] [--no-external] [--dry] [--mcp <nx_mcp_call elf> --base <url> --cap <seat cap> --extcap <extllm cap>] [--keyfile <path outside the estate>] [--ledger <estate egress ledger>] [--classes <engine_classes.conf>] nx_engine_dispatch judge <candidate-file> <task.conf> task.conf rows (pipe-separated, # comments): name|<id> tclass|<class row name> or class|U or C prompt|<path> judge|kat|<expected-file> or judge|contains|<literal> max_new|N (default 24; the class row's ceiling and the seat's 96 cap both bound it) subsystem|<name for the egress ledger> Ledger: <state-dir>/engine_dispatch.jrnl, one row per engine attempt: epoch TAB task TAB engine TAB status TAB verdict TAB gen_tokens TAB ms TAB note. Shift row on a LOCAL GREEN when --mcp is given: nx_seat meter maker-local-dispatch 1 <gen_tokens> <prompt_tokens> 0 dispatch-<task>-engine=local-src=nx_engine_dispatch Exit: 0 GREEN (an engine passed) | 2 usage | 3 UNOBSERVABLE (no engine could be reached) | 4 NEEDS-FRONTIER (every engine below the seat was reached or excluded by its class row and none passed). verdict= is the last token. license_tier: ORIGINAL. Writes only the ledger under <state-dir>. No hw writes (Rule 26).

dependencies 5 imports · 0 importers

nx_syscalls.nx nx_memplane_lib.nx nx_tool_run.nx nx_http_client.nx nx_http_response_parse.nx nx_engine_dispatch.nx

imports: nx_syscalls.nxnx_memplane_lib.nxnx_tool_run.nxnx_http_client.nxnx_http_response_parse.nx

imported by: nobody (leaf or entry point)

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

main sys_exit ed_usage mp_write_all sys_write mp_len 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 ↻ mp_streq ed_load_task sys_mmap ↻ ed_read sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close mp_cat ed_cell ed_trim_into ed_is_ws mp_streq ↻ ed_atoi sys_munmap ↻ ec_route_class

structs

none

consts

46const ED_EXIT_GREEN: i64 = 0
47const ED_EXIT_USAGE: i64 = 2
48const ED_EXIT_UNOBS: i64 = 3
49const ED_EXIT_FRONTIER: i64 = 4
50const ED_CONF_CAP: i64 = 65536
51const ED_PATH: i64 = 4096
52const ED_PROMPT_CAP: i64 = 16384 // the seat's own request window is 16 KB
53const ED_BODY_CAP: i64 = 65536
54const ED_REQ_CAP: i64 = 131072
55const ED_RESP_CAP: i64 = 1048576
56const ED_R_NOREPLY: i64 = 0 - 3 // ed_local_gen: the socket ACCEPTED, the request was WRITTEN, and zero bytes came back -- a listener that is not a seat. Measured 2026-09-05 on the NAS: 127.0.0.1:8032 accepted and closed, and the old code printed ANSWERED-UNPARSEABLE http=0, a status word that named the wrong stage and sent the reader at the parser
57const ED_TEXT_CAP: i64 = 262144
58const ED_OUT: i64 = 65536
59const ED_ROW: i64 = 1024
60const ED_FRAG_CAP: i64 = 4096
61const ED_ARGV_MAX: i64 = 16
62const ED_I64: i64 = 8
63const ED_MAX_NEW_DEFAULT: i64 = 24
64const ED_MAX_NEW_SEAT_CAP: i64 = 96 // NSV_MAXNEW in nx_nofloat_serve_core
65const ED_LOCAL_TIMEOUT_MS: i64 = 180000 // 96 tokens at the NAS CPU's 1 tok/s is 96 s; 180 s covers a loaded box
66const ED_FORK_TIMEOUT_MS: i64 = 300000 // an external call outran the edge window once at 282 s
67const ED_DEFAULT_A: i64 = 127
68const ED_DEFAULT_B: i64 = 0
69const ED_DEFAULT_C: i64 = 0
70const ED_DEFAULT_D: i64 = 1
71const ED_DEFAULT_PORT: i64 = 8032 // nx_nofloat_serve NSD_PORT
72const ED_NL: i64 = 10
73const ED_QUOTE: i64 = 34
74const ED_BSLASH: i64 = 92
75const ED_PIPE: i64 = 124
76const ED_HASH: i64 = 35
77const ED_SPACE: i64 = 32
78const ED_TAB: i64 = 9
79const ED_CR: i64 = 13
80const ED_HTTP_OK: i64 = 200
81const ED_MODE_RW: i64 = 420
82const ED_CLASS_U: i64 = 0
83const ED_CLASS_C: i64 = 1
84const ED_CLASS_UNSET: i64 = 2 // ES16: neither tclass nor class declared -- a refusal, never a default
85const ED_JUDGE_NONE: i64 = 0
86const ED_JUDGE_KAT: i64 = 1
87const ED_JUDGE_CONTAINS: i64 = 2
88const ED_V_GREEN: i64 = 0
89const ED_V_RED: i64 = 1
90const ED_V_UNOBS: i64 = 3
91const ED_ENGINE_LOCAL: i64 = 1
92const ED_ENGINE_EXTERNAL: i64 = 2
93const ED_ENGINE_FRONTIER: i64 = 3
95const ED_T_NAME: i64 = 0
96const ED_T_CLASS: i64 = 1
97const ED_T_PROMPT: i64 = 2
98const ED_T_JUDGE_ARG: i64 = 3
99const ED_T_SUBSYS: i64 = 4
100const ED_T_TCLASS: i64 = 5
101const ED_T_CELLS: i64 = 6
103const ED_CF_FIELDS: i64 = 5
104const ED_ORD_LOCAL: i64 = 0
105const ED_ORD_EXTERNAL: i64 = 1
106const ED_ORD_CELLS: i64 = 2

functions

109func ed_cell(base: *u8, k: i64) -> *u8 { return ((base as i64) + k * ED_PATH) as *u8 }
110func ed_fld(base: *u8, k: i64) -> *u8 { return ((base as i64) + k * ED_ROW) as *u8 }
called by 1: ec_route_class
111func ed_find(buf: *u8, s: i64, e: i64, lit: *u8) -> i64
125func ed_atoi(s: *u8) -> i64
131func ed_is_ws(c: i64) -> i64 { if c == ED_SPACE { return 1 } if c == ED_NL { return 1 } if c == ED_CR { return 1 } if c == ED_TAB { return 1 } return 0 }
called by 1: ed_trim_into
133func ed_trim_into(buf: *u8, s: i64, e: i64, dst: *u8, cap: i64) -> i64
147func ed_read(path: *u8, lenp: *i64) -> *u8 { return sys_read_file(path, lenp) }
154func ec_route_class(path: *u8, name: *u8, cls: *i64, mx: *i64, ord: *i64, why: *u8) -> i64
207func ed_load_task(path: *u8, cells: *u8, cls: *i64, mx: *i64, ord: *i64, classes: *u8, why: *u8) -> i64
279func ed_judge_contains(cand: *u8, cn: i64, lit: *u8) -> i64
called by 1: ed_judge calls 1: ed_find
283func ed_judge_kat(cand: *u8, cn: i64, expected_path: *u8) -> i64
297func ed_judge(kind: i64, arg: *u8, cand: *u8, cn: i64) -> i64
302func ed_vname(v: i64) -> *u8
called by 2: ed_dispatchmain
309func ed_json_escape(src: *u8, n: i64, dst: *u8, off: i64, cap: i64) -> i64
called by 1: ed_local_gen
325func ed_hexval(c: i64) -> i64
called by 1: ed_json_str
332func ed_json_str(json: *u8, s: i64, e: i64, key: *u8, dst: *u8, cap: i64) -> i64
370func ed_json_int(json: *u8, s: i64, e: i64, key: *u8) -> i64
390func ed_local_gen(a: i64, b: i64, c: i64, d: i64, port: i64, prompt: *u8, pn: i64, max_new: i64, text: *u8, meta: *i64) -> i64
434func ed_external_gen(mcp: *u8, base: *u8, extcap: *u8, prompt_path: *u8, keyfile: *u8, subsys: *u8, ledger: *u8, text: *u8) -> i64
471func ed_ledger_row(path: *u8, now: i64, task: *u8, engine: *u8, status: *u8, verdict: *u8, gen: i64, ms: i64, note: *u8) -> i64
493func ed_shift_row(mcp: *u8, base: *u8, cap: *u8, task: *u8, gen: i64, ptok: i64, resp: *u8) -> i64
518func ed_dispatch(taskpath: *u8, statedir: *u8, la: i64, lb: i64, lc: i64, ld: i64, lport: i64, no_external: i64, dry: i64,
666func ed_usage() -> i64
called by 1: main calls 2: mp_write_allmp_len
673func ed_parse_hostport(s: *u8, out: *i64) -> i64
called by 1: main
698func main(argc: i64, argv: *i64) -> i64