{"record":{"id":"1c3201be68b0c1ba","repo":"Hmbown/CodeWhale","slug":"receipt-source-sha-must-be-an-exact-lowercase-git-sha","errorCode":null,"errorMessage":"receipt source_sha must be an exact lowercase Git SHA","messagePattern":"receipt source_sha must be an exact lowercase Git SHA","errorType":"validation","errorClass":"PersistenceBacklogError","httpStatus":null,"severity":"error","filePath":"scripts/check-persistence-backlog-budget.py","lineNumber":156,"sourceCode":"    *,\n    expected_source: dict[str, Any] | None = None,\n    require_clean_source: bool = False,\n) -> None:\n    missing = [field for field in REQUIRED_RECEIPT_FIELDS if field not in receipt]\n    if missing:\n        raise PersistenceBacklogError(\n            \"receipt missing required field(s): \" + \", \".join(missing)\n        )\n    if receipt[\"document_kind\"] != RECEIPT_KIND:\n        raise PersistenceBacklogError(f\"receipt document_kind must be {RECEIPT_KIND}\")\n    if receipt[\"schema_version\"] != SCHEMA_VERSION:\n        raise PersistenceBacklogError(\"receipt schema_version changed\")\n    for field, expected in FIXTURE.items():\n        validate_frozen_field(field, receipt[field], expected)\n    if not isinstance(receipt[\"source_sha\"], str) or not SOURCE_SHA_PATTERN.fullmatch(\n        receipt[\"source_sha\"]\n    ):\n        raise PersistenceBacklogError(\"receipt source_sha must be an exact lowercase Git SHA\")\n    if type(receipt[\"source_dirty\"]) is not bool:\n        raise PersistenceBacklogError(\"receipt source_dirty must be boolean\")\n    for field, prefix in ((\"rustc_version\", \"rustc \"), (\"cargo_version\", \"cargo \")):\n        if not isinstance(receipt[field], str) or not receipt[field].startswith(prefix):\n            raise PersistenceBacklogError(f\"receipt {field} must be a version string\")\n    validate_frozen_field(\"build_profile\", receipt[\"build_profile\"], \"test\")\n    validate_frozen_field(\"sample_count\", receipt[\"sample_count\"], 1)\n    if expected_source is not None:\n        for field in (\n            \"source_sha\",\n            \"source_dirty\",\n            \"rustc_version\",\n            \"cargo_version\",\n            \"build_profile\",\n            \"sample_count\",\n        ):\n            if receipt[field] != expected_source[field]:\n                raise PersistenceBacklogError(","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-persistence-backlog-budget.py#L138-L174","documentation":"`receipt.source_sha` must be a string of exactly 40 lowercase hex characters matching `SOURCE_SHA_PATTERN = re.compile(r\"[0-9a-f]{40}\")` (fullmatch). This is the full Git commit SHA of the source the measurement was taken against, used to tie the receipt to a reproducible provenance. Uppercase hex, abbreviated SHAs (7-12 chars), prefixes like `sha:`, or non-string values are rejected.","triggerScenarios":"Receipt stores a short SHA like `abc1234`; SHA written in uppercase; SHA stored as a number or with a `refs/heads/` prefix; a hand-written receipt with a placeholder value.","commonSituations":"Copying `git rev-parse --short HEAD` output into a hand-authored receipt; pasting a GitHub UI SHA that was displayed abbreviated; a script storing `git log -1 --format=%H` output with trailing newline preserved incorrectly (via fullmatch that also fails on whitespace).","solutions":["Use the full SHA: `git rev-parse HEAD` (not --short) and store the 40-char lowercase result","Normalize the value: `receipt[\"source_sha\"] = receipt[\"source_sha\"].strip().lower()` before validation","Regenerate the receipt with the measurement script, which fills source_sha automatically via `git rev-parse HEAD`"],"exampleFix":"// before\n\"source_sha\": \"9d4A1c\" // short/uppercase\n// after\n\"source_sha\": \"9d4a1c0f...\" // full 40-char lowercase from `git rev-parse HEAD`","handlingStrategy":"validation","validationCode":"import re\nSHA = re.compile(r\"[0-9a-f]{40}\")\nassert isinstance(receipt.get(\"source_sha\"), str) and SHA.fullmatch(receipt[\"source_sha\"])","typeGuard":"def is_full_git_sha(v):\n    return isinstance(v, str) and re.fullmatch(r\"[0-9a-f]{40}\", v) is not None","tryCatchPattern":"try:\n    validate_receipt(receipt)\nexcept PersistenceBacklogError as e:\n    if \"source_sha must be an exact lowercase Git SHA\" in str(e):\n        receipt[\"source_sha\"] = subprocess.check_output([\"git\",\"rev-parse\",\"HEAD\"], text=True).strip()","preventionTips":["Always use `git rev-parse HEAD` (no --short) when recording source SHAs","Lowercase and strip SHAs before storing them","Reject abbreviated SHAs at receipt-generation time"],"tags":["git","validation","format","receipt"],"backgroundTag":"invalid-identifier-format","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}