affaan-m/ECC · error · anyhow::Error

candidate alias integrity verification failed

Error message

candidate alias integrity verification failed

What it means

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.

Solutions

  1. Delete/recreate the database or run schema migrations from scratch so init_schema rebuilds alias rows cleanly
  2. Check for prior failed migrations or schema mismatch and repair the schema
  3. Inspect the alias insert and verification query for mismatched keys/columns; fix the invariant bug if present
  4. Verify the SQLite file integrity (PRAGMA integrity_check) and restore from backup if corrupt

Example fix

// before (opaque failure)
anyhow::bail!("candidate alias integrity verification failed");
// after (diagnostic context)
anyhow::bail!(
    "candidate alias integrity verification failed: alias_id={alias_id} not readable after insert (rows={inserted})"
);
Defensive patterns

Strategy: try-catch

Validate before calling

conn.execute_batch("PRAGMA integrity_check;")?;
// also verify schema version matches before init_schema
let version: i64 = conn.query_row("PRAGMA user_version", [], |r| r.get(0))?;

Try / catch

match ensure_schema(&conn) {
    Err(e) if e.to_string().contains("candidate alias integrity verification failed") => {
        eprintln!("alias table inconsistent; rebuilding database or re-running migrations recommended");
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/f08870255df7c3c5. Report an issue: GitHub.

Appendix: source

Thrown at ecc2/src/session/store.rs:985

            let target = CandidateSpec {
                id: target_id.clone(),
                canonical_config,
                trace_refs: serde_json::from_str(&trace_json)?,
                evidence_refs: serde_json::from_str(&evidence_json)?,
            };
            if version != 2
                || target_id != target.legacy_id()
                || alias_id != target.id_for_v2()?
                || tx
                    .query_row(
                        "SELECT 1 FROM harness_candidates WHERE id = ?1",
                        [&alias_id],
                        |_| Ok(()),
                    )
                    .optional()?
                    .is_some()
            {
                anyhow::bail!("candidate alias integrity verification failed");
            }
        }
        tx.commit()?;
        Ok(())
    }

    fn ensure_session_board_columns(&self) -> Result<()> {
        if !self.has_column("session_board", "row_label")? {
            self.conn
                .execute("ALTER TABLE session_board ADD COLUMN row_label TEXT", [])
                .context("Failed to add row_label column to session_board table")?;
        }

        if !self.has_column("session_board", "previous_lane")? {
            self.conn
                .execute(
                    "ALTER TABLE session_board ADD COLUMN previous_lane TEXT",
                    [],

View on GitHub (pinned to 8321021c54)