{"record":{"id":"3f98651cd92eba64","repo":"astrid-runtime/astrid","slug":"equal-chunk-identities-named-different-bytes-in-de","errorCode":null,"errorMessage":"equal chunk identities named different bytes in delta evidence","messagePattern":"equal chunk identities named different bytes in delta evidence","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/astrid-storage-chunker-evidence/src/sketch.rs","lineNumber":593,"sourceCode":"            (None, None) => break,\n        }\n        sampled = sampled.saturating_add(1);\n    }\n    (shared, sampled)\n}\n\nfn delta_size(base: &Version, target: &Version) -> Result<u64> {\n    let mut by_id = BTreeMap::new();\n    for chunk in &base.chunks {\n        by_id.entry(chunk.id).or_insert(*chunk);\n    }\n    let mut operations = Vec::new();\n    for target_chunk in &target.chunks {\n        if let Some(base_chunk) = by_id.get(&target_chunk.id) {\n            if base.record(base_chunk.id)?.canonical_bytes()\n                != target.record(target_chunk.id)?.canonical_bytes()\n            {\n                bail!(\"equal chunk identities named different bytes in delta evidence\");\n            }\n            push_copy(&mut operations, base_chunk.offset, base_chunk.length)?;\n        } else {\n            push_add(\n                &mut operations,\n                target.record(target_chunk.id)?.canonical_bytes(),\n            )?;\n        }\n    }\n    let encoded = encode_delta(base.file, target.file, target.logical_bytes, &operations)?;\n    let reconstructed = apply_delta(&base.materialize()?, &encoded)?;\n    if reconstructed != target.materialize()? {\n        bail!(\"encoded evidence delta did not reconstruct its target\");\n    }\n    Ok(u64::try_from(encoded.len())?)\n}\n\nfn push_copy(operations: &mut Vec<DeltaOperation>, offset: u64, length: u64) -> Result<()> {","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/sketch.rs#L575-L611","documentation":"When measuring delta size between a base and target version, `delta_size` assumes chunk identity (ObjectId) implies identical canonical bytes — content addressing should guarantee this. If a target chunk shares its ID with a base chunk but `canonical_bytes()` differ, the content-addressing invariant is broken and emitting a Copy operation would silently produce wrong data, so the function bails.","triggerScenarios":"Calling `measure_target`/`delta_size` where a target file contains a chunk whose ObjectId exists in the base version's chunk map, but the two records' canonical_bytes() differ — caused by hash collisions, mis-keyed records, or a store where object IDs were reused for different content.","commonSituations":"Corrupted or hand-assembled object stores; hashing configuration changes (same ID scheme, different byte serialization); evidence stores merged from differently-configured writers.","solutions":["Verify object IDs are true content hashes (recompute the hash of canonical_bytes for the mismatched chunk and re-key the record).","Rebuild the evidence store / re-chunk the affected files so each chunk ID maps to exactly one byte sequence.","Check that base and target records were loaded from the same store with the same serialization configuration.","If intentional dedup-by-ID must be relaxed, compare bytes before emitting Copy and emit Add for mismatches instead of bailing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn verify_chunk_identity(record: &ObjectRecord, id: ObjectId) -> Result<()> {\n    let bytes = record.canonical_bytes();\n    let recomputed = hash_content(bytes);\n    if recomputed != id {\n        bail!(\"chunk id {id:?} does not hash its content ({recomputed:?})\");\n    }\n    Ok(())\n}","typeGuard":"fn chunk_ids_match_bytes(base: &ObjectRecord, target: &ObjectRecord) -> bool {\n    base.canonical_bytes() == target.canonical_bytes()\n}","tryCatchPattern":"match delta_size(&base, &target) {\n    Err(e) if e.to_string().contains(\"named different bytes\") => {\n        eprintln!(\"content-addressing violated: re-hash and re-key the store\");\n    },\n    r => r?,\n}","preventionTips":["Always derive object IDs from a hash of canonical_bytes; never hand-assign IDs.","Periodically re-hash stored chunks to detect ID/content divergence.","Avoid merging evidence stores written with different hashing configurations."],"tags":["rust","storage","content-addressed","hash-mismatch"],"backgroundTag":"checksum-mismatch","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}