{"record":{"id":"dc48d457f7ad7e7b","repo":"affaan-m/ECC","slug":"candidate-alias-collision-with-physical-candidate","errorCode":null,"errorMessage":"candidate alias collision with physical candidate id","messagePattern":"candidate alias collision with physical candidate id","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":5307,"sourceCode":"    }\n}\n\nimpl StateStore {\n    fn register_harness_alias(\n        tx: &rusqlite::Transaction<'_>,\n        alias_id: &str,\n        candidate_id: &str,\n    ) -> Result<()> {\n        if tx\n            .query_row(\n                \"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        )?;","sourceCodeStart":5289,"sourceCodeEnd":5325,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/store.rs#L5289-L5325","documentation":"The harness candidate alias registration path refuses to create an alias whose alias_id already exists as a physical candidate id in the candidates table. It checks the physical id space first and bails 'candidate alias collision with physical candidate id' to keep the two id namespaces disjoint — an alias must never shadow a real candidate.","triggerScenarios":"registering an alias (alias_id) that collides with an existing physical harness_candidate row id; auto-generated alias/id sequences overlapping after an import or rename; minting aliases from user-controlled strings that match real ids.","commonSituations":"Migrating candidate data where a legacy alias was later promoted to a physical candidate; tooling generating deterministic aliases that collide with real ids; two import sources producing overlapping identifiers.","solutions":["Generate alias ids in a namespace that can't collide with physical ids (prefix, e.g. 'alias:<uuid>').","Before registering, check that alias_id is absent from the physical candidates table and pick another id on conflict.","Deduplicate/normalize identifiers at import time so legacy aliases can't equal promoted physical ids.","If the collision is intentional migration state, re-key the physical candidate instead of aliasing."],"exampleFix":"// before\nstore.register_candidate_alias(&candidate_id, alias_id)?;\n\n// after\nlet safe_alias = if store.physical_candidate_exists(alias_id) {\n    format!(\"alias:{alias_id}\")\n} else {\n    alias_id.to_string()\n};\nstore.register_candidate_alias(&candidate_id, &safe_alias)?;","handlingStrategy":"validation","validationCode":"if store.physical_candidate_exists(alias_id) {\n    return Err(anyhow::anyhow!(\"refusing alias {alias_id}: collides with physical candidate id\"));\n}\nstore.register_candidate_alias(&candidate_id, alias_id)?;","typeGuard":"fn is_safe_alias(id: &str) -> bool {\n    id.starts_with(\"alias:\") && id.len() > 6\n}","tryCatchPattern":"match store.register_candidate_alias(&cid, alias) {\n    Err(e) if e.to_string().contains(\"candidate alias collision with physical candidate id\") => {\n        retry_with_namespaced_alias()\n    }\n    other => other,\n}","preventionTips":["Namespace aliases (e.g. 'alias:' prefix) so they can never equal physical ids.","Check both id spaces (physical + existing aliases) before registering.","Deduplicate identifiers during imports/migrations."],"tags":["sqlite","aliases","identifier-collision","invariant"],"backgroundTag":"internal-invariant-violation","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"}