nx_seat_warm.nx source
↩ module page · 59 lines · 2154 B
1// nx_seat_warm.nx -- SEAT PRIMER (the anti-prefill-tax capability, 2026-07-16). One POST /gen
2// {prompt=<pack file>, max_new:1, chat, pfx:1} against a live serve builds the serve-resident
3// prefix-KV snapshot ONCE; every later engine/loop/curves call sharing the pack prefix then
4// re-prefills only its task suffix (boundary-safe, byte-identical -- nx_gen_pfx_live_gate 4/4).
5// At 1.5B this converts ~20min prefill per run into a one-time cost per seat boot.
6// usage: nx_seat_warm <packfile> <port> <chat> exit 0 = warmed ("ok":1 in reply), 1 = fail.
7// license_tier: ORIGINAL
8import "nx_forge_loop.nx"
9
10func main(argc: i64, argv: *i64) -> i64 {
11 if argc < 4 {
12 std_putln("usage: nx_seat_warm <packfile> <port> <chat>" as *u8)
13 sys_exit(2)
14 return 2
15 }
16 let a1: i64 = argv[1]
17 let packf: *u8 = a1 as *u8
18 let a2: i64 = argv[2]
19 let p2: *u8 = a2 as *u8
20 let port: i64 = std_atoi(p2)
21 let a3: i64 = argv[3]
22 let p3: *u8 = a3 as *u8
23 let chat: i64 = std_atoi(p3)
24 let prompt: *u8 = sys_mmap(32768) as *u8
25 let body: *u8 = sys_mmap(65536) as *u8
26 let resp: *u8 = sys_mmap(131072) as *u8
27 let plen: i64 = fc_read(packf, prompt, 32000)
28 if plen <= 0 {
29 std_putln("SEAT-WARM pack-unreadable" as *u8)
30 sys_exit(1)
31 return 1
32 }
33 var blen: i64 = flp_build_gen_body(prompt, plen, 1, 0, chat, body)
34 blen = flp_splice_pfx(body, blen)
35 let t0: i64 = sys_now_ms()
36 let got: i64 = fm_post_gen(127, 0, 0, 1, port, body, blen, resp, 131072)
37 let t1: i64 = sys_now_ms()
38 if got <= 0 {
39 std_putln("SEAT-WARM POST failed (serve live?)" as *u8)
40 sys_exit(1)
41 return 1
42 }
43 let okk: *u8 = "\"ok\":1" as *u8
44 let hit: i64 = fc_contains(resp, got, okk, 6)
45 std_puts("SEAT-WARM port=" as *u8)
46 std_pdec(port)
47 std_puts(" bytes=" as *u8)
48 std_pdec(plen)
49 std_puts(" ms=" as *u8)
50 std_pdec(t1 - t0)
51 if hit == 1 {
52 std_putln(" WARMED (snapshot resident; suffix-only prefill from here)" as *u8)
53 sys_exit(0)
54 return 0
55 }
56 std_putln(" REPLY-NOT-OK" as *u8)
57 sys_exit(1)
58 return 1
59}