astrid-runtime/astrid · warning

stability quantiles select duplicate boundary neighborhoods

Error message

stability quantiles select duplicate boundary neighborhoods

What it means

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.

Source

Thrown at crates/astrid-storage-chunker-evidence/src/stability.rs:164

    let mut previous_index = None;
    for quantile in quantiles_basis_points {
        if *quantile == 0 || *quantile >= 10_000 {
            bail!("stability quantiles must lie strictly between zero and 10,000");
        }
        let index = usize::try_from(
            u64::try_from(interior.len())?
                .checked_mul(u64::from(*quantile))
                .and_then(|value| value.checked_div(10_000))
                .ok_or_else(|| anyhow::anyhow!("stability quantile overflow"))?,
        )?
        .min(
            interior
                .len()
                .checked_sub(1)
                .expect("the empty interior returned above"),
        );
        if previous_index == Some(index) {
            bail!("stability quantiles select duplicate boundary neighborhoods");
        }
        previous_index = Some(index);
        sampled.push((*quantile, interior[index].end));
    }
    Ok(sampled)
}

fn collect(candidate: &Candidate, bytes: &[u8]) -> Result<Vec<Chunk>> {
    let mut chunks = Vec::new();
    let mut offset = 0_usize;
    candidate.visit_boundary_chunks(Cursor::new(bytes), |chunk| {
        let start = offset;
        offset = offset
            .checked_add(chunk.len())
            .ok_or_else(|| anyhow::anyhow!("chunk offset overflow"))?;
        chunks.push(Chunk {
            start,
            end: offset,

View on GitHub (pinned to affd8760f4)

Solutions

  1. Deduplicate and widen the quantile spacing in the configuration (e.g. 1250, 2500, 5000, 7500).
  2. Ensure the fixture is large enough that adjacent quantiles map to distinct interior indices.
  3. Pre-filter quantiles by computed index (drop any whose index equals the previous one) before calling.
  4. Check the config file for copy-pasted duplicate quantile entries.

Example fix

// before
let quantiles: &[u16] = &[5000, 5001, 5002];
// after
let quantiles: &[u16] = &[2500, 5000, 7500];
Defensive patterns

Strategy: validation

Validate before calling

fn dedupe_quantile_indices(interior_len: usize, quantiles: &[u16]) -> Vec<u16> {
    let mut last: Option<usize> = None;
    let mut kept = Vec::new();
    for &q in quantiles {
        let idx = interior_len * q as usize / 10_000;
        if last != Some(idx) {
            kept.push(q);
            last = Some(idx);
        }
    }
    kept
}

Try / catch

let quantiles = dedupe_quantile_indices(interior_len, &configured_quantiles);
match measure_fixture(&fixture, &quantiles) {
    Err(e) if e.to_string().contains("duplicate boundary neighborhoods") => {
        eprintln!("quantiles too dense for this fixture; widen spacing");
    },
    r => r?,
}

Prevention

When it happens

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

Common situations: Fine-grained quantile sets applied to small fixtures; duplicated entries in a quantile config; quantiles listed out of order after sorting dedupe was skipped.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09). Data as JSON: /api/errors/8d2eecb387914550. Report an issue: GitHub.