Hmbown/CodeWhale · error · PersistenceBacklogError

receipt source_dirty must be boolean

Error message

receipt source_dirty must be boolean

What it means

`receipt.source_dirty` must be a JSON boolean (`type(...) is bool`). This field records whether the git working tree had uncommitted changes when the measurement ran, and it is used both for provenance matching and for the clean-tree requirement (`require_clean_source`). Strings like "false", integers 0/1, or null are all rejected because they would break strict provenance comparison.

Solutions

  1. Change the field to a JSON boolean: `"source_dirty": false` (or true)
  2. Recompute it with `git status --porcelain` and store `bool(output.strip())`
  3. Regenerate the receipt via the measurement script rather than editing by hand

Example fix

// before
"source_dirty": "false"
// after
"source_dirty": false
Defensive patterns

Strategy: type-guard

Validate before calling

assert type(receipt.get("source_dirty")) is bool, repr(receipt.get("source_dirty"))

Type guard

def is_strict_bool(v):
    return type(v) is bool  # rejects 0/1 and "false"

Try / catch

try:
    validate_receipt(receipt)
except PersistenceBacklogError as e:
    if "source_dirty must be boolean" in str(e):
        receipt["source_dirty"] = bool(receipt["source_dirty"]) in (True, False) and receipt["source_dirty"] is not None

Prevention

When it happens

Trigger: A hand-edited receipt sets `"source_dirty": "false"` or `0`; a JSON producer serializes a Python truthy value without casting to bool; the field is null.

Common situations: Manually authoring receipts and typing the value as a string; an older generator emitting 0/1 from a shell exit code; editing JSON in a templating language where booleans render as strings.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/e8ac6c5a5fdebbd3. Report an issue: GitHub.

Appendix: source

Thrown at scripts/check-persistence-backlog-budget.py:158

    require_clean_source: bool = False,
) -> None:
    missing = [field for field in REQUIRED_RECEIPT_FIELDS if field not in receipt]
    if missing:
        raise PersistenceBacklogError(
            "receipt missing required field(s): " + ", ".join(missing)
        )
    if receipt["document_kind"] != RECEIPT_KIND:
        raise PersistenceBacklogError(f"receipt document_kind must be {RECEIPT_KIND}")
    if receipt["schema_version"] != SCHEMA_VERSION:
        raise PersistenceBacklogError("receipt schema_version changed")
    for field, expected in FIXTURE.items():
        validate_frozen_field(field, receipt[field], expected)
    if not isinstance(receipt["source_sha"], str) or not SOURCE_SHA_PATTERN.fullmatch(
        receipt["source_sha"]
    ):
        raise PersistenceBacklogError("receipt source_sha must be an exact lowercase Git SHA")
    if type(receipt["source_dirty"]) is not bool:
        raise PersistenceBacklogError("receipt source_dirty must be boolean")
    for field, prefix in (("rustc_version", "rustc "), ("cargo_version", "cargo ")):
        if not isinstance(receipt[field], str) or not receipt[field].startswith(prefix):
            raise PersistenceBacklogError(f"receipt {field} must be a version string")
    validate_frozen_field("build_profile", receipt["build_profile"], "test")
    validate_frozen_field("sample_count", receipt["sample_count"], 1)
    if expected_source is not None:
        for field in (
            "source_sha",
            "source_dirty",
            "rustc_version",
            "cargo_version",
            "build_profile",
            "sample_count",
        ):
            if receipt[field] != expected_source[field]:
                raise PersistenceBacklogError(
                    f"receipt {field} does not match the checked source"
                )

View on GitHub (pinned to 433685b202)