{"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":"anyhow::Error","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/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/store.rs#L5398-L5434","documentation":"activate_initial_harness is one-shot: it requires that no row exists in active_harness_config for slot 'default'. A second initial activation is refused — subsequent harness changes must go through the promotion path, not re-initialization.","triggerScenarios":"Calling activate_initial_harness when SELECT candidate_id FROM active_harness_config WHERE slot='default' already returns a row.","commonSituations":"Re-running setup/bootstrap on an already-initialized store; calling activate twice in a test without resetting the DB; a deployment script that re-runs initialization idempotently.","solutions":["Use promote_harness (the compare-and-swap path) for any change after the first activation.","If you genuinely need to re-initialize, drop the active_harness_config 'default' row first as an explicit, audited reset.","Guard activation behind an 'is this the first activation?' check that queries active_harness_config."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn has_active_harness(conn: &rusqlite::Connection) -> Result<bool> {\n    let row: Option<String> = conn.query_row(\n        \"SELECT candidate_id FROM active_harness_config WHERE slot = 'default'\",\n        [], |r| r.get(0)).optional()?;\n    Ok(row.is_some())\n}\n\nif has_active_harness(&conn)? {\n    // do not call activate_initial_harness; use promote_harness instead\n    return Err(anyhow::anyhow!(\"harness already active; use promote path\"));\n}","typeGuard":"fn initial_activation_allowed(conn: &rusqlite::Connection) -> bool {\n    !has_active_harness(conn).unwrap_or(true)\n}","tryCatchPattern":"match store.activate_initial_harness(&candidate_id, &evidence_ref) {\n    Ok(()) => { /* first activation done */ }\n    Err(e) if e.to_string().contains(\"active harness configuration already exists\") => {\n        // switch to the promotion flow instead of re-initializing\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat activate_initial_harness as bootstrap-only; gate it behind a setup phase that runs once.","In tests, reset active_harness_config between cases so activation is reproducible.","Make deployment scripts idempotent by checking for an active config before calling activate."],"tags":["rust","sqlite","harness","state-machine"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}