nx_bright_rewrite_run.nx source
↩ module page · 151 lines · 9598 B
1// nx_bright_rewrite_run.nx -- R0l-d: the SOVEREIGN reasoning-rewrite run for BRIGHT (search R0l, 2026-09-16).
2// The program is a thin door over nx_bright_rewrite_lib (the lib carries the run, the two engine doors, the lease,
3// the idempotent re-run and the split verdict, so nx_bright_rewrite_gate can drive every rule in-process).
4//
5// argv are key=value only (so nx_sov_build_run --qualify can forward them):
6// gguf=<path> | engine=a.b.c.d:port -- ONE of the two engine doors is required: in-process weights, or a
7// sovereign nx_nofloat_serve on the LAN (POST /gen); a NAS plan row names
8// the compute node's engine and the NAS never loads the model
9// root=<bright root> out=<name> [mode=reason|concat] [maxnew=512] [limit=0] [split=<one split>]
10// [temp=<permil, 0 = greedy> topp=<permil> topk=<n> seed=<n>] -- sampling as DATA: the NAS smoke (2026-09-16)
11// showed greedy decoding looping on the same paragraph by the third step, so a run may declare the paper's
12// sampling instead; the seed keeps a sampled run reproducible byte for byte and every receipt names the values.
13// [lease_ttl=<s>] [progress=<path>]
14// Exit 0 every requested split COMPLETE, COMPLETE-EXISTING or SMOKE / 1 any split PARTIAL, LEASED-ELSEWHERE,
15// ALL-PASSTHROUGH or UNREADABLE / 2 usage / 3 model load failed / 4 the engine went down mid-run (rows kept).
16// license_tier: ORIGINAL. No hw writes (Rule 26).
17import "nx_bright_rewrite_lib.nx"
18
19const BRR_EXIT_OK: i64 = 0
20const BRR_EXIT_PARTIAL: i64 = 1
21const BRR_EXIT_USAGE: i64 = 2
22const BRR_EXIT_MODEL: i64 = 3
23const BRR_EXIT_ENGINE: i64 = 4
24
25func brr_usage() -> i64 {
26 br_puts("usage: nx_bright_rewrite_run gguf=<path>|engine=a.b.c.d:port [engine_kind=nishi|llamacpp] root=<bright-root> out=<name> [mode=reason|concat] [maxnew=512] [limit=0] [split=<name>] [temp=<permil> topp=<permil> topk=<n> seed=<n>] [lease_ttl=<s>] [progress=<path>]\n" as *u8)
27 return BRR_EXIT_USAGE
28}
29
30func main(argc: i64, argv: *i64) -> i64 {
31 var gguf: *u8 = 0 as *u8
32 var root: *u8 = 0 as *u8
33 var out: *u8 = 0 as *u8
34 var only: *u8 = 0 as *u8
35 var progress: *u8 = 0 as *u8
36 var engine_s: *u8 = 0 as *u8
37 var engine_kind_s: *u8 = 0 as *u8
38 let cfg: *i64 = sys_mmap(BR_CFG_SLOTS * BR_I64) as *i64
39 cfg[0] = 0; cfg[1] = BR_MAXNEW_DEFAULT; cfg[2] = 0; cfg[3] = BR_TEMP_GREEDY; cfg[4] = BR_TOPP_PERMIL
40 cfg[5] = BR_TOPK_DEFAULT; cfg[6] = BR_SEED; cfg[7] = BR_LEASE_TTL_DEFAULT
41 var ai: i64 = 1
42 while ai < argc {
43 let a: *u8 = argv[ai] as *u8
44 if br_starts(a, "gguf=" as *u8) == 1 { gguf = a + 5 }
45 if br_starts(a, "engine=" as *u8) == 1 { engine_s = a + 7 }
46 if br_starts(a, "engine_kind=" as *u8) == 1 { engine_kind_s = a + 12 }
47 if br_starts(a, "root=" as *u8) == 1 { root = a + 5 }
48 if br_starts(a, "out=" as *u8) == 1 { out = a + 4 }
49 if br_starts(a, "split=" as *u8) == 1 { only = a + 6 }
50 if br_starts(a, "progress=" as *u8) == 1 { progress = a + 9 }
51 if br_starts(a, "mode=" as *u8) == 1 { if br_streq(a + 5, "concat" as *u8) == 1 { cfg[0] = 1 } }
52 if br_starts(a, "maxnew=" as *u8) == 1 { cfg[1] = br_atoi(a + 7) }
53 if br_starts(a, "limit=" as *u8) == 1 { cfg[2] = br_atoi(a + 6) }
54 if br_starts(a, "temp=" as *u8) == 1 { cfg[3] = br_atoi(a + 5) }
55 if br_starts(a, "topp=" as *u8) == 1 { cfg[4] = br_atoi(a + 5) }
56 if br_starts(a, "topk=" as *u8) == 1 { cfg[5] = br_atoi(a + 5) }
57 if br_starts(a, "seed=" as *u8) == 1 { cfg[6] = br_atoi(a + 5) }
58 if br_starts(a, "lease_ttl=" as *u8) == 1 { cfg[7] = br_atoi(a + 10) }
59 ai = ai + 1
60 }
61 if (gguf as i64) == 0 { if (engine_s as i64) == 0 { return brr_usage() } }
62 if (root as i64) == 0 { br_puts("usage: root= is required\n" as *u8); return BRR_EXIT_USAGE }
63 if (out as i64) == 0 { br_puts("usage: out= is required\n" as *u8); return BRR_EXIT_USAGE }
64 if cfg[1] < 1 { cfg[1] = BR_MAXNEW_DEFAULT }
65 if cfg[1] > BR_MAXNEW_DEFAULT { cfg[1] = BR_MAXNEW_DEFAULT }
66 if cfg[4] < 1 { cfg[4] = BR_TOPP_PERMIL }
67 if cfg[4] > BR_TOPP_PERMIL { cfg[4] = BR_TOPP_PERMIL }
68 if cfg[5] < 1 { cfg[5] = BR_TOPK_DEFAULT }
69 if cfg[7] < 1 { cfg[7] = BR_LEASE_TTL_DEFAULT }
70 let eng: *i64 = br_eng_alloc()
71 if (engine_s as i64) != 0 {
72 if br_engine_parse(engine_s, eng) != 1 { br_puts("usage: engine= must be a.b.c.d:port (got " as *u8); br_puts(engine_s); br_puts(")\n" as *u8); return BRR_EXIT_USAGE }
73 eng[5] = br_engine_timeout_s(cfg[1])
74 if (engine_kind_s as i64) != 0 {
75 if br_streq(engine_kind_s, "llamacpp" as *u8) == 1 { eng[7] = BR_ENGINE_KIND_LLAMACPP } else {
76 if br_streq(engine_kind_s, "nishi" as *u8) == 0 { br_puts("usage: engine_kind= must be nishi or llamacpp (got " as *u8); br_puts(engine_kind_s); br_puts(")\n" as *u8); return BRR_EXIT_USAGE } }
77 }
78 // the liar-killer: an outside oracle may only write files that SAY so, so nothing it writes can be scored as ours
79 if eng[7] == BR_ENGINE_KIND_LLAMACPP { if br_find(out, br_slen(out), BR_ORACLE_MARK) < 0 { br_puts("REFUSED: engine_kind=llamacpp is an OUTSIDE ORACLE; out= must carry the word oracle (got " as *u8); br_puts(out); br_puts(") so its rows can never be mistaken for the sovereign run\n" as *u8); return BRR_EXIT_USAGE } }
80 }
81 br_puts("=== nx_bright_rewrite_run: the sovereign reasoning-rewrite run (chatml, i8) ===\n" as *u8)
82 if eng[6] == 1 {
83 br_puts(" engine=" as *u8); br_puts(engine_s)
84 if eng[7] == BR_ENGINE_KIND_LLAMACPP { br_puts(" engine_kind=llamacpp (OUTSIDE ORACLE: llama.cpp POST /completion, GPU; a bar, never the system of record; reply budget s=" as *u8) } else { br_puts(" engine_kind=nishi (remote door: POST /gen on a sovereign nx_nofloat_serve; reply budget s=" as *u8) }
85 br_putn(eng[5]); br_puts(")" as *u8)
86 } else { br_puts(" gguf=" as *u8); br_puts(gguf); br_puts(" (in-process door)" as *u8) }
87 br_puts(" root=" as *u8); br_puts(root); br_puts(" out=" as *u8); br_puts(out)
88 br_puts(" mode=" as *u8); if cfg[0] == 1 { br_puts("concat" as *u8) } else { br_puts("reason" as *u8) }
89 br_puts(" maxnew=" as *u8); br_putn(cfg[1]); br_puts(" limit=" as *u8); br_putn(cfg[2])
90 br_puts(" temp_pm=" as *u8); br_putn(cfg[3]); br_puts(" top_p_pm=" as *u8); br_putn(cfg[4]); br_puts(" top_k=" as *u8); br_putn(cfg[5]); br_puts(" seed=" as *u8); br_putn(cfg[6])
91 if cfg[3] == 0 { br_puts(" decoding=greedy" as *u8) } else { br_puts(" decoding=sampled" as *u8) }
92 br_puts(" lease_ttl_s=" as *u8); br_putn(cfg[7])
93 br_puts("\n" as *u8)
94 if eng[6] == 0 {
95 let t0: i64 = sys_now_ms()
96 let rc: i64 = nsv_init_i8(gguf)
97 if rc != 0 { br_puts("MODEL-LOAD-FAILED rc=" as *u8); br_putn(rc); br_puts("\n" as *u8); return BRR_EXIT_MODEL }
98 br_puts(" model loaded in ms=" as *u8); br_putn(sys_now_ms() - t0); br_puts("\n" as *u8)
99 }
100 if (progress as i64) == 0 { progress = sys_mmap(BR_PATH_CAP); br_progress_path(progress, root, out) }
101 br_puts(" progress=" as *u8); br_puts(progress); br_puts("\n" as *u8)
102 let st: *i64 = sys_mmap(BR_I64 * BR_ST_SLOTS) as *i64
103 var splits: i64 = 0
104 var complete: i64 = 0
105 var existing: i64 = 0
106 var smoke: i64 = 0
107 var partial: i64 = 0
108 var leased: i64 = 0
109 var down: i64 = 0
110 var allpass: i64 = 0
111 var unreadable: i64 = 0
112 var rows: i64 = 0
113 var written: i64 = 0
114 var pass: i64 = 0
115 var i: i64 = 0
116 while i < BR_NSPLITS {
117 let sp: *u8 = br_split(i)
118 var go: i64 = 1
119 if (only as i64) != 0 { if br_streq(only, sp) == 0 { go = 0 } }
120 if go == 1 {
121 splits = splits + 1
122 let r: i64 = br_run_split(root, sp, out, cfg, eng, progress, st)
123 if r != 0 { unreadable = unreadable + 1 } else {
124 rows = rows + st[0]; written = written + st[1]; pass = pass + st[2]
125 let s: i64 = st[8]
126 if s == BR_STATE_COMPLETE { complete = complete + 1 }
127 if s == BR_STATE_EXISTING { existing = existing + 1 }
128 if s == BR_STATE_SMOKE { smoke = smoke + 1 }
129 if s == BR_STATE_PARTIAL { partial = partial + 1 }
130 if s == BR_STATE_LEASED { leased = leased + 1 }
131 if s == BR_STATE_LEASE_IO { leased = leased + 1 }
132 if s == BR_STATE_ENGINE_DOWN { down = down + 1 }
133 if s == BR_STATE_ALL_PASSTHROUGH { allpass = allpass + 1 }
134 }
135 }
136 i = i + 1
137 }
138 br_puts("SUMMARY splits=" as *u8); br_putn(splits); br_puts(" complete=" as *u8); br_putn(complete)
139 br_puts(" existing=" as *u8); br_putn(existing); br_puts(" smoke=" as *u8); br_putn(smoke)
140 br_puts(" partial=" as *u8); br_putn(partial); br_puts(" leased=" as *u8); br_putn(leased)
141 br_puts(" engine_down=" as *u8); br_putn(down); br_puts(" all_passthrough=" as *u8); br_putn(allpass)
142 br_puts(" unreadable=" as *u8); br_putn(unreadable)
143 br_puts(" (partition: complete+existing+smoke+partial+leased+engine_down+all_passthrough+unreadable=splits) rows=" as *u8); br_putn(rows)
144 br_puts(" written_now=" as *u8); br_putn(written); br_puts(" passthrough=" as *u8); br_putn(pass); br_puts("\n" as *u8)
145 if down > 0 { return BRR_EXIT_ENGINE }
146 if partial > 0 { return BRR_EXIT_PARTIAL }
147 if leased > 0 { return BRR_EXIT_PARTIAL }
148 if allpass > 0 { return BRR_EXIT_PARTIAL }
149 if unreadable > 0 { return BRR_EXIT_PARTIAL }
150 return BRR_EXIT_OK
151}