nx_atlas_budget.nx source
↩ module page · 33 lines · 1070 B
1// nx_atlas_budget.nx -- atlas-hygiene COMPUTE CIRCUIT-BREAKER (blueprint Callout 4 / F266).
2// Per-subgraph token/compute budget: spent < limit -> OK (exit 0, continue); spent >= limit -> BREAK
3// (exit 5, pause + alert operator). Integer-only. license_tier: ORIGINAL expect_exit: 0
4import "nx_syscalls.nx"
5func ab_atoi(s: *u8) -> i64 {
6 var n: i64 = 0
7 var i: i64 = 0
8 while s[i] != (0 as u8) {
9 let c: i64 = s[i] as i64
10 if c < 48 { return n }
11 if c > 57 { return n }
12 n = n * 10 + (c - 48)
13 i = i + 1
14 }
15 return n
16}
17func main(argc: i64, argv: *i64) -> i64 {
18 if argc < 3 {
19 sys_write(1, "ATLASBUDGET ERR need spent limit\n" as *u8, 33)
20 sys_exit(2)
21 return 2
22 }
23 let sp: i64 = ab_atoi(argv[1] as *u8)
24 let lim: i64 = ab_atoi(argv[2] as *u8)
25 if sp < lim {
26 sys_write(1, "ATLASBUDGET OK under-budget continue\n" as *u8, 37)
27 sys_exit(0)
28 return 0
29 }
30 sys_write(1, "ATLASBUDGET BREAK over-budget PAUSE-alert\n" as *u8, 42)
31 sys_exit(5)
32 return 5
33}