fix(gateway): keep owed delivery obligations under max-row prune#71111
Open
fangliquanflq wants to merge 1 commit into
Open
fix(gateway): keep owed delivery obligations under max-row prune#71111fangliquanflq wants to merge 1 commit into
fangliquanflq wants to merge 1 commit into
Conversation
Count-cap prune deleted oldest pending/attempting/failed rows when the ledger exceeded _MAX_ROWS, permanently dropping undelivered finals under backlog pressure. Scope the DELETE to delivered/abandoned only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Stops the delivery-obligation ledger from hard-deleting still-owed final replies when the row-count cap is exceeded. Count pressure now only drops terminal
delivered/abandonedrows, matching time-based retention, so backlog pressure cannot silently erase recoverables.Bug Cause
gateway/delivery_ledger._pruneapplies a max-row DELETE after the time cutoff. The subquery ordereddelivered=0,abandoned=1, thenELSE=2. Under a backlog of only (or mostly)pending/attempting/failedrows, excess deleted the oldest owed obligations permanently. Those rows never reachsweep_recoverable, so users lose finals the ledger was meant to protect. Time retention already scoped to terminal states; the count path did not. Existing tests only covered the time cutoff, not_MAX_ROWS.Reproduction Steps
HERMES_HOMEat an empty temp dir and importgateway.delivery_ledger.record_obligationmore than_MAX_ROWStimes with distinct pending ids (each call triggers_prune).delivery_obligations: total is capped at_MAX_ROWS, and the oldest pending id is gone.Expected: owed (
pending/attempting/failed) rows survive count pressure (or at least are abandoned for inspection, not hard-deleted).Before fix: oldest owed rows disappear with no
abandonedtransition.Fix
Scope the max-row DELETE to
state IN ('delivered', 'abandoned'), preferringdeliveredbeforeabandonedby updated age. Owed rows may temporarily exceed_MAX_ROWSuntil delivered or until dead-owner sweep transitions poison/stale rows toabandoned. AddedTestPrunecoverage for all-pending overflow and mixed terminal + owed (including abandoned).Related Issue
No issue - discovered via bug-hunter finding BUG-GDL-2.
Type of Change
Changes Made
gateway/delivery_ledger.py- max-row prune deletes only terminal rows; document soft cap for owed backlogtests/gateway/test_delivery_ledger.py- assert owed rows survive count cap; terminal rows (delivered + abandoned) are preferred victimsHow to Test
_MAX_ROWSpending obligations viarecord_obligation; confirm oldest pending ids remain and only terminal rows are dropped when mixed.Checklist
Code
scripts/run_tests.shon relevant tests and they passDocumentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys - N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows - N/A