nx_remedy.nx
buildroot/runtime/nx_remedy.nx
about
nx_remedy.nx -- formalized self-remediation cycle as substrate primitives.
Implements the SELF_REMEDIATION_AS_MATHEMATICIAN cardinal as a sequence
of named primitives, so NishiLang itself can run the 7-phase cycle
autonomously -- no AI in the loop. Every fix is principled, every
recommendation cites the math, every applied change is A/B verified
AND generalization-proven before adoption.
CYCLE PHASES (mirror docs/SELF_REMEDIATION_AS_MATHEMATICIAN.md):
1. detect -- anomaly check vs baseline / threshold / regression
2. diagnose -- classify into closed RootCause taxonomy
3. propose -- rank candidate FixClass options w/ cost+effectiveness
4. apply -- emit ActionPlan struct for the top proposal
5. ab_verify -- before/after measurement verdict
6. generalize -- grid coverage proof (no single-point overfitting)
7. record -- structured provenance ledger entry
Closed taxonomies (also numeric IDs for fast dispatch):
AnomalyKind : ANOMALY_NONE / TOLERANCE_EXCEEDED / REGRESSION /
STATISTICAL_OUTLIER / TIER_OVERFLOW / TIER_UNDERFLOW /
CALIBRATION_MISMATCH
RootCause : RC01..RC14 (NumericOverflow ... StaleCalibration)
FixClass : FX01..FX13 (EscalateNumericTier ... Ensemble)
ApplyVerdict : WORKED / NO_CHANGE / REGRESSION
GenVerdict : PASSES_GRID / FAILS_AT_CELL
CycleVerdict : ADOPT / REJECT_FAILED_AB / REJECT_FAILED_GEN / NO_ACTION_NEEDED
genealogy_id: lehmann_casella_1998 (estimator theory) +
aristotelian_root_cause (4-cause taxonomy) +
toyota_production_system_andon (halt-on-anomaly)
lineage_id: estimator_theory + change_impact_measurement
dependencies 2 imports · 1 importers
imports: syscalls.nxnx_estimator_diagnostics.nx
imported by: nx_remedy_test.nx
structs
| 104 | struct AnomalyReport |
| 112 | struct DiagnosisReport |
| 118 | struct FixProposal |
| 125 | struct ActionPlan |
| 131 | struct CycleOutcome |
consts
| 41 | const NX_MAGIC_950000000: i64 = 950000000 |
| 42 | const NX_MAGIC_900000000: i64 = 900000000 |
| 43 | const NX_MAGIC_700000000: i64 = 700000000 |
| 44 | const NX_MAGIC_800000000: i64 = 800000000 |
| 45 | const NX_MAGIC_500000000: i64 = 500000000 |
| 46 | const NX_MAGIC_990000000: i64 = 990000000 |
| 47 | const NX_MAGIC_600000000: i64 = 600000000 |
| 48 | const NX_MAGIC_850000000: i64 = 850000000 |
| 49 | const NX_MAGIC_750000000: i64 = 750000000 |
| 53 | const NX_ANOMALY_NONE: i64 = 0 |
| 54 | const NX_ANOMALY_TOLERANCE_EXCEEDED: i64 = 1 |
| 55 | const NX_ANOMALY_REGRESSION: i64 = 2 |
| 56 | const NX_ANOMALY_STATISTICAL_OUTLIER: i64 = 3 |
| 57 | const NX_ANOMALY_TIER_OVERFLOW: i64 = 4 |
| 58 | const NX_ANOMALY_TIER_UNDERFLOW: i64 = 5 |
| 59 | const NX_ANOMALY_CALIBRATION_MISMATCH: i64 = 6 |
| 61 | const NX_RC_NUMERIC_OVERFLOW: i64 = 1 |
| 62 | const NX_RC_NUMERIC_UNDERFLOW: i64 = 2 |
| 63 | const NX_RC_PRECISION_LOSS: i64 = 3 |
| 64 | const NX_RC_HASH_QUALITY_BIAS: i64 = 4 |
| 65 | const NX_RC_SAMPLE_DENSITY_TOO_LOW: i64 = 5 |
| 66 | const NX_RC_SAMPLE_VARIANCE_TOO_HIGH: i64 = 6 |
| 67 | const NX_RC_SIGN_HANDLING_ERROR: i64 = 7 |
| 68 | const NX_RC_OFF_BY_ONE: i64 = 8 |
| 69 | const NX_RC_ALGORITHM_ASYMPTOTIC: i64 = 9 |
| 70 | const NX_RC_DOMAIN_VIOLATED: i64 = 10 |
| 71 | const NX_RC_ESTIMATOR_MISMATCH: i64 = 11 |
| 72 | const NX_RC_SYSTEMIC_HW_LIMIT: i64 = 12 |
| 73 | const NX_RC_RACE_OR_ORDERING: i64 = 13 |
| 74 | const NX_RC_STALE_CALIBRATION: i64 = 14 |
| 76 | const NX_FX_ESCALATE_TIER: i64 = 1 |
| 77 | const NX_FX_SWAP_ALGORITHM: i64 = 2 |
| 78 | const NX_FX_DENSER_SAMPLING: i64 = 3 |
| 79 | const NX_FX_MORE_SEEDS_PER_SAMPLE: i64 = 4 |
| 80 | const NX_FX_SWAP_HASH_FAMILY: i64 = 5 |
| 81 | const NX_FX_REFORMULATE_MATH: i64 = 6 |
| 82 | const NX_FX_FIX_SIGN_HANDLING: i64 = 7 |
| 83 | const NX_FX_DEFEND_DOMAIN: i64 = 8 |
| 84 | const NX_FX_UPGRADE_Q_SCALE: i64 = 9 |
| 85 | const NX_FX_UNLOCK_TIER_ADAPTER: i64 = 10 |
| 86 | const NX_FX_RECALIBRATE_TABLE: i64 = 11 |
| 87 | const NX_FX_TIGHTEN_SYNC: i64 = 12 |
| 88 | const NX_FX_ENSEMBLE: i64 = 13 |
| 90 | const NX_APPLY_WORKED: i64 = 0 |
| 91 | const NX_APPLY_NO_CHANGE: i64 = 1 |
| 92 | const NX_APPLY_REGRESSION: i64 = 2 |
| 94 | const NX_GEN_PASSES: i64 = 0 |
| 95 | const NX_GEN_FAILS_AT_CELL: i64 = 1 |
| 97 | const NX_CYCLE_ADOPT: i64 = 0 |
| 98 | const NX_CYCLE_REJECT_FAILED_AB: i64 = 1 |
| 99 | const NX_CYCLE_REJECT_FAILED_GEN: i64 = 2 |
| 100 | const NX_CYCLE_NO_ACTION_NEEDED: i64 = 3 |
| 282 | const NX_FIX_PROPOSAL_BYTES: i64 = 32 |
functions
| 141 | func nx_anomaly_alloc() -> *AnomalyReport |
| 152 | func nx_diag_report_alloc() -> *DiagnosisReport |
| 161 | func nx_plan_alloc() -> *ActionPlan |
| 170 | func nx_cycle_outcome_alloc() -> *CycleOutcome |
| 188 | func nx_remedy_detect(observed: i64, baseline: i64, tolerance_ppb: i64, |
| 235 | func nx_remedy_diagnose(anomaly: *AnomalyReport, comparison_verdict: i64, |
| 284 | func nx_remedy_fp_at(arr: *FixProposal, i: i64) -> *FixProposal |
| 288 | func nx_remedy_fp_set(arr: *FixProposal, i: i64, |
| 298 | func nx_remedy_propose(rc_code: i64, out: *FixProposal, max_n: i64) -> i64 |
| 356 | func nx_remedy_apply_plan(top: *FixProposal, plan: *ActionPlan) -> i64 |
| 377 | func nx_remedy_ab_verify(before: *EstimatorDiag, after: *EstimatorDiag, |
| 401 | func nx_remedy_generalize(befores: **EstimatorDiag, afters: **EstimatorDiag, |
| 424 | func rl_putc(fd: i64, c: i64) -> i64 called by 1: rl_i64 |
| 431 | func rl_str(fd: i64, s: *u8, len: i64) -> i64 called by 1: nx_remedy_record |
| 436 | func rl_i64(fd: i64, n: i64) -> i64 |
| 460 | func nx_remedy_record(fd: i64, cycle_id: i64, anomaly: *AnomalyReport, |
| 504 | func nx_remedy_cycle_run( |