Hmbown/CodeWhale · error · PersistenceBacklogMeasurementError

exact library measurement test {TEST_NAME} emitted no valid

Error message

exact library measurement test {TEST_NAME} emitted no valid receipt: {error}

What it means

After the measurement test runs, the script json.loads the receipt at CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH (a temp file it created and exported into the cargo env). OSError (missing/unreadable file) or JSONDecodeError (empty/truncated/corrupt JSON) raises this: the test executed but did not emit a trustworthy receipt. Causes: the test skips writing under some condition, the env-var name changed on one side only, or the write is incomplete when the test process exits.

Source

Thrown at scripts/measure-persistence-backlog.py:70

        text=True,
        capture_output=True,
        check=False,
    )
    sys.stderr.write(result.stderr)
    if result.returncode != 0:
        sys.stdout.write(result.stdout)
        result.check_returncode()

    combined = "\n".join(result.stdout.splitlines() + result.stderr.splitlines())
    if re.search(r"\brunning\s+0\s+tests?\b", combined):
        sys.stdout.write(result.stdout)
        raise PersistenceBacklogMeasurementError(
            f"exact library measurement test {TEST_NAME} ran zero tests"
        )
    try:
        return json.loads(receipt_path.read_text(encoding="utf-8"))
    except (OSError, json.JSONDecodeError) as error:
        raise PersistenceBacklogMeasurementError(
            f"exact library measurement test {TEST_NAME} emitted no valid receipt: {error}"
        ) from error


def main() -> int:
    source_sha = subprocess.run(
        ["git", "rev-parse", "HEAD"],
        cwd=ROOT,
        text=True,
        capture_output=True,
        check=True,
    ).stdout.strip()
    source_dirty = bool(
        subprocess.run(
            ["git", "status", "--porcelain", "--untracked-files=normal"],
            cwd=ROOT,
            text=True,
            capture_output=True,

View on GitHub (pinned to 8880682c63)

Solutions

  1. Make the test unconditionally write complete, valid JSON to the env-var path as its final step (write-temp-then-rename for atomicity)
  2. Keep RECEIPT_ENV ('CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH') identical in scripts/measure-persistence-backlog.py:15 and the Rust test
  3. Reproduce locally: 'CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH=/tmp/r.json cargo test --locked -p codewhale-tui --lib -- --exact --ignored --test-threads=1 <TEST_NAME>' then inspect /tmp/r.json

Example fix

// before (Rust test)
if backlog.is_empty() { return; } // receipt silently skipped
std::fs::write(path, json)?;

// after
let tmp = path.with_extension("tmp");
std::fs::write(&tmp, json)?;
std::fs::rename(&tmp, path)?; // always emit a complete receipt
Defensive patterns

Strategy: try-catch

Validate before calling

import os
from pathlib import Path
# Before running: confirm the env contract the test expects
assert "CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH" in os.environ
assert Path(os.environ["CODEWHALE_TEST_PERSISTENCE_BACKLOG_RECEIPT_PATH"]).parent.is_dir(), "receipt dir missing"

Type guard

def is_backlog_measurement_error(exc: BaseException) -> bool:
    return isinstance(exc, RuntimeError) and type(exc).__name__ == "PersistenceBacklogMeasurementError"

Try / catch

try:
    receipt = run_measurement(receipt_path, env)
except PersistenceBacklogMeasurementError as error:
    sys.stderr.write(f"invalid persistence backlog receipt: {error}\n")
    return 1

Prevention

When it happens

Trigger: The test returns early (cfg/skip logic) without writing the receipt; RECEIPT_ENV renamed in the Rust test or the Python script but not both; the test writes partial JSON then panics; the tempdir is cleaned before the read.

Common situations: Editing the receipt-writing helper; changing env-var names; adding skip conditions to the measurement test.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/8e3b872bf2d98fdb. Report an issue: GitHub.