{"record":{"id":"b3ea3b57a6c1f5a9","repo":"affaan-m/ECC","slug":"harness-health-evidence-is-inconsistent-with-audit","errorCode":null,"errorMessage":"harness health evidence is inconsistent with audit outcome","messagePattern":"harness health evidence is inconsistent with audit outcome","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":5618,"sourceCode":"        }\n        let snapshot: HealthEvidenceSnapshot = serde_json::from_str(json)?;\n        let snapshot_candidate_id =\n            Self::resolve_harness_candidate_id(&self.conn, &snapshot.candidate_id)?;\n        if snapshot.canonical_json()? != *json\n            || snapshot.digest()? != *digest\n            || snapshot.asserted_healthy != asserted\n            || snapshot_candidate_id != entry.candidate_id\n        {\n            anyhow::bail!(\"harness health evidence integrity verification failed\");\n        }\n        let event_consistent = match entry.event_type.as_str() {\n            \"promoted\" => status == \"healthy\" && asserted,\n            \"promotion_rolled_back\" => status == \"unhealthy\" && !asserted,\n            \"health_check_error_rolled_back\" => status == \"error\",\n            _ => false,\n        };\n        if !event_consistent {\n            anyhow::bail!(\"harness health evidence is inconsistent with audit outcome\");\n        }\n        if let Some(evaluation_id) = entry.evaluation_id {\n            let evaluation: (Option<String>, Option<String>, Option<bool>, Option<String>, bool) = self.conn.query_row(\n                \"SELECT health_evidence_json, health_evidence_sha256, asserted_health, health_check_status, legacy_unverifiable FROM harness_evaluations WHERE id = ?1\",\n                [evaluation_id],\n                |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?)),\n            )?;\n            if evaluation\n                != (\n                    Some(json.clone()),\n                    Some(digest.clone()),\n                    Some(asserted),\n                    Some(status.clone()),\n                    false,\n                )\n            {\n                anyhow::bail!(\"audit health evidence does not match its evaluation\");\n            }","sourceCodeStart":5600,"sourceCodeEnd":5636,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/store.rs#L5600-L5636","documentation":"After integrity verification passes, the store checks the audit event_type is internally consistent with status and asserted: 'promoted' requires status=='healthy' && asserted true; 'promotion_rolled_back' requires status=='unhealthy' && asserted false; 'health_check_error_rolled_back' requires status=='error'. Any other combination is a state-machine violation.","triggerScenarios":"An audit row whose (event_type, health_check_status, asserted_health) triple is impossible per the promotion state machine, e.g. event_type='promoted' with status='unhealthy'.","commonSituations":"A write path selected the wrong event_type for the outcome; a manual row edit changed one field; a bug in the event_type match expression that produced inconsistent values.","solutions":["Re-derive the correct event_type from the actual outcome (healthy/unhealthy/error) and rewrite the row.","Centralize event_type + status + asserted computation in one place so they cannot drift apart.","Add a CHECK constraint encoding the state machine so the DB rejects inconsistent rows at write time."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn event_type_consistent(event_type: &str, status: &str, asserted: bool) -> bool {\n    match event_type {\n        \"promoted\" => status == \"healthy\" && asserted,\n        \"promotion_rolled_back\" => status == \"unhealthy\" && !asserted,\n        \"health_check_error_rolled_back\" => status == \"error\",\n        _ => false,\n    }\n}\n\nif !event_type_consistent(&entry.event_type, &entry.health_check_status, entry.asserted_health.unwrap_or(false)) {\n    return Err(anyhow::anyhow!(\"audit event_type/status/asserted inconsistent\"));\n}","typeGuard":"fn audit_outcome_is_consistent(event_type: &str, status: &str, asserted: bool) -> bool {\n    event_type_consistent(event_type, status, asserted)\n}","tryCatchPattern":"match verify_audit_entry(&store, &entry) {\n    Ok(()) => { /* ok */ }\n    Err(e) if e.to_string().contains(\"inconsistent with audit outcome\") => {\n        // re-derive the correct event_type from status/asserted and rewrite the row\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Compute event_type, status, and asserted in one place from the single health_result value.","Encode the state machine as a CHECK constraint on harness_eval_audit.","Never manually edit one of the three fields without updating the others."],"tags":["rust","sqlite","harness","audit","state-machine"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}