code wiki / _hdl_build / nx_torrent_backoff_gate.nx

nx_torrent_backoff_gate.nx

buildroot/runtime/_hdl_build/nx_torrent_backoff_gate.nx

9249 B176 linesdepth 8pulls 15 transitivereach 0 importersview sourcekind gate/prooftopic torrent
docsdependenciesstructsconstsfunctions

about

nx_torrent_backoff_gate.nx -- does the seeder stop burning a core when nothing it accepts can be served? ★THE DEFECT THIS PROVES (measured live 2026-07-30). `nx_torrent_seed` held ~71.6% of a core with the signature of a hot accept loop. Two independent faults, one symptom: (1) BOTH accept loops read `if afd >= 0 { ... }` with NO else branch. A persistently failing sys_accept (EMFILE / ENFILE / ECONNABORTED) therefore re-looped with ZERO delay -- an unconditional spin at whatever rate the CPU allows. (2) The forked child called `sys_exit(0)` UNCONDITIONALLY, so the parent could not observe that `ts_serve_peer_registry` was returning -2 every single time. /tmp/seed.log showed `served blocks=-2` repeating without end while the parent forked again immediately, forever. ★A LOOP THAT CANNOT SEE ITS OWN FAILURES CANNOT BACK OFF FROM THEM. The exit code was the missing wire. ★WHY A PURE FUNCTION IS THE UNIT UNDER TEST. "every peer handshake fails" is not a host state you can summon on a shared box, so a policy welded into an accept loop beside its own syscalls is untestable in practice -- which is exactly how it survived. Same discipline as `hc_keep_delay` and `ba_verdict`. ★THE TOOTH THAT MATTERS IS T6, the NEG-CONTROL: the pre-fix policy is kept alive as `ts_backoff_ms_old` and asserted to return 0 on the very inputs where the fix backs off. If someone reverts the fix, T2/T3/T4 go green against a spinning loop unless a tooth pins the OLD behaviour to the OLD answer. A gate that cannot fail on the unfixed code proves nothing about the fixed code. usage: nx_torrent_backoff_gate (CWD = the store root) exit 0 = GREEN · 1 = RED license_tier: ORIGINAL expect_exit: 0

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_torrent_seed.nx nx_artifact_root.nx nx_torrent_backoff_gate.nx

imports: nx_syscalls.nxnx_torrent_seed.nxnx_artifact_root.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main tb_p sys_write tb_len ts_backoff_ms tb_ck tb_p ↻ ts_backoff_ms_old sys_mmap ar_resolve ar_resolve_with ar_exists sys_openat_rd sys_close sys_mmap ↻ ar_read sys_openat_rd ↻ sys_read sys_close ↻ tb_read sys_openat_rd ↻ sys_read ↻ sys_close ↻ tb_pn sys_mmap ↻ sys_write ↻ tb_find tb_len ↻ sys_exit

structs

none

consts

29const TB_SRC: *u8 = "runtime/nx_torrent_seed.nx"
30const TB_CAP: i64 = 2097152

functions

32func tb_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: tb_ptb_find
33func tb_p(s: *u8) -> i64 { sys_write(1, s, tb_len(s)); return 0 }
called by 2: tb_ckmain calls 2: sys_writetb_len
34func tb_pn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
43func tb_ck(name: *u8, c: i64) -> i64
called by 1: main calls 1: tb_p
47func tb_read(path: *u8, buf: *u8) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
63func tb_find(buf: *u8, n: i64, pat: *u8) -> i64
called by 1: main calls 1: tb_len
77func main() -> i64