{"record":{"id":"dc76d9cc2e3d86fc","repo":"affaan-m/ECC","slug":"an-active-harness-configuration-already-exists","errorCode":null,"errorMessage":"an active harness configuration already exists","messagePattern":"an active harness configuration already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":5416,"sourceCode":"\n    pub fn activate_initial_harness(&self, candidate_id: &str, evidence_ref: &str) -> Result<()> {\n        if candidate_id.len() != 64 || evidence_ref.trim().is_empty() || evidence_ref.len() > 4096 {\n            anyhow::bail!(\n                \"valid candidate id and bounded activation evidence reference are required\"\n            );\n        }\n        let tx = self.conn.unchecked_transaction()?;\n        let stored_candidate_id = Self::resolve_harness_candidate_id(&tx, candidate_id)?;\n        if tx\n            .query_row(\n                \"SELECT candidate_id FROM active_harness_config WHERE slot = 'default'\",\n                [],\n                |row| row.get::<_, String>(0),\n            )\n            .optional()?\n            .is_some()\n        {\n            anyhow::bail!(\"an active harness configuration already exists\");\n        }\n        let now = chrono::Utc::now().to_rfc3339();\n        tx.execute(\"INSERT INTO active_harness_config (slot, candidate_id, updated_at) VALUES ('default', ?1, ?2)\", rusqlite::params![stored_candidate_id, now])?;\n        tx.execute(\"INSERT INTO harness_eval_audit (event_type, candidate_id, evidence_ref, legacy_unverifiable, created_at) VALUES ('initial_activation', ?1, ?2, 0, ?3)\", rusqlite::params![stored_candidate_id, evidence_ref, now])?;\n        tx.commit()?;\n        Ok(())\n    }\n\n    #[cfg(test)]\n    pub fn active_harness_id(&self) -> Result<Option<String>> {\n        let stored = self\n            .conn\n            .query_row(\n                \"SELECT candidate_id FROM active_harness_config WHERE slot = 'default'\",\n                [],\n                |row| row.get(0),\n            )\n            .optional()?;","sourceCodeStart":5398,"sourceCodeEnd":5434,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/store.rs#L5398-L5434","documentation":"activate_initial_harness only allows the first activation of a harness configuration. If a row already exists in active_harness_config for slot 'default', the initial activation is refused; subsequent changes must go through the evaluate/promote (compare-and-swap) path rather than the initial-activation path.","triggerScenarios":"Calling activate_initial_harness when the active_harness_config table already contains a row for slot 'default', i.e. a harness was previously activated in this store/database.","commonSituations":"Re-running an initialization script against a database that was already initialized; pointing a new tool run at a shared/migrated SQLite file with existing harness state; trying to reset the active configuration via the initial-activation API instead of the promotion flow.","solutions":["If the goal is to change the active harness, use evaluate_promote_and_health_check (promotion with evidence) instead of activate_initial_harness.","Verify current state by querying active_harness_config WHERE slot = 'default' before attempting initial activation.","If the existing active configuration is invalid and you truly need to re-initialize, clear the active_harness_config row (and audit accordingly) in a deliberate migration, then call activate_initial_harness.","Use a fresh store/database if you intended a brand-new harness lifecycle rather than continuing an existing one."],"exampleFix":"// before: re-initializing an already-activated store\nstore.activate_initial_harness(&candidate_id, &evidence)?; // already active\n\n// after: guard first, promote instead\nif store.active_harness_id()?.is_none() {\n    store.activate_initial_harness(&candidate_id, &evidence)?;\n} else {\n    // change via promotion flow\n    store.evaluate_promote_and_health_check(...)?;\n}","handlingStrategy":"validation","validationCode":"// Only call activate_initial_harness when nothing is active yet\nif store.active_harness_id()?.is_some() {\n    // switch via promotion flow instead\n    return Err(anyhow!(\"harness already active; use promotion flow\"));\n}\nstore.activate_initial_harness(&candidate_id, &evidence_ref)?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check active_harness_config before any initialization run; make init scripts idempotent","Never use initial activation to change configurations — use the evaluate/promote path","Tag/migrate shared databases consciously so old harness state is visible before init"],"tags":["state-machine","database","rust"],"backgroundTag":"invalid-state-transition","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}