{"record":{"id":"8d2eecb387914550","repo":"astrid-runtime/astrid","slug":"stability-quantiles-select-duplicate-boundary-neig","errorCode":null,"errorMessage":"stability quantiles select duplicate boundary neighborhoods","messagePattern":"stability quantiles select duplicate boundary neighborhoods","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/astrid-storage-chunker-evidence/src/stability.rs","lineNumber":164,"sourceCode":"    let mut previous_index = None;\n    for quantile in quantiles_basis_points {\n        if *quantile == 0 || *quantile >= 10_000 {\n            bail!(\"stability quantiles must lie strictly between zero and 10,000\");\n        }\n        let index = usize::try_from(\n            u64::try_from(interior.len())?\n                .checked_mul(u64::from(*quantile))\n                .and_then(|value| value.checked_div(10_000))\n                .ok_or_else(|| anyhow::anyhow!(\"stability quantile overflow\"))?,\n        )?\n        .min(\n            interior\n                .len()\n                .checked_sub(1)\n                .expect(\"the empty interior returned above\"),\n        );\n        if previous_index == Some(index) {\n            bail!(\"stability quantiles select duplicate boundary neighborhoods\");\n        }\n        previous_index = Some(index);\n        sampled.push((*quantile, interior[index].end));\n    }\n    Ok(sampled)\n}\n\nfn collect(candidate: &Candidate, bytes: &[u8]) -> Result<Vec<Chunk>> {\n    let mut chunks = Vec::new();\n    let mut offset = 0_usize;\n    candidate.visit_boundary_chunks(Cursor::new(bytes), |chunk| {\n        let start = offset;\n        offset = offset\n            .checked_add(chunk.len())\n            .ok_or_else(|| anyhow::anyhow!(\"chunk offset overflow\"))?;\n        chunks.push(Chunk {\n            start,\n            end: offset,","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/stability.rs#L146-L182","documentation":"As `sampled_boundaries` walks quantiles in order, it computes each quantile's boundary index in the interior and requires each to differ from the previous one. Two quantiles resolving to the same index would sample the identical boundary neighborhood twice, yielding redundant measurements, so the function bails instead.","triggerScenarios":"Calling `measure_fixture` with quantiles that are close enough (or on a small interior) that floor(interior_len * q / 10000) repeats — e.g. quantiles [5000, 5001] on a very short interior, or duplicate quantile values in the list.","commonSituations":"Fine-grained quantile sets applied to small fixtures; duplicated entries in a quantile config; quantiles listed out of order after sorting dedupe was skipped.","solutions":["Deduplicate and widen the quantile spacing in the configuration (e.g. 1250, 2500, 5000, 7500).","Ensure the fixture is large enough that adjacent quantiles map to distinct interior indices.","Pre-filter quantiles by computed index (drop any whose index equals the previous one) before calling.","Check the config file for copy-pasted duplicate quantile entries."],"exampleFix":"// before\nlet quantiles: &[u16] = &[5000, 5001, 5002];\n// after\nlet quantiles: &[u16] = &[2500, 5000, 7500];","handlingStrategy":"validation","validationCode":"fn dedupe_quantile_indices(interior_len: usize, quantiles: &[u16]) -> Vec<u16> {\n    let mut last: Option<usize> = None;\n    let mut kept = Vec::new();\n    for &q in quantiles {\n        let idx = interior_len * q as usize / 10_000;\n        if last != Some(idx) {\n            kept.push(q);\n            last = Some(idx);\n        }\n    }\n    kept\n}","typeGuard":null,"tryCatchPattern":"let quantiles = dedupe_quantile_indices(interior_len, &configured_quantiles);\nmatch measure_fixture(&fixture, &quantiles) {\n    Err(e) if e.to_string().contains(\"duplicate boundary neighborhoods\") => {\n        eprintln!(\"quantiles too dense for this fixture; widen spacing\");\n    },\n    r => r?,\n}","preventionTips":["Deduplicate quantiles and pre-compute their interior indices before measuring.","Scale quantile spacing with fixture size (fewer quantiles for small fixtures).","Sort and dedupe configured quantile lists at load time."],"tags":["rust","chunker","config","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}