code wiki / _hdl_build / nx_mgmt_core.nx

nx_mgmt_core.nx source

↩ module page · 37 lines · 2360 B

1// nx_mgmt_core.nx -- the LOGIC / DOMAIN layer of the management plane (the hexagonal CORE). 2// PURE business rules: NO IO, NO HTTP, NO file/exec, NO sockets. It computes verdicts/flags/decisions from 3// PRIMITIVE inputs only, so it is independently testable and the transport (IO) + data (adapter) layers depend 4// on IT -- never the reverse (dependency inversion). Grounded in the banked architecture research 5// (knowledge/library/arch_*.txt: three-tier presentation/logic/data + hexagonal ports-and-adapters + loose 6// coupling / high cohesion + dependency-inversion + SRP). This is the inner ring; adapters plug in at the edges. 7// license_tier: ORIGINAL 8import "nx_syscalls.nx" 9 10const MC_MAXR: i64 = 5 // crash-loop policy: restarts-in-window >= MC_MAXR => looping. (a domain threshold) 11 12// ---- per-service classification rules (pure) -------------------------------------------------------- 13func mc_is_dup(procs: i64) -> i64 { if procs > 1 { return 1 } return 0 } 14func mc_is_loop(rwin: i64) -> i64 { if rwin >= MC_MAXR { return 1 } return 0 } 15// NB: callers MUST pass the count of INDEPENDENT supervisor LINEAGES (session-leaders), NOT raw `supervise` 16// procs -- the supervisor's reader-keeper child shares the argv, so raw proc-count false-positives (live-proven 17// 2026-06-29). The rule is correct; the DATA layer is responsible for computing the lineage count. 18func mc_is_duel(sup_lineages: i64) -> i64 { if sup_lineages > 1 { return 1 } return 0 } 19 20// ---- overall health verdict (pure): 0 = UNKNOWN (no data), 1 = OK, 2 = DEGRADED ----------------------- 21func mc_verdict(no_data: i64, reasons: i64) -> i64 { 22 if no_data == 1 { return 0 } 23 if reasons == 0 { return 1 } 24 return 2 25} 26 27// ---- the deploy safety decision (pure state machine) -------------------------------------------------- 28// 0 = SUCCESS (promoted + healthy) ; 1 = ROLLBACK (promoted-but-unhealthy / promote-failed) ; 29// 2 = ABORT (invalid artifact / ship-failed -- nothing promoted). This is the SAME rule the SOTA-gated 30// nx_deploy_lib encodes; the CORE owns it so the transport layer depends on the domain, not on an adapter. 31func mc_deploy_decide(valid: i64, ship_rc: i64, promote_rc: i64, health_ok: i64) -> i64 { 32 if valid == 0 { return 2 } 33 if ship_rc != 0 { return 2 } 34 if promote_rc != 0 { return 1 } 35 if health_ok == 0 { return 1 } 36 return 0 37}