{"record":{"id":"f2aed7a799a6539d","repo":"Hmbown/CodeWhale","slug":"retained-queued-requests-exceeds-accepted-requests","errorCode":null,"errorMessage":"retained_queued_requests exceeds accepted_requests","messagePattern":"retained_queued_requests exceeds accepted_requests","errorType":"validation","errorClass":"PersistenceBacklogError","httpStatus":null,"severity":"error","filePath":"scripts/check-persistence-backlog-budget.py","lineNumber":193,"sourceCode":"                    f\"receipt {field} does not match the checked source\"\n                )\n    if require_clean_source and receipt[\"source_dirty\"]:\n        raise PersistenceBacklogError(\"persistence measurement source tree is dirty\")\n    platform = receipt[\"platform\"]\n    if not isinstance(platform, str) or platform not in SUPPORTED_PLATFORMS:\n        raise PersistenceBacklogError(\"receipt platform is unsupported\")\n\n    attempted = non_negative_integer(receipt[\"requests_attempted\"], \"requests_attempted\")\n    accepted = non_negative_integer(receipt[\"accepted_requests\"], \"accepted_requests\")\n    if accepted != attempted:\n        raise PersistenceBacklogError(\n            \"accepted_requests must equal requests_attempted; sender rejection is not backlog improvement\"\n        )\n    retained = non_negative_integer(\n        receipt[\"retained_queued_requests\"], \"retained_queued_requests\"\n    )\n    if retained > accepted:\n        raise PersistenceBacklogError(\"retained_queued_requests exceeds accepted_requests\")\n    for field in (\"estimated_retained_payload_bytes\", \"enqueue_elapsed_ns\"):\n        non_negative_integer(receipt[field], field)\n    if retained == 0 or receipt[\"estimated_retained_payload_bytes\"] == 0:\n        raise PersistenceBacklogError(\n            \"the paused channel must retain the newest request and its payload\"\n        )\n    minimum_payload_bytes = retained * FIXTURE[\"content_bytes_per_request\"]\n    if receipt[\"estimated_retained_payload_bytes\"] < minimum_payload_bytes:\n        raise PersistenceBacklogError(\n            \"estimated_retained_payload_bytes is smaller than the frozen retained content\"\n        )\n    applied = non_negative_integer(\n        receipt[\"applied_version\"], \"applied_version\"\n    )\n    if applied != FIXTURE[\"expected_applied_version\"]:\n        raise PersistenceBacklogError(\"applied_version is not the final sent version\")\n    if receipt[\"final_version_applied\"] is not True:\n        raise PersistenceBacklogError(\"final_version_applied must be true\")","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/scripts/check-persistence-backlog-budget.py#L175-L211","documentation":"validate_receipt checks that retained_queued_requests never exceeds accepted_requests: you cannot retain more queued requests than were accepted into the channel. This is a logical-consistency invariant on the receipt produced by the paused-channel measurement; a larger retained count implies corrupted or fabricated measurement output.","triggerScenarios":"Raised by validate_receipt when receipt['retained_queued_requests'] > receipt['accepted_requests'], from validate_baseline_receipt or compare.","commonSituations":"Hand-edited receipts where retained was increased for a tighter baseline but accepted was not; a buggy estimator that counts requests twice; schema drift between the measuring script and the checker.","solutions":["Regenerate the receipt with the current measurement script so retained_queued_requests is measured, not asserted.","Verify retained_queued_requests counts distinct queued requests only (no double counting of the final applied request).","If the baseline receipt was edited, restore scripts/persistence-backlog-baseline-receipt.json from a clean measurement run."],"exampleFix":"// before\n{\"accepted_requests\": 128, \"retained_queued_requests\": 129}\n// after\n{\"accepted_requests\": 128, \"retained_queued_requests\": 1}  # from a real run","handlingStrategy":"validation","validationCode":"def retained_within_accepted(receipt):\n    return 0 <= receipt.get(\"retained_queued_requests\", -1) <= receipt.get(\"accepted_requests\", 0)","typeGuard":"def is_non_negative_int(v):\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 0","tryCatchPattern":"try:\n    validate_receipt(receipt)\nexcept PersistenceBacklogError as e:\n    print(f\"receipt inconsistent: {e}\", file=sys.stderr)\n    sys.exit(2)","preventionTips":["Count retained requests from the channel's own queue length, not from assumptions.","Validate receipts at generation time, before committing them as baselines.","Treat baseline receipt files as build artifacts: regenerate, never hand-edit."],"tags":["measurement","validation","consistency","python"],"backgroundTag":"schema-validation-failed","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"}