{"record":{"id":"f08870255df7c3c5","repo":"affaan-m/ECC","slug":"candidate-alias-integrity-verification-failed","errorCode":null,"errorMessage":"candidate alias integrity verification failed","messagePattern":"candidate alias integrity verification failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":985,"sourceCode":"            let target = CandidateSpec {\n                id: target_id.clone(),\n                canonical_config,\n                trace_refs: serde_json::from_str(&trace_json)?,\n                evidence_refs: serde_json::from_str(&evidence_json)?,\n            };\n            if version != 2\n                || target_id != target.legacy_id()\n                || alias_id != target.id_for_v2()?\n                || 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 integrity verification failed\");\n            }\n        }\n        tx.commit()?;\n        Ok(())\n    }\n\n    fn ensure_session_board_columns(&self) -> Result<()> {\n        if !self.has_column(\"session_board\", \"row_label\")? {\n            self.conn\n                .execute(\"ALTER TABLE session_board ADD COLUMN row_label TEXT\", [])\n                .context(\"Failed to add row_label column to session_board table\")?;\n        }\n\n        if !self.has_column(\"session_board\", \"previous_lane\")? {\n            self.conn\n                .execute(\n                    \"ALTER TABLE session_board ADD COLUMN previous_lane TEXT\",\n                    [],","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/store.rs#L967-L1003","documentation":"ensure_harness_candidate_aliases creates alias rows in a SQLite transaction and then verifies each alias is actually retrievable; if a re-read of an alias row by alias_id finds nothing, the invariants of the write have been violated and the transaction aborts with this opaque integrity error. It is an internal consistency check guarding against a silently failed insert or a broken read path.","triggerScenarios":"Running init_schema (which calls ensure_harness_candidate_aliases) when an inserted candidate-alias row cannot be read back by alias_id within the same transaction — e.g., insert silently skipped, wrong column/key used in the verification query, or a trigger/filter excluding the row.","commonSituations":"Database file created by an older schema version conflicting with new alias writes; SQLite file corruption or a failed/partial prior migration; running with a read-only or constrained DB connection where the verification read sees stale data; a bug in the alias insert loop skipping rows.","solutions":["Delete/recreate the database or run schema migrations from scratch so init_schema rebuilds alias rows cleanly","Check for prior failed migrations or schema mismatch and repair the schema","Inspect the alias insert and verification query for mismatched keys/columns; fix the invariant bug if present","Verify the SQLite file integrity (PRAGMA integrity_check) and restore from backup if corrupt"],"exampleFix":"// before (opaque failure)\nanyhow::bail!(\"candidate alias integrity verification failed\");\n// after (diagnostic context)\nanyhow::bail!(\n    \"candidate alias integrity verification failed: alias_id={alias_id} not readable after insert (rows={inserted})\"\n);","handlingStrategy":"try-catch","validationCode":"conn.execute_batch(\"PRAGMA integrity_check;\")?;\n// also verify schema version matches before init_schema\nlet version: i64 = conn.query_row(\"PRAGMA user_version\", [], |r| r.get(0))?;","typeGuard":null,"tryCatchPattern":"match ensure_schema(&conn) {\n    Err(e) if e.to_string().contains(\"candidate alias integrity verification failed\") => {\n        eprintln!(\"alias table inconsistent; rebuilding database or re-running migrations recommended\");\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Run PRAGMA integrity_check and schema-version checks on startup","Back up the SQLite file before schema upgrades","Ensure all alias writes and their verification reads use the same keys/columns and commit atomically"],"tags":["database","sqlite","integrity","schema","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"}