Files
OmniRoute/tests
diegosouzapw 0de1660f10 fix(db): cap per-request batch sweep and guard shared files (#13680, #13681)
deleteCompletedBatches ran an unbounded synchronous for(;;) loop over
INSTANCE_SWEEP_CHUNK-sized chunks, so one request could hold the event
loop for as long as it took to sweep every completed batch on the
instance, with no way for the caller to detect or bound the work.
Separately, the sweep (and deleteBatch) nulled a batch's input/output/
error file unconditionally, even when another batch — in progress, or
completed but outside the swept chunk — still referenced the same file.

Adds MAX_CHUNKS_PER_REQUEST (25 * INSTANCE_SWEEP_CHUNK = 5000 batches)
to sweepLoop with a hasMore continuation flag threaded through the
DELETE /v1/batches/delete-completed response (resumption is natural via
rowid ordering, no cursor needed); and isFileReferencedByOtherBatch(),
applied before every file soft-delete in deleteCompletedBatches,
deleteBatch, and cleanupExpiredBatches.

Regression tests: tests/unit/issue-13680-batches-delete-completed-unbounded-work.test.ts,
tests/unit/issue-13681-shared-file-across-batches.test.ts
2026-09-15 19:56:13 -03:00
..