code wiki / (root) / nx_field_beat.nx

nx_field_beat.nx source

↩ module page · 162 lines · 9806 B

1// nx_field_beat.nx -- THE OFF-PEAK FIELD BEAT (/compare/fieldwatch FW4, 2026-09-05): re-runs nx_field_discover for every 2// domain on regen.list that carries a .seeds file, so the discovered field is LIVING -- re-read on a beat, never authored 3// once. "Not during peak times" (operator, 2026-09-05) is MEASURED, not guessed: the clock row `fieldbeat` is listed in 4// knowledge/status/clock_heavy.conf, so nx_clock_tickless defers it through clk_storm_defer while nx_ioadmit_lib reports 5// zero spawn budget (the same D-state line /api/build refuses on); a wall-clock window would be a magic number that 6// dispatches into a storm at 03:00 and idles a quiet afternoon. 7// Stamp: knowledge/status/fieldbeat.stamp, truncate-written LAST (ts= domains= ran= ok= failed= skipped_no_seeds= sum= 8// candidates_total= drifted_total= capped= verdict=GREEN|RED|EMPTY); a non-default list stamps <list>.stamp so a trial run can 9// never forge the production heartbeat. Journal: knowledge/status/fieldbeat.jrnl, one row per domain per run (append). 10// The decisions live in nx_field_beat_lib (gated in-process); the first production stamp is the wire's witness. 11// fw_beat is the FW4 watch symbol: it IS the loop, not a name written to flip a cell. fw_refetch_drift is the FW5 watch 12// symbol: the discover organ re-fetches every seed on every run and reports drifted= (a mirror whose bytes changed since 13// the previous fetch); this beat sums it into drifted_total= -- a COUNT, never an alarm, because a dynamic page carrying a 14// per-request nonce drifts every beat; the alarm is the .field diff FW9 raises when a rival appears or vanishes. 15// Usage: nx_field_beat [list-path] default buildroot/knowledge/compare/regen.list 16// Exits: 0 every domain with seeds ran OK | 1 at least one domain FAILED (stamp written, verdict=RED) | 2 usage 17// | 3 refused: list unreadable or names no domain (NO stamp), or no domain carried seeds (stamp verdict=EMPTY) 18// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 19import "nx_syscalls.nx" 20import "nx_tool_run.nx" 21import "nx_field_beat_lib.nx" 22 23const FB_ROOT: *u8 = "/volume1/homes/elderwesto/nishihost/" 24const FB_DISCOVER: *u8 = "/volume1/homes/elderwesto/nishihost/nx_field_discover.elf" 25const FB_LIST_DEFAULT: *u8 = "buildroot/knowledge/compare/regen.list" 26const FB_SEEDS_DIR: *u8 = "buildroot/knowledge/compare/" 27const FB_SEEDS_EXT: *u8 = ".seeds" 28const FB_JRNL: *u8 = "knowledge/status/fieldbeat.jrnl" 29const FB_PATH_CAP: i64 = 1024 30const FB_CAPCAP: i64 = 262144 // one discover receipt: FIELD-SEED lines for up to FD_MAX_SEEDS=62 seeds plus the FIELD-OK line, 256 KiB is 40x the measured 43-seed run 31const FB_ARGVN: i64 = 4 32const FB_DOMAIN_TIMEOUT_MS: i64 = 1800000 // one domain's discovery: at most FD_MAX_SEEDS=62 fetches through the sovereign fetcher, whose own per-fetch deadline bounds each; a domain past 30 minutes is counted FAILED and announced, never waited on forever 33const FB_T_OK: i64 = 0 // slots of the totals vector fw_beat fills 34const FB_T_FAILED: i64 = 1 35const FB_T_SKIPPED: i64 = 2 36const FB_T_CANDS: i64 = 3 37const FB_T_DRIFT: i64 = 4 // FW5: seed mirrors that changed since the previous fetch, summed over the domains that ran 38const FB_T_N: i64 = 5 39const FB_EXIT_RED: i64 = 1 40const FB_EXIT_USAGE: i64 = 2 41const FB_EXIT_REFUSE: i64 = 3 42const FB_OUTFD: i64 = 1 43const FB_ERRFD: i64 = 2 44 45func fbp_out(s: *u8) -> i64 { fb_puts(FB_OUTFD, s); return 0 } 46func fbp_err(s: *u8) -> i64 { fb_puts(FB_ERRFD, s); return 0 } 47func fbp_exists(path: *u8) -> i64 { 48 let lp: *i64 = sys_mmap(16) as *i64 49 let b: *u8 = sys_read_file(path, lp) 50 if (b as i64) == 0 { return 0 } 51 return 1 52} 53// FW5: the drifted= field of one discover receipt -- the count of seed mirrors whose bytes changed since the previous fetch. 54// FB_UNPARSED when the receipt has no FIELD-OK line or predates the field (an older discover binary), so an absent measurement 55// is never summed as zero. 56func fw_refetch_drift(cap: *u8, n: i64) -> i64 { return fb_receipt_int(cap, n, "drifted" as *u8) } 57 58// THE BEAT: one pass over every named domain -- stat its seeds, fork the discover organ when they exist, read the 59// receipt, classify, announce, journal. Fills tot[FB_T_OK..FB_T_DRIFT]; returns how many domains actually ran. 60func fw_beat(names: *u8, n: i64, ts: i64, jfd: i64, tot: *i64) -> i64 { 61 let spath: *u8 = sys_mmap(FB_PATH_CAP) 62 let cap: *u8 = sys_mmap(FB_CAPCAP) 63 let olen: *i64 = sys_mmap(16) as *i64 64 tot[FB_T_OK] = 0; tot[FB_T_FAILED] = 0; tot[FB_T_SKIPPED] = 0; tot[FB_T_CANDS] = 0; tot[FB_T_DRIFT] = 0 65 var i: i64 = 0 66 while i < n { 67 let dom: *u8 = fb_domain_at(names, i) 68 var o: i64 = fb_cat(spath, 0, FB_SEEDS_DIR, FB_PATH_CAP) 69 o = fb_cat(spath, o, dom, FB_PATH_CAP) 70 o = fb_cat(spath, o, FB_SEEDS_EXT, FB_PATH_CAP) 71 let present: i64 = fbp_exists(spath) 72 var rc: i64 = 0 73 var ok: i64 = 0 74 var c: i64 = FB_UNPARSED 75 var nm: i64 = FB_UNPARSED 76 var fs: i64 = FB_UNPARSED 77 var dr: i64 = FB_UNPARSED 78 olen[0] = 0 79 if present == 1 { 80 let av: *i64 = sys_mmap(8 * FB_ARGVN) as *i64 81 av[0] = FB_DISCOVER as i64 82 av[1] = dom as i64 83 av[2] = 0 84 rc = tr_run_capture_to(FB_DISCOVER, av, cap, FB_CAPCAP, olen, FB_DOMAIN_TIMEOUT_MS) 85 ok = fb_receipt_ok(cap, olen[0]) 86 c = fb_receipt_int(cap, olen[0], "candidates" as *u8) 87 nm = fb_receipt_int(cap, olen[0], "named" as *u8) 88 fs = fb_receipt_int(cap, olen[0], "failed" as *u8) 89 dr = fw_refetch_drift(cap, olen[0]) 90 } 91 let cls: i64 = fb_classify(rc, ok, present) 92 if cls == FB_CLASS_OK { tot[FB_T_OK] = tot[FB_T_OK] + 1; if c > 0 { tot[FB_T_CANDS] = tot[FB_T_CANDS] + c } if dr > 0 { tot[FB_T_DRIFT] = tot[FB_T_DRIFT] + dr } } 93 if cls == FB_CLASS_FAIL { tot[FB_T_FAILED] = tot[FB_T_FAILED] + 1 } 94 if cls == FB_CLASS_SKIP { tot[FB_T_SKIPPED] = tot[FB_T_SKIPPED] + 1 } 95 fbp_out("FIELDBEAT dom=" as *u8); fbp_out(dom) 96 fbp_out(" class=" as *u8); fbp_out(fb_class_name(cls)) 97 fbp_out(" rc=" as *u8); fb_putn(FB_OUTFD, rc) 98 fbp_out(" candidates=" as *u8); fb_putn(FB_OUTFD, c) 99 fbp_out(" named=" as *u8); fb_putn(FB_OUTFD, nm) 100 fbp_out(" failed_seeds=" as *u8); fb_putn(FB_OUTFD, fs) 101 fbp_out(" drifted=" as *u8); fb_putn(FB_OUTFD, dr) 102 fbp_out(" receipt_bytes=" as *u8); fb_putn(FB_OUTFD, olen[0]) 103 fbp_out("\n" as *u8) 104 if jfd >= 0 { fb_jrnl_row(jfd, ts, dom, cls, rc, c, nm, fs) } 105 i = i + 1 106 } 107 return tot[FB_T_OK] + tot[FB_T_FAILED] 108} 109 110func main(argc: i64, argv: *i64) -> i64 { 111 if argc > 2 { fbp_err("usage: nx_field_beat [list-path]\n" as *u8); return FB_EXIT_USAGE } 112 // CWD ANCHOR: the list, the seeds, the journal and the stamp are serving-root-relative, and the clock plane, the 113 // job lane and a seat's shell all start somewhere else. Announced, never silent. 114 sys_chdir(FB_ROOT) 115 fbp_out("[nx_field_beat] CWD anchored to " as *u8); fbp_out(FB_ROOT); fbp_out("\n" as *u8) 116 var list: *u8 = FB_LIST_DEFAULT 117 var is_default: i64 = 1 118 if argc == 2 { list = argv[1] as *u8; is_default = 0 } 119 let lp: *i64 = sys_mmap(16) as *i64 120 let lb: *u8 = sys_read_file(list, lp) 121 if (lb as i64) == 0 { fbp_err("FIELDBEAT-REFUSE list unreadable: " as *u8); fbp_err(list); fbp_err("\n" as *u8); return FB_EXIT_REFUSE } 122 let names: *u8 = sys_mmap(FB_NAME_CAP * FB_MAX_DOMAINS) 123 let capped: *i64 = sys_mmap(16) as *i64 124 let n: i64 = fb_list_domains(lb, lp[0], names, capped) 125 if n < 1 { fbp_err("FIELDBEAT-REFUSE the list names no domain: " as *u8); fbp_err(list); fbp_err("\n" as *u8); return FB_EXIT_REFUSE } 126 if capped[0] == 1 { fbp_out("FIELDBEAT-CAPPED the list holds more than FB_MAX_DOMAINS rows; domains= below is a FLOOR, not the population\n" as *u8) } 127 let tsb: *i64 = sys_mmap(16) as *i64 128 sys_clock_gettime_real(tsb) 129 let ts: i64 = tsb[0] 130 let jfd: i64 = sys_openat_append(FB_JRNL, MODE_0644) 131 if jfd < 0 { fbp_out("FIELDBEAT-JRNL-UNWRITABLE " as *u8); fbp_out(FB_JRNL); fbp_out(" -- rows below are announced only\n" as *u8) } 132 let tot: *i64 = sys_mmap(8 * FB_T_N) as *i64 133 fw_beat(names, n, ts, jfd, tot) 134 if jfd >= 0 { sys_close(jfd) } 135 let okc: i64 = tot[FB_T_OK] 136 let failc: i64 = tot[FB_T_FAILED] 137 let skipc: i64 = tot[FB_T_SKIPPED] 138 let cands: i64 = tot[FB_T_CANDS] 139 let drift: i64 = tot[FB_T_DRIFT] 140 let stp: *u8 = sys_mmap(FB_PATH_CAP) 141 fb_stamp_path(list, is_default, stp, FB_PATH_CAP) 142 let sfd: i64 = sys_openat_wr(stp, MODE_0644) 143 if sfd < 0 { fbp_err("FIELDBEAT-STAMP-UNWRITABLE " as *u8); fbp_err(stp); fbp_err("\n" as *u8) } else { 144 fb_stamp_write(sfd, ts, list, n, okc, failc, skipc, cands, capped[0], drift) 145 sys_close(sfd) 146 fbp_out("FIELDBEAT-STAMP " as *u8); fbp_out(stp); fbp_out("\n" as *u8) 147 } 148 fbp_out("FIELDBEAT-OK list=" as *u8); fbp_out(list) 149 fbp_out(" domains=" as *u8); fb_putn(FB_OUTFD, n) 150 fbp_out(" ran=" as *u8); fb_putn(FB_OUTFD, okc + failc) 151 fbp_out(" ok=" as *u8); fb_putn(FB_OUTFD, okc) 152 fbp_out(" failed=" as *u8); fb_putn(FB_OUTFD, failc) 153 fbp_out(" skipped_no_seeds=" as *u8); fb_putn(FB_OUTFD, skipc) 154 fbp_out(" sum=" as *u8); fb_putn(FB_OUTFD, okc + failc + skipc) 155 fbp_out(" candidates_total=" as *u8); fb_putn(FB_OUTFD, cands) 156 fbp_out(" drifted_total=" as *u8); fb_putn(FB_OUTFD, drift) 157 fbp_out(" capped=" as *u8); fb_putn(FB_OUTFD, capped[0]) 158 fbp_out(" verdict=" as *u8); fbp_out(fb_stamp_verdict(okc, failc)); fbp_out("\n" as *u8) 159 if okc + failc == 0 { return FB_EXIT_REFUSE } 160 if failc > 0 { return FB_EXIT_RED } 161 return 0 162}