{"record":{"id":"5b0f8a383f91ea59","repo":"astrid-runtime/astrid","slug":"a-corpus-produced-no-chunks","errorCode":null,"errorMessage":"a corpus produced no chunks","messagePattern":"a corpus produced no chunks","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-storage-chunker-evidence/src/metrics.rs","lineNumber":212,"sourceCode":"}\n\n/// Returns the ratio in basis points, rounded down.\n///\n/// Retained and saved ratios are deliberately calculated independently with\n/// this same rule. Deriving one as the complement of the other would round one\n/// side up whenever the exact ratio is fractional.\nfn basis_points(part: u64, total: u64) -> Result<u64> {\n    if total == 0 {\n        return Ok(0);\n    }\n    part.checked_mul(BASIS_POINTS)\n        .and_then(|value| value.checked_div(total))\n        .ok_or_else(|| anyhow::anyhow!(\"dedup ratio overflow\"))\n}\n\nfn distribution(sorted: &[(u64, u64)]) -> Result<ChunkSizeDistributionBytes> {\n    if sorted.is_empty() {\n        bail!(\"a corpus produced no chunks\");\n    }\n    let count = weighted_count(sorted)?;\n    let sum = sorted.iter().try_fold(0_u64, |sum, (length, weight)| {\n        let weighted = length\n            .checked_mul(*weight)\n            .ok_or_else(|| anyhow::anyhow!(\"weighted chunk length overflow\"))?;\n        checked_add(sum, weighted, \"chunk-length sum\")\n    })?;\n    let mean = sum\n        .checked_div(count)\n        .ok_or_else(|| anyhow::anyhow!(\"chunk distribution is empty\"))?;\n    Ok(ChunkSizeDistributionBytes {\n        mean,\n        minimum: sorted[0].0,\n        p50: percentile(sorted, 50)?,\n        p95: percentile(sorted, 95)?,\n        p99: percentile(sorted, 99)?,\n        maximum: sorted","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/metrics.rs#L194-L230","documentation":"distribution computes chunk-size statistics and requires at least one (length, weight) pair; an empty distribution means the corpus produced no chunks at all, so percentiles and averages are undefined and the library bails.","triggerScenarios":"optional_distribution invoked on a corpus where no chunks were ever recorded — empty inputs only, or all add_record calls skipped/failed before the summary was built.","commonSituations":"Running the evidence tool against an empty directory; a filter that excluded every input; a chunker that emitted nothing for all inputs.","solutions":["Point the tool at a corpus containing at least one non-empty file.","Ensure chunking actually ran and records were added before requesting the distribution.","Handle the empty-corpus case in the caller and report a meaningful message instead of requesting stats."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if total_chunks() == 0 { return Ok(None); } // skip distribution for empty corpus","typeGuard":null,"tryCatchPattern":"match optional_distribution(&metrics) {\n    Err(e) if e.to_string().contains(\"no chunks\") => eprintln!(\"corpus produced no chunks\"),\n    other => other,\n}","preventionTips":["Verify the corpus contains at least one non-empty input before measuring","Confirm chunking produced records before requesting statistics","Check include/exclude filters do not eliminate all inputs"],"tags":["metrics","empty-input","chunking","validation"],"backgroundTag":"empty-required-field","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"}