{"record":{"id":"bc203556f0449423","repo":"affaan-m/ECC","slug":"candidate-alias-collision-with-different-immutable","errorCode":null,"errorMessage":"candidate alias collision with different immutable target","messagePattern":"candidate alias collision with different immutable target","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":5318,"sourceCode":"                \"SELECT 1 FROM harness_candidates WHERE id = ?1\",\n                [alias_id],\n                |_| Ok(()),\n            )\n            .optional()?\n            .is_some()\n        {\n            anyhow::bail!(\"candidate alias collision with physical candidate id\");\n        }\n        let existing = tx\n            .query_row(\n                \"SELECT candidate_id FROM harness_candidate_aliases WHERE alias_id = ?1\",\n                [alias_id],\n                |row| row.get::<_, String>(0),\n            )\n            .optional()?;\n        if let Some(existing) = existing {\n            if existing != candidate_id {\n                anyhow::bail!(\"candidate alias collision with different immutable target\");\n            }\n            return Ok(());\n        }\n        tx.execute(\n            \"INSERT INTO harness_candidate_aliases (alias_id, candidate_id, id_version, created_at) VALUES (?1, ?2, 2, ?3)\",\n            rusqlite::params![alias_id, candidate_id, chrono::Utc::now().to_rfc3339()],\n        )?;\n        Ok(())\n    }\n\n    fn resolve_harness_candidate_id(connection: &Connection, candidate_id: &str) -> Result<String> {\n        if let Some(target) = connection\n            .query_row(\n                \"SELECT candidate_id FROM harness_candidate_aliases WHERE alias_id = ?1\",\n                [candidate_id],\n                |row| row.get::<_, String>(0),\n            )\n            .optional()?","sourceCodeStart":5300,"sourceCodeEnd":5336,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/store.rs#L5300-L5336","documentation":"Thrown by register_harness_alias when alias_id already exists in harness_candidate_aliases but points to a different candidate_id than the one requested. Aliases are immutable once bound: the same alias cannot be repointed to a new canonical target.","triggerScenarios":"Calling register_harness_alias with an alias_id whose stored candidate_id differs from the passed candidate_id. Idempotent re-registration with the same target returns Ok(()); a different target bails.","commonSituations":"Re-running a migration/registration with content that changed under the same legacy id; two different canonical configs claiming the same legacy id; concurrent registrations racing on the same alias.","solutions":["Reuse the exact candidate_id originally bound to that alias (re-derive it deterministically from content).","If the existing binding is genuinely wrong, run a data migration to delete/rewrite the harness_candidate_aliases row, then re-register.","Make alias assignment a pure function of content so retries are idempotent and never produce a conflicting target."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn existing_alias_target(tx: &rusqlite::Transaction, alias_id: &str) -> Result<Option<String>> {\n    Ok(tx.query_row(\n        \"SELECT candidate_id FROM harness_candidate_aliases WHERE alias_id = ?1\",\n        [alias_id], |row| row.get::<_, String>(0)).optional()?)\n}\n\n// before registering:\nif let Some(prior) = existing_alias_target(&tx, alias_id)? {\n    if prior != candidate_id {\n        return Err(anyhow::anyhow!(\"alias {alias_id} already bound to {prior}; refusing to repoint\"));\n    }\n}","typeGuard":"fn alias_is_compatible(tx: &rusqlite::Transaction, alias_id: &str, candidate_id: &str) -> bool {\n    match existing_alias_target(tx, alias_id) {\n        Ok(Some(prior)) => prior == candidate_id,\n        Ok(None) => true,\n        Err(_) => false,\n    }\n}","tryCatchPattern":"match store.register_harness_alias(&tx, alias_id, candidate_id) {\n    Ok(()) => { /* ok */ }\n    Err(e) if e.to_string().contains(\"different immutable target\") => {\n        // the alias is permanently bound elsewhere; do not retry with a new target,\n        // either accept the prior target or run a data migration.\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Derive candidate_id deterministically from content so re-registration under the same alias always targets the same value.","Treat aliases as write-once in your data model and never attempt to repoint them in normal flows.","If a binding must change, do it via an explicit, logged migration that deletes the old row first."],"tags":["rust","sqlite","harness","alias","immutability"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}