nx_circuit_breaker.nx
buildroot/runtime/nx_circuit_breaker.nx
about
nx_circuit_breaker.nx -- 3-state circuit breaker (Hystrix pattern).
module: nishi-core.ingest.circuit_breaker
depends: nishi-core.io.syscalls, nishi-core.io.iso8601
disk_kb: 4
capability: CORE_IO
license_tier: PUBLIC_NISHI_SUBSTRATE
genealogy_id: nygard_2007_release_it_stability_patterns +
netflix_hystrix_circuit_breaker_pattern +
resilience4j_circuit_breaker_states +
nishi_cardinal_14_graceful_degradation
Three-state circuit breaker primitive. Substrate Cardinal 14
(graceful degradation) guard against runaway-failing upstreams:
when an upstream returns errors at high frequency, the breaker
trips OPEN and short-circuits subsequent calls without hitting
the upstream. After a cool-down window, the breaker transitions
to HALF_OPEN to test recovery; success closes it, failure re-trips.
Per Pillar 5 equipment-health-verdict pattern applied at the
ingestion-substrate layer: every adapter gets a breaker
automatically; the substrate's poll-loop honors the verdict.
===== Why three states ===========================================
CLOSED requests flow through; failures counted toward threshold
OPEN requests short-circuited; counter timer running
HALF_OPEN probe requests allowed; success → CLOSED, failure → OPEN
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_iso8601.nx
imported by: nobody (leaf or entry point)
structs
| 68 | struct CircuitBreaker |
consts
| 42 | const NX_BREAKER_CLOSED: i64 = 1 |
| 43 | const NX_BREAKER_OPEN: i64 = 2 |
| 44 | const NX_BREAKER_HALF_OPEN: i64 = 3 |
| 55 | const NX_BREAKER_VERDICT_PROCEED: i64 = 1 |
| 56 | const NX_BREAKER_VERDICT_SHORT_CIRCUIT: i64 = 2 // OPEN — don't call upstream |
| 57 | const NX_BREAKER_VERDICT_PROBE: i64 = 3 // HALF_OPEN — single probe call |
| 89 | const NX_CIRCUIT_BREAKER_BYTES: i64 = 120 // 15 fields * 8 bytes |
| 93 | const NX_BREAKER_DEFAULT_FAILURE_PCT_Q10: i64 = 512 // 50% in Q10 |
| 94 | const NX_BREAKER_DEFAULT_MIN_REQUESTS: i64 = 10 |
| 95 | const NX_BREAKER_DEFAULT_COOLDOWN_SEC: i64 = 60 |
| 96 | const NX_BREAKER_DEFAULT_HALF_OPEN_PROBES: i64 = 3 |
| 152 | const NX_BREAKER_OUTCOME_SUCCESS: i64 = 1 |
| 153 | const NX_BREAKER_OUTCOME_FAILURE: i64 = 2 |
functions
| 46 | func nx_breaker_state_name(s: i64) -> *u8 |
| 59 | func nx_breaker_verdict_name(v: i64) -> *u8 |
| 100 | func nx_circuit_breaker_new(descriptor_hk: i64, now_unix: i64) -> *CircuitBreaker calls 1: sys_mmap |
| 126 | func nx_circuit_breaker_verdict(b: *CircuitBreaker, now_unix: i64) -> i64 |
| 155 | func nx_circuit_breaker_record_outcome(b: *CircuitBreaker, outcome: i64, now_unix: i64) -> i64 |
| 209 | func nx_circuit_breaker_force_trip(b: *CircuitBreaker, now_unix: i64) -> i64 |
| 220 | func nx_circuit_breaker_force_reset(b: *CircuitBreaker, now_unix: i64) -> i64 |