nx_engine_dispatch.nx
buildroot/runtime/nx_engine_dispatch.nx
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
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
structs
| none |
consts
| 46 | const ED_EXIT_GREEN: i64 = 0 |
| 47 | const ED_EXIT_USAGE: i64 = 2 |
| 48 | const ED_EXIT_UNOBS: i64 = 3 |
| 49 | const ED_EXIT_FRONTIER: i64 = 4 |
| 50 | const ED_CONF_CAP: i64 = 65536 |
| 51 | const ED_PATH: i64 = 4096 |
| 52 | const ED_PROMPT_CAP: i64 = 16384 // the seat's own request window is 16 KB |
| 53 | const ED_BODY_CAP: i64 = 65536 |
| 54 | const ED_REQ_CAP: i64 = 131072 |
| 55 | const ED_RESP_CAP: i64 = 1048576 |
| 56 | const 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 |
| 57 | const ED_TEXT_CAP: i64 = 262144 |
| 58 | const ED_OUT: i64 = 65536 |
| 59 | const ED_ROW: i64 = 1024 |
| 60 | const ED_FRAG_CAP: i64 = 4096 |
| 61 | const ED_ARGV_MAX: i64 = 16 |
| 62 | const ED_I64: i64 = 8 |
| 63 | const ED_MAX_NEW_DEFAULT: i64 = 24 |
| 64 | const ED_MAX_NEW_SEAT_CAP: i64 = 96 // NSV_MAXNEW in nx_nofloat_serve_core |
| 65 | const 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 |
| 66 | const ED_FORK_TIMEOUT_MS: i64 = 300000 // an external call outran the edge window once at 282 s |
| 67 | const ED_DEFAULT_A: i64 = 127 |
| 68 | const ED_DEFAULT_B: i64 = 0 |
| 69 | const ED_DEFAULT_C: i64 = 0 |
| 70 | const ED_DEFAULT_D: i64 = 1 |
| 71 | const ED_DEFAULT_PORT: i64 = 8032 // nx_nofloat_serve NSD_PORT |
| 72 | const ED_NL: i64 = 10 |
| 73 | const ED_QUOTE: i64 = 34 |
| 74 | const ED_BSLASH: i64 = 92 |
| 75 | const ED_PIPE: i64 = 124 |
| 76 | const ED_HASH: i64 = 35 |
| 77 | const ED_SPACE: i64 = 32 |
| 78 | const ED_TAB: i64 = 9 |
| 79 | const ED_CR: i64 = 13 |
| 80 | const ED_HTTP_OK: i64 = 200 |
| 81 | const ED_MODE_RW: i64 = 420 |
| 82 | const ED_CLASS_U: i64 = 0 |
| 83 | const ED_CLASS_C: i64 = 1 |
| 84 | const ED_CLASS_UNSET: i64 = 2 // ES16: neither tclass nor class declared -- a refusal, never a default |
| 85 | const ED_JUDGE_NONE: i64 = 0 |
| 86 | const ED_JUDGE_KAT: i64 = 1 |
| 87 | const ED_JUDGE_CONTAINS: i64 = 2 |
| 88 | const ED_V_GREEN: i64 = 0 |
| 89 | const ED_V_RED: i64 = 1 |
| 90 | const ED_V_UNOBS: i64 = 3 |
| 91 | const ED_ENGINE_LOCAL: i64 = 1 |
| 92 | const ED_ENGINE_EXTERNAL: i64 = 2 |
| 93 | const ED_ENGINE_FRONTIER: i64 = 3 |
| 95 | const ED_T_NAME: i64 = 0 |
| 96 | const ED_T_CLASS: i64 = 1 |
| 97 | const ED_T_PROMPT: i64 = 2 |
| 98 | const ED_T_JUDGE_ARG: i64 = 3 |
| 99 | const ED_T_SUBSYS: i64 = 4 |
| 100 | const ED_T_TCLASS: i64 = 5 |
| 101 | const ED_T_CELLS: i64 = 6 |
| 103 | const ED_CF_FIELDS: i64 = 5 |
| 104 | const ED_ORD_LOCAL: i64 = 0 |
| 105 | const ED_ORD_EXTERNAL: i64 = 1 |
| 106 | const ED_ORD_CELLS: i64 = 2 |
functions
| 109 | func ed_cell(base: *u8, k: i64) -> *u8 { return ((base as i64) + k * ED_PATH) as *u8 } |
| 110 | func ed_fld(base: *u8, k: i64) -> *u8 { return ((base as i64) + k * ED_ROW) as *u8 } called by 1: ec_route_class |
| 111 | func ed_find(buf: *u8, s: i64, e: i64, lit: *u8) -> i64 called by 6: ec_route_classed_judge_containsed_json_stred_json_inted_external_gened_shift_row calls 1: mp_len |
| 125 | func ed_atoi(s: *u8) -> i64 |
| 131 | func 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 |
| 133 | func ed_trim_into(buf: *u8, s: i64, e: i64, dst: *u8, cap: i64) -> i64 |
| 147 | func ed_read(path: *u8, lenp: *i64) -> *u8 { return sys_read_file(path, lenp) } |
| 154 | func ec_route_class(path: *u8, name: *u8, cls: *i64, mx: *i64, ord: *i64, why: *u8) -> i64 |
| 207 | func ed_load_task(path: *u8, cells: *u8, cls: *i64, mx: *i64, ord: *i64, classes: *u8, why: *u8) -> i64 |
| 279 | func ed_judge_contains(cand: *u8, cn: i64, lit: *u8) -> i64 |
| 283 | func ed_judge_kat(cand: *u8, cn: i64, expected_path: *u8) -> i64 |
| 297 | func ed_judge(kind: i64, arg: *u8, cand: *u8, cn: i64) -> i64 |
| 302 | func ed_vname(v: i64) -> *u8 |
| 309 | func ed_json_escape(src: *u8, n: i64, dst: *u8, off: i64, cap: i64) -> i64 called by 1: ed_local_gen |
| 325 | func ed_hexval(c: i64) -> i64 called by 1: ed_json_str |
| 332 | func ed_json_str(json: *u8, s: i64, e: i64, key: *u8, dst: *u8, cap: i64) -> i64 |
| 370 | func ed_json_int(json: *u8, s: i64, e: i64, key: *u8) -> i64 |
| 390 | func 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 |
| 434 | func ed_external_gen(mcp: *u8, base: *u8, extcap: *u8, prompt_path: *u8, keyfile: *u8, subsys: *u8, ledger: *u8, text: *u8) -> i64 |
| 471 | func ed_ledger_row(path: *u8, now: i64, task: *u8, engine: *u8, status: *u8, verdict: *u8, gen: i64, ms: i64, note: *u8) -> i64 |
| 493 | func ed_shift_row(mcp: *u8, base: *u8, cap: *u8, task: *u8, gen: i64, ptok: i64, resp: *u8) -> i64 |
| 518 | func ed_dispatch(taskpath: *u8, statedir: *u8, la: i64, lb: i64, lc: i64, ld: i64, lport: i64, no_external: i64, dry: i64, |
| 666 | func ed_usage() -> i64 |
| 673 | func ed_parse_hostport(s: *u8, out: *i64) -> i64 called by 1: main |
| 698 | func main(argc: i64, argv: *i64) -> i64 |