{"record":{"id":"39a2e29c9daecb47","repo":"affaan-m/ECC","slug":"health-check-result-does-not-match-persisted-asser","errorCode":null,"errorMessage":"health check result does not match persisted assertion","messagePattern":"health check result does not match persisted assertion","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":5511,"sourceCode":"        if !comparison.passed {\n            tx.execute(\"INSERT INTO harness_evaluations (candidate_id, baseline_id, evaluator, samples_json, policy_json, comparison_json, evidence_ref, legacy_unverifiable, created_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, 0, ?8)\", rusqlite::params![stored_candidate_id, stored_baseline_id, evaluator, serde_json::to_string(samples)?, serde_json::to_string(&policy)?, serde_json::to_string(&comparison)?, evidence_ref, now])?;\n            let evaluation_id = tx.last_insert_rowid();\n            tx.execute(\"INSERT INTO harness_eval_audit (event_type, candidate_id, prior_candidate_id, evaluation_id, evidence_ref, legacy_unverifiable, created_at) VALUES ('promotion_rejected', ?1, ?2, ?3, ?4, 0, ?5)\", rusqlite::params![stored_candidate_id, stored_baseline_id, evaluation_id, evidence_ref, now])?;\n            tx.commit()?;\n            return Ok(HarnessPromotionOutcome {\n                evaluation_id: Some(evaluation_id),\n                promoted: false,\n                rolled_back: false,\n                failures: comparison.failures,\n            });\n        }\n        let changed = tx.execute(\"UPDATE active_harness_config SET candidate_id = ?1, updated_at = ?2 WHERE slot = 'default' AND candidate_id = ?3\", rusqlite::params![stored_candidate_id, now, stored_baseline_id])?;\n        if changed != 1 {\n            anyhow::bail!(\"atomic promotion compare-and-swap failed\");\n        }\n        let health_result = health_check(candidate_id).and_then(|healthy| {\n            if healthy != health_evidence.asserted_healthy {\n                anyhow::bail!(\"health check result does not match persisted assertion\");\n            }\n            Ok(healthy)\n        });\n        let healthy = matches!(health_result, Ok(true));\n        let event_type = match &health_result {\n            Ok(true) => \"promoted\",\n            Ok(false) => \"promotion_rolled_back\",\n            Err(_) => \"health_check_error_rolled_back\",\n        };\n        let health_check_status = match &health_result {\n            Ok(true) => \"healthy\",\n            Ok(false) => \"unhealthy\",\n            Err(_) => \"error\",\n        };\n        if !healthy {\n            let restored = tx.execute(\"UPDATE active_harness_config SET candidate_id = ?1, updated_at = ?2 WHERE slot = 'default' AND candidate_id = ?3\", rusqlite::params![stored_baseline_id, now, stored_candidate_id])?;\n            if restored != 1 {\n                anyhow::bail!(\"atomic rollback compare-and-swap failed\");","sourceCodeStart":5493,"sourceCodeEnd":5529,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/store.rs#L5493-L5529","documentation":"After the promotion CAS succeeds, promote_harness invokes the caller-supplied health_check closure and requires its bool result to equal health_evidence.asserted_healthy. The persisted assertion must agree with the live probe taken at promotion time.","triggerScenarios":"health_check(candidate_id) returns a bool different from health_evidence.asserted_healthy (e.g. asserted true but the probe returned false, or vice versa).","commonSituations":"The candidate became unhealthy between evidence capture and the live check; the health_check closure is flaky or depends on a service that is down; the assertion was optimistically set to true without a real probe.","solutions":["Re-capture health_evidence immediately before promoting so assertion and live probe observe the same state.","Make the health_check closure deterministic, fast, and free of external flakiness.","If the candidate is genuinely unhealthy, fix the underlying cause before retrying promotion."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Probe health first, then build the assertion from the probe result so they cannot disagree.\nlet live_healthy = run_health_check(&candidate_id)?;\nlet health_evidence = HealthEvidenceSnapshot::for_candidate(&candidate_id, evaluator, live_healthy)?;\nhealth_evidence.verify()?;\n// now promote — health_check closure will re-run and must agree with live_healthy.","typeGuard":"fn assertion_matches_probe(asserted: bool, probe: bool) -> bool {\n    asserted == probe\n}","tryCatchPattern":"match store.promote_harness(&candidate_id, &baseline_id, evaluator, evidence_ref, &health_evidence, |id| run_health_check(id)) {\n    Ok(out) => { /* handled; out.rolled_back indicates a mismatch-driven rollback */ }\n    Err(e) if e.to_string().contains(\"health check result does not match\") => {\n        // candidate flapped between capture and probe; re-capture and retry once stable\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Capture health_evidence and run the promotion probe as close together as possible.","Make the health_check closure deterministic and free of external flakiness.","Never set asserted_healthy=true without a successful live probe."],"tags":["rust","harness","health-evidence","consistency"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}