{"record":{"id":"9fb568fa2d2df175","repo":"Hmbown/CodeWhale","slug":"rss-during-delta-bytes-is-inconsistent","errorCode":null,"errorMessage":"rss_during_delta_bytes is inconsistent","messagePattern":"rss_during_delta_bytes is inconsistent","errorType":"exception","errorClass":"PersistenceBacklogError","httpStatus":null,"severity":"error","filePath":"scripts/check-persistence-backlog-budget.py","lineNumber":233,"sourceCode":"        isinstance(item, str) and item for item in limitations\n    ):\n        raise PersistenceBacklogError(\"limitations must be a non-empty string array\")\n\n    if not isinstance(receipt[\"rss_supported\"], bool):\n        raise PersistenceBacklogError(\"rss_supported must be boolean\")\n    if receipt[\"rss_supported\"] != (platform == \"macos\"):\n        raise PersistenceBacklogError(\n            \"rss_supported must be true exactly on the macOS measurement lane\"\n        )\n    rss_fields = RSS_SAMPLE_FIELDS + RSS_DELTA_FIELDS\n    if receipt[\"rss_supported\"]:\n        for field in rss_fields:\n            non_negative_integer(receipt[field], field)\n        before = receipt[\"rss_before_bytes\"]\n        if receipt[\"rss_during_delta_bytes\"] != max(\n            0, receipt[\"rss_during_bytes\"] - before\n        ):\n            raise PersistenceBacklogError(\"rss_during_delta_bytes is inconsistent\")\n        if receipt[\"rss_after_delta_bytes\"] != max(\n            0, receipt[\"rss_after_bytes\"] - before\n        ):\n            raise PersistenceBacklogError(\"rss_after_delta_bytes is inconsistent\")\n    elif any(receipt[field] is not None for field in rss_fields):\n        raise PersistenceBacklogError(\"unsupported RSS fields must be null\")\n\n\ndef validate_budget(budget: dict[str, Any]) -> None:\n    if budget.get(\"document_kind\") != BUDGET_KIND:\n        raise PersistenceBacklogError(f\"budget document_kind must be {BUDGET_KIND}\")\n    if budget.get(\"schema_version\") != SCHEMA_VERSION:\n        raise PersistenceBacklogError(\"budget schema_version changed\")\n    fixture = budget.get(\"fixture\")\n    if not isinstance(fixture, dict) or set(fixture) != set(FIXTURE):\n        raise PersistenceBacklogError(\"budget fixture no longer matches the frozen workload\")\n    for field, expected in FIXTURE.items():\n        if type(fixture[field]) is not type(expected) or fixture[field] != expected:","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/scripts/check-persistence-backlog-budget.py#L215-L251","documentation":"Raised by validate_receipt() in scripts/check-persistence-backlog-budget.py when a receipt with rss_supported=true records rss_during_delta_bytes that is not exactly max(0, rss_during_bytes - rss_before_bytes). The raw RSS samples are treated as ground truth and the delta column must be a deterministic, clamped-at-zero recompute of them, so any mismatch means the receipt was hand-edited or produced by a buggy sampler. This integrity check runs before the receipt is compared against the budget ceilings.","triggerScenarios":"Calling compare()/validate_receipt() with rss_supported true and rss_during_delta_bytes differing from max(0, rss_during_bytes - rss_before_bytes) - e.g. an off-by-one edit, a delta computed from a stale rss_during_bytes sample, or an unclamped negative difference stored as anything other than 0. The repo's own tests trigger it by bumping rss_during_delta_bytes by 1 (test_rss_delta_must_match_samples).","commonSituations":"Hand-editing a receipt JSON to nudge a number; refactoring scripts/measure-persistence-backlog.py so it samples RSS in a different order or drops the max(0, ...) clamp; mixing in receipts from an older schema where deltas were computed differently; KB-vs-bytes unit confusion.","solutions":["Recompute and write rss_during_delta_bytes = max(0, rss_during_bytes - rss_before_bytes) in the receipt","Prefer regenerating the receipt entirely: python scripts/measure-persistence-backlog.py > receipt.json","If the sampler itself emits inconsistent deltas, fix its delta computation to use the identical clamp formula","Re-run scripts/check-persistence-backlog-budget.py --receipt receipt.json to confirm"],"exampleFix":"// before (receipt.json)\n\"rss_before_bytes\": 18923520,\n\"rss_during_bytes\": 28377088,\n\"rss_during_delta_bytes\": 9453000\n\n// after: 28377088 - 18923520 = 9453568\n\"rss_before_bytes\": 18923520,\n\"rss_during_bytes\": 28377088,\n\"rss_during_delta_bytes\": 9453568","handlingStrategy":"validation","validationCode":"def rss_during_delta_consistent(receipt: dict) -> bool:\n    if not receipt.get(\"rss_supported\"):\n        return receipt.get(\"rss_during_delta_bytes\") is None\n    return receipt[\"rss_during_delta_bytes\"] == max(\n        0, receipt[\"rss_during_bytes\"] - receipt[\"rss_before_bytes\"]\n    )\n# call before compare(receipt, budget)","typeGuard":"from typing import TypeGuard\n\ndef has_consistent_rss_deltas(r: dict) -> TypeGuard[dict]:\n    before = r[\"rss_before_bytes\"]\n    return (r[\"rss_during_delta_bytes\"] == max(0, r[\"rss_during_bytes\"] - before)\n            and r[\"rss_after_delta_bytes\"] == max(0, r[\"rss_after_bytes\"] - before))","tryCatchPattern":"try:\n    increases, decreases = compare(receipt, budget)\nexcept PersistenceBacklogError as error:\n    print(f\"[persistence-backlog-budget] ERROR: {error}\", file=sys.stderr)\n    raise SystemExit(2) from error","preventionTips":["Never hand-edit receipt JSON; regenerate it with scripts/measure-persistence-backlog.py","Keep the clamp formula max(0, sample - rss_before_bytes) in one shared helper used by both the sampler and the checker","Run scripts/test_check_persistence_backlog_budget.py after touching any RSS handling"],"tags":["rss","measurement-receipt","python","ci-gate","json"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}