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 <noreply@anthropic.com>
This commit is contained in:
SucukdeluxeandClaude Opus 5.5 committed 2026-10-21 22:19:19 +02:00
1 parent b5b81d8a8d
commit b7be8d492a
1 file changed
+12 -1
+12 -1
View File
@@ -174,7 +174,12 @@ function createSourceFileCleanup(options) {
const canonicalFile = canonicalize(input.file); const canonicalFile = canonicalize(input.file);
const manifest = createManifest(input, canonicalFile); const manifest = createManifest(input, canonicalFile);
const leaseToken = leases.get(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.registrationOutcome = 'blocked';
manifest.registrationError = new Error('active-source-lease'); manifest.registrationError = new Error('active-source-lease');
const leaseOwner = groups.get(leaseToken); const leaseOwner = groups.get(leaseToken);
@@ -208,6 +213,12 @@ function createSourceFileCleanup(options) {
return true; return true;
} }
function canBeSuperseded(manifest) {
return !manifest.finalizationPromise
&& manifest.jobs.size > 0
&& [...manifest.jobs.values()].every((job) => job.status !== 'pending');
}
function isReady(manifest) { function isReady(manifest) {
return !manifest.finalizationPromise return !manifest.finalizationPromise
&& !manifest.registrationOutcome && !manifest.registrationOutcome