mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-21 22:32:22 +03:00
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