code wiki / (root) / nx_netscope_heal_loop.nx

nx_netscope_heal_loop.nx

buildroot/runtime/nx_netscope_heal_loop.nx

5463 B122 linesdepth 5pulls 6 transitivereach 1 importersview sourcekind librarytopic netscope
docsdependenciesstructsconstsfunctions

about

nx_netscope_heal_loop.nx -- NX-NETSCOPE rung 3, part 2: the live MAPE-K loop's SAFETY BRAIN. Pure, deterministic, sovereign (raw NishiLang, no deps) -> KAT-able offline. These are the "first do no harm" guards that turn the decision core (nx_netscope_heal.nx) into a self-healing loop that converges instead of thrashing. Concepts (re-implemented, no code copied): AWS "Exponential Backoff and Jitter" (Full Jitter), the circuit breaker (Nygard/Fowler), and a token-bucket retry budget (metastable-failure avoidance). The remaining thin I/O wrapper (real sys_clock_nanosleep sleep + set-resolver) is the deployment step. license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_netscope_heal.nx nx_netscope_heal_loop.nx nx_netscope_heal_loop_test.nx

imports: nx_netscope_heal.nx

imported by: nx_netscope_heal_loop_test.nx

structs

29struct HealCircuit { state: i64, fails: i64, opened_ms: i64 } // 24 B
31struct HealBudget { tokens: i64, last_refill_ms: i64 } // 16 B

consts

14const HLOOP_MAGIC_2654435761: i64 = 2654435761
15const HLOOP_MAGIC_1103515245: i64 = 1103515245
16const HLOOP_MAGIC_12345: i64 = 12345
19const HLOOP_STABLE: i64 = 0 // healthy -> no action, resume monitoring
20const HLOOP_ACT: i64 = 1 // execute the switch now
21const HLOOP_WAIT: i64 = 2 // back off (out_wait ms) then retry
22const HLOOP_GIVEUP: i64 = 3 // stop safely (no candidate / budget spent)
25const HCB_CLOSED: i64 = 0
26const HCB_OPEN: i64 = 1
27const HCB_HALFOPEN: i64 = 2
30const HEAL_CIRCUIT_BYTES: i64 = 24
32const HEAL_BUDGET_BYTES: i64 = 16

functions

37func heal_jitter(seed: i64, attempt: i64, range: i64) -> i64
called by 1: heal_backoff_ms
47func heal_backoff_ms(base_ms: i64, cap_ms: i64, attempt: i64, seed: i64) -> i64
called by 2: heal_loop_nextmain calls 1: heal_jitter
60func heal_cb_init(cb: *HealCircuit) -> i64
called by 1: main
66func heal_cb_allow(cb: *HealCircuit, now_ms: i64, open_ms: i64) -> i64
called by 2: heal_loop_nextmain
74func heal_cb_on_fail(cb: *HealCircuit, now_ms: i64, threshold: i64) -> i64
called by 1: main
80func heal_cb_on_success(cb: *HealCircuit) -> i64
called by 1: main
86func heal_budget_init(b: *HealBudget, tokens: i64) -> i64
called by 1: main
91func heal_budget_try(b: *HealBudget, now_ms: i64, refill_ms: i64, max_tokens: i64) -> i64
called by 2: heal_loop_nextmain
105func heal_loop_next(decision_action: i64, cb: *HealCircuit, budget: *HealBudget,