nx_netscope_heal_loop.nx
buildroot/runtime/nx_netscope_heal_loop.nx
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
imports: nx_netscope_heal.nx
imported by: nx_netscope_heal_loop_test.nx
structs
| 29 | struct HealCircuit { state: i64, fails: i64, opened_ms: i64 } // 24 B |
| 31 | struct HealBudget { tokens: i64, last_refill_ms: i64 } // 16 B |
consts
| 14 | const HLOOP_MAGIC_2654435761: i64 = 2654435761 |
| 15 | const HLOOP_MAGIC_1103515245: i64 = 1103515245 |
| 16 | const HLOOP_MAGIC_12345: i64 = 12345 |
| 19 | const HLOOP_STABLE: i64 = 0 // healthy -> no action, resume monitoring |
| 20 | const HLOOP_ACT: i64 = 1 // execute the switch now |
| 21 | const HLOOP_WAIT: i64 = 2 // back off (out_wait ms) then retry |
| 22 | const HLOOP_GIVEUP: i64 = 3 // stop safely (no candidate / budget spent) |
| 25 | const HCB_CLOSED: i64 = 0 |
| 26 | const HCB_OPEN: i64 = 1 |
| 27 | const HCB_HALFOPEN: i64 = 2 |
| 30 | const HEAL_CIRCUIT_BYTES: i64 = 24 |
| 32 | const HEAL_BUDGET_BYTES: i64 = 16 |
functions
| 37 | func heal_jitter(seed: i64, attempt: i64, range: i64) -> i64 called by 1: heal_backoff_ms |
| 47 | func heal_backoff_ms(base_ms: i64, cap_ms: i64, attempt: i64, seed: i64) -> i64 |
| 60 | func heal_cb_init(cb: *HealCircuit) -> i64 called by 1: main |
| 66 | func heal_cb_allow(cb: *HealCircuit, now_ms: i64, open_ms: i64) -> i64 |
| 74 | func heal_cb_on_fail(cb: *HealCircuit, now_ms: i64, threshold: i64) -> i64 called by 1: main |
| 80 | func heal_cb_on_success(cb: *HealCircuit) -> i64 called by 1: main |
| 86 | func heal_budget_init(b: *HealBudget, tokens: i64) -> i64 called by 1: main |
| 91 | func heal_budget_try(b: *HealBudget, now_ms: i64, refill_ms: i64, max_tokens: i64) -> i64 |
| 105 | func heal_loop_next(decision_action: i64, cb: *HealCircuit, budget: *HealBudget, |