fix(db): forward-progress guard in both deleteCompletedBatches chunk loops (#13377) - #13570
Closed
jonlwheat2-gif wants to merge 1 commit into
Conversation
…loops (diegosouzapw#13377) Issue diegosouzapw#13377 asks for a forward-progress guard in BOTH `for (;;)` loops of `deleteCompletedBatches` — the key-scoped loop and the instance-wide loop. Both loops walk completed batches in chunks of `INSTANCE_SWEEP_CHUNK`: SELECT id FROM batches WHERE status = 'completed' [AND api_key_id = ?] ORDER BY rowid LIMIT ? Each iteration sweeps its chunk (file soft-deletes + checkpoint DELETE + batch DELETE) and then re-selects the next chunk. If a DELETE ever fails to make progress — a concurrent deleter holding the same rows, or a swallowed no-op delete — the same chunk is returned forever and the request thread spins. The guard remembers the first id of the previous chunk and throws when the next chunk starts with the same id: deleteCompletedBatches: chunk sweep made no forward progress (first id repeated) Failure semantics match each mode: - Key mode wraps the whole chunk loop in ONE outer transaction, so throwing rolls the entire key sweep back (all-or-nothing, unchanged). - Instance mode commits per chunk (SEC-D), so throwing leaves earlier chunks committed, rolls the current chunk back, and rethrows. Stacked on diegosouzapw#13374 (`fix/batches-sweep-file-ownership-chunks`), whose two chunked loops this guard protects.
This was referenced Sep 13, 2026
Contributor
Author
|
CI note. No Checks will run once this is retargeted to Local verification of this change: the diff against #13374's head is exactly the 23 added lines in |
diegosouzapw
deleted the branch
diegosouzapw:fix/batches-sweep-file-ownership-chunks
September 14, 2026 16:42
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
Stacked on #13374 (
fix/batches-sweep-file-ownership-chunks). Adds the forward-progress guard that issue #13377 asks for in bothfor (;;)loops ofdeleteCompletedBatches.Why
Both loops walk completed batches in chunks of
INSTANCE_SWEEP_CHUNK:Each iteration sweeps its chunk (file soft-deletes + checkpoint DELETE + batch DELETE) and then re-selects the next chunk. If a DELETE ever fails to make progress — a concurrent deleter holding the same rows, or a swallowed no-op delete — the same chunk is returned forever and the request thread spins.
Change
src/lib/db/batches.ts— +23 lines, one guard per loop:Failure semantics stay consistent with each mode:
{ apiKeyId }){ allTenants: true })Verification
git diffagainst fix(db): owner-scoped file half and chunked instance sweep for DELETE /v1/batches/delete-completed (SEC-C/SEC-D, omni-code-sec on #12969) #13374's head is exactly the 23 added lines,src/lib/db/batches.tsonlynode --experimental-strip-types --check)Related
CONFLICTING; needs a rebase before this stack can land)node:fsin the client chunk graph)