astrid-runtime/astrid · warning

corpus input changed during throughput measurement: expected

Error message

corpus input changed during throughput measurement: expected {} bytes, read {observed_bytes}

What it means

During throughput measurement, the corpus input is read repeatedly and each pass checks that the number of bytes read matches the input's declared `logical_bytes()`. A mismatch means the underlying file (or in-memory buffer) changed while being benchmarked, so the measurement is invalid and the crate bails.

Solutions

  1. Identify and stop whatever is modifying the corpus file during the benchmark (editors, log writers, sync daemons).
  2. Copy the corpus to a stable, private location before measuring and benchmark the copy.
  3. Use fixed in-memory corpora instead of live files for throughput tests.
  4. Re-run the measurement after ensuring the file is static; `input.validate_current_file()` results can help pinpoint the change.
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure the corpus file is stable before benchmarking
let before = std::fs::metadata(&path)?.len();
std::thread::sleep(std::time::Duration::from_millis(100));
assert_eq!(std::fs::metadata(&path)?.len(), before, "file is being modified; use a snapshot copy");

Try / catch

match measure_throughput(&mut input, /* ... */) {
    Err(e) if e.to_string().contains("changed during throughput measurement") => {
        log::warn!("input mutated mid-benchmark; re-running on a frozen copy");
        // copy input to a temp snapshot and retry
    }
    other => other,
}

Prevention

When it happens

Trigger: `measure_throughput` (called from `measure_throughput_samples`) reads a corpus input and `observed_bytes != input.logical_bytes()` — the source data was appended to, truncated, or rewritten during the timed loop.

Common situations: Another process (editor, build step, log rotation, sync tool) modifying the corpus file mid-benchmark; the caller mutating shared in-memory inputs between samples; running benchmarks against a live/logged file path.

Related errors


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

Appendix: source

Thrown at crates/astrid-storage-chunker-evidence/src/corpus.rs:297

                        input.logical_bytes(),
                        candidate,
                        hash_records,
                        &mut guard,
                    )?
                },
                Input::Memory(bytes) => measure_reader(
                    Cursor::new(bytes.as_ref()),
                    input.logical_bytes(),
                    candidate,
                    hash_records,
                    &mut guard,
                )?,
            };
            elapsed = elapsed
                .checked_add(started.elapsed())
                .ok_or_else(|| anyhow::anyhow!("corpus throughput duration overflow"))?;
            if observed_bytes != input.logical_bytes() {
                bail!(
                    "corpus input changed during throughput measurement: expected {} bytes, read {observed_bytes}",
                    input.logical_bytes()
                );
            }
            input.validate_current_file()?;
        }
        black_box(guard);
        Ok(elapsed)
    }

    fn logical_bytes(&self) -> Result<u64> {
        self.inputs.iter().try_fold(0_u64, |total, input| {
            total
                .checked_add(input.logical_bytes())
                .ok_or_else(|| anyhow::anyhow!("corpus logical byte count overflow"))
        })
    }

View on GitHub (pinned to affd8760f4)