{"record":{"id":"892a133af4e458af","repo":"astrid-runtime/astrid","slug":"a-representation-record-must-cover-at-least-one-lo","errorCode":null,"errorMessage":"a representation record must cover at least one logical chunk","messagePattern":"a representation record must cover at least one logical chunk","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage-chunker-evidence/src/metrics.rs","lineNumber":94,"sourceCode":"                if *entry.get() != length {\n                    bail!(\"BLAKE3 evidence collision with inconsistent file lengths\");\n                }\n            },\n        }\n        Ok(())\n    }\n\n    pub fn add_whole_record(&mut self, bytes: &[u8]) -> Result<()> {\n        self.add_record(bytes, 1, false)\n    }\n\n    pub fn add_chunk_record(&mut self, bytes: &[u8], logical_chunks: u64) -> Result<()> {\n        self.add_record(bytes, logical_chunks, true)\n    }\n\n    fn add_record(&mut self, bytes: &[u8], logical_chunks: u64, cdc: bool) -> Result<()> {\n        if logical_chunks == 0 {\n            bail!(\"a representation record must cover at least one logical chunk\");\n        }\n        let length = u64::try_from(bytes.len())?;\n        self.total_chunks = checked_add(self.total_chunks, logical_chunks, \"chunk count\")?;\n        self.representation_records = checked_add(\n            self.representation_records,\n            1,\n            \"representation record count\",\n        )?;\n        self.chunk_lengths.push((length, logical_chunks));\n        if cdc {\n            self.cdc_chunk_lengths.push((length, logical_chunks));\n        }\n        insert_identity(&mut self.chunks, bytes, &mut self.unique_chunk_bytes)\n    }\n\n    pub fn finish(mut self, elapsed: Duration) -> Result<Measurements> {\n        self.chunk_lengths.sort_unstable();\n        self.cdc_chunk_lengths.sort_unstable();","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/metrics.rs#L76-L112","documentation":"add_record (backing add_whole_record and add_chunk_record) rejects representation records that claim to cover zero logical chunks. Chunk-count accounting assumes every recorded representation contributes at least one chunk, otherwise totals and ratios would be meaningless.","triggerScenarios":"Calling add_chunk_record(bytes, 0) or add_whole_record(bytes, 0) — e.g. when upstream chunk counting returned an empty iterator or a counter was never incremented.","commonSituations":"Processing an empty file and passing 0 chunks instead of skipping the record; a bug in a custom chunker producing no chunks; miswired counters in calling code.","solutions":["Ensure the caller only records representations that produced >= 1 logical chunk.","Skip or special-case empty inputs before calling add_*_record.","Fix the upstream chunker so it emits at least one chunk for non-empty input."],"exampleFix":"// before\nmetrics.add_chunk_record(bytes, chunks.len() as u64);\n// after\nif !chunks.is_empty() {\n    metrics.add_chunk_record(bytes, chunks.len() as u64);\n}","handlingStrategy":"validation","validationCode":"if logical_chunks == 0 { skip_record(); } else { metrics.add_chunk_record(bytes, logical_chunks)?; }","typeGuard":null,"tryCatchPattern":"match metrics.add_chunk_record(bytes, n) {\n    Err(e) if e.to_string().contains(\"at least one logical chunk\") => eprintln!(\"empty representation skipped\"),\n    Err(e) => return Err(e),\n    Ok(()) => {},\n}","preventionTips":["Skip empty inputs before recording","Assert chunkers emit >=1 chunk for non-empty input","Test custom chunkers against empty and single-byte files"],"tags":["validation","metrics","chunking"],"backgroundTag":"invalid-argument-value","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}