{"record":{"id":"918141c9f12afdca","repo":"Hmbown/CodeWhale","slug":"receipt-field-must-remain-expected-r-got-value-r","errorCode":null,"errorMessage":"receipt {field} must remain {expected!r}, got {value!r}","messagePattern":"receipt (.+?) must remain (.+?), got (.+?)","errorType":"validation","errorClass":"PersistenceBacklogError","httpStatus":null,"severity":"error","filePath":"scripts/check-persistence-backlog-budget.py","lineNumber":104,"sourceCode":"def load_json(path: Path, label: str) -> dict[str, Any]:\n    try:\n        value = json.loads(path.read_text(encoding=\"utf-8\"))\n    except (OSError, json.JSONDecodeError) as error:\n        raise PersistenceBacklogError(f\"invalid {label} {path}: {error}\") from error\n    if not isinstance(value, dict):\n        raise PersistenceBacklogError(f\"{label} must be a JSON object\")\n    return value\n\n\ndef non_negative_integer(value: Any, field: str) -> int:\n    if isinstance(value, bool) or not isinstance(value, int) or value < 0:\n        raise PersistenceBacklogError(f\"{field} must be a non-negative integer\")\n    return value\n\n\ndef validate_frozen_field(field: str, value: Any, expected: Any) -> None:\n    if type(value) is not type(expected) or value != expected:\n        raise PersistenceBacklogError(\n            f\"receipt {field} must remain {expected!r}, got {value!r}\"\n        )\n\n\ndef current_source_identity() -> dict[str, Any]:\n    def run(command: list[str]) -> str:\n        result = subprocess.run(\n            command,\n            cwd=ROOT,\n            text=True,\n            capture_output=True,\n            check=False,\n        )\n        if result.returncode != 0:\n            raise PersistenceBacklogError(\n                f\"source provenance command failed: {' '.join(command)}\"\n            )\n        return result.stdout.strip()","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-persistence-backlog-budget.py#L86-L122","documentation":"validate_frozen_field enforces that certain receipt fields are frozen: their value (and exact type) must still equal a pinned expected value. A mismatch raises PersistenceBacklogError with both the expected and actual values, preventing a stale or tampered persistence-backlog receipt from being accepted after the source identity or pinned constants changed.","triggerScenarios":"Running the budget checker with a receipt generated against different source content than the current tree — e.g. the receipt was committed earlier and since then a pinned field (like a source hash, identity string, or budget constant) changed, or the receipt was hand-edited.","commonSituations":"Forgetting to regenerate the receipt after modifying tracked source files; rebasing onto commits that changed the frozen constants; CI comparing a receipt from an older run against new code; manual edits to the receipt JSON.","solutions":["Regenerate the receipt with the current source so the frozen fields match (usually a refresh/regenerate command in the same script)","If the frozen constant legitimately changed, update the pinned expected value alongside the receipt","Discard hand-edits to the receipt and recreate it from the producing pipeline","Commit the refreshed receipt together with the source change that invalidated it"],"exampleFix":"# regenerate the receipt so the frozen field matches current source\npython scripts/check-persistence-backlog-budget.py --refresh-receipt\npython scripts/check-persistence-backlog-budget.py  # now passes","handlingStrategy":"try-catch","validationCode":"# compare the receipt's frozen field against the current expected value before checking\nexpected = current_source_identity()[\"hash\"]\nassert receipt[\"source_hash\"] == expected, \"receipt is stale; regenerate it\"","typeGuard":null,"tryCatchPattern":"try:\n    validate_receipt(doc)\nexcept PersistenceBacklogError as exc:\n    print(f\"stale/tampered receipt: {exc}\")\n    print(\"regenerate the receipt against current source and commit it\")\n    sys.exit(1)","preventionTips":["Always regenerate the receipt in the same commit that changes pinned source content","Treat the receipt as generated output; never hand-edit it","Re-run the checker after rebase/merge before pushing","Document which fields are frozen so contributors know when a refresh is required"],"tags":["validation","integrity","frozen-field"],"backgroundTag":"checksum-mismatch","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"}