From b7be8d492a37c169778e8b54752fc62452a0ae15 Mon Sep 17 00:00:00 2001 From: Sucukdeluxe <259325684+Sucukdeluxe@users.noreply.github.com> Date: Wed, 21 Oct 2026 22:19:19 +0200 Subject: [PATCH] Let a later cleanup group take over a source whose earlier group has finished When the same file was registered for cleanup a second time (for example a repeated upload to one hoster), both groups blocked each other through the source lease and the file was never deleted, even after every hoster had succeeded. A later group now takes over the lease once every job of the earlier group has reached a terminal state; the earlier group is audited as superseded. Groups with a still running job keep blocking as before. Co-Authored-By: Claude Opus 5.5 --- lib/source-file-cleanup.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/source-file-cleanup.js b/lib/source-file-cleanup.js index 9847a8b..72db854 100644 --- a/lib/source-file-cleanup.js +++ b/lib/source-file-cleanup.js @@ -174,7 +174,12 @@ function createSourceFileCleanup(options) { const canonicalFile = canonicalize(input.file); const manifest = createManifest(input, canonicalFile); const leaseToken = leases.get(canonicalFile); - if (leaseToken && leaseToken !== token) { + const previousOwner = leaseToken && leaseToken !== token ? groups.get(leaseToken) : null; + if (previousOwner && previousOwner.canonicalFile === canonicalFile && canBeSuperseded(previousOwner)) { + previousOwner.registrationOutcome = previousOwner.registrationOutcome || 'superseded'; + leases.set(canonicalFile, token); + await inspectRegistration(manifest); + } else if (leaseToken && leaseToken !== token) { manifest.registrationOutcome = 'blocked'; manifest.registrationError = new Error('active-source-lease'); const leaseOwner = groups.get(leaseToken); @@ -208,6 +213,12 @@ function createSourceFileCleanup(options) { return true; } + function canBeSuperseded(manifest) { + return !manifest.finalizationPromise + && manifest.jobs.size > 0 + && [...manifest.jobs.values()].every((job) => job.status !== 'pending'); + } + function isReady(manifest) { return !manifest.finalizationPromise && !manifest.registrationOutcome