fix(gateway): preserve expiration sweep coverage - #468
Merged
Conversation
Count target rows from DELETE RETURNING because D1 meta.changes includes trigger side effects and can make bounded cleanup report the wrong batch size.\n\nAdd a database invariant that rejects queue deletion while domain rows remain, then re-enqueue every existing dump and Responses key missing coverage. Cover trigger-amplified counts, migration repair, guarded completion, and bounded inactive cleanup.
Prevent queue identity updates from bypassing the source-row guard. Exercise each migration source and preservation path independently, calibrate D1 change-count instrumentation, and cover active and inactive trigger-amplified deletions.
Enforce queue identity as an unconditional database invariant, reject missing change-count instrumentation, and attach the complete D1 and SQLite evidence chain to exact deletion accounting.
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.
Summary
D1 reports
meta.changesfrom SQLitetotal_changes(), which includes writes performed by trigger programs. Dump and spilled Responses deletion therefore returned a trigger-amplified count rather than the number of source rows deleted. Inactive cleanup could mistake a full batch for a drained key and remove itsexpiration_sweepsrow while records remained.DELETE ... RETURNINGresult rows.0082_expiration_sweep_integrity.sql.The migration installs the deletion guard before repairing coverage, so the pre-deploy Worker cannot recreate the gap during a migrate-then-deploy rollout.
Test Plan
meta.changes = 150for 50 dump rows and loses the queue; current code repairs and drains 70 → 20 → 0.pnpm run verify— 544 test files and 5,654 tests passed, plus lint, typecheck, installer harness, generated assets, AGENTS validation, verification parity, and web build.