code wiki / _hdl_build / nx_torrent_backoff_gate.nx
nx_torrent_backoff_gate.nx
buildroot/runtime/_hdl_build/nx_torrent_backoff_gate.nx
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
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
structs
| none |
consts
| 29 | const TB_SRC: *u8 = "runtime/nx_torrent_seed.nx" |
| 30 | const TB_CAP: i64 = 2097152 |
functions
| 32 | func tb_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 33 | func tb_p(s: *u8) -> i64 { sys_write(1, s, tb_len(s)); return 0 } |
| 34 | func tb_pn(v: i64) -> i64 |
| 43 | func tb_ck(name: *u8, c: i64) -> i64 |
| 47 | func tb_read(path: *u8, buf: *u8) -> i64 |
| 63 | func tb_find(buf: *u8, n: i64, pat: *u8) -> i64 |
| 77 | func main() -> i64 |