From bc90e5a244958213b6aea5ba5e9c9bede3cbc296 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Wed, 4 Nov 2026 19:26:31 +0100 Subject: [PATCH] fix(workspace): a copy cancelled just before its commit never commits A cancel landing while the copy's last query was in flight (PostgreSQL answers a finished query anyway) went unseen: the copy took the freed project lease, committed media.json and ended Done over Cancelled, so its clean-up never ran. Both commit points now check the token under the lease. Seen once in CI's PostgreSQL 17 run of ACancelledFirstCopyRemovesTheMediaItWroteOnceItStopped. Co-Authored-By: Claude Opus 5.5 --- docs/CHANGELOG.md | 2 ++ src/Chronos.Data/Workspaces/WorkspaceCopyJobHandler.cs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 16903d25..f270a305 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -51,6 +51,8 @@ commits follow Conventional Commits (release notes are generated from them by `C keeps *Change…* and *Move…* disabled until then. The Server header no longer shows this PC's local renders as server jobs; the *Copying originals* toast's Jobs button works; disabled *Copy originals…* and *Proxies only…* say why. Italian wording. +- A workspace copy cancelled just before it committed (its last query already answered, the project's lease then free) + could commit anyway and end *Done*, keeping the media it wrote; it now stops at the commit and its clean-up runs. ### Changed - *Pause uploads on metered* (Server screen) is now *Pause metered transfers*: on a metered connection the sync's diff --git a/src/Chronos.Data/Workspaces/WorkspaceCopyJobHandler.cs b/src/Chronos.Data/Workspaces/WorkspaceCopyJobHandler.cs index 81a40fea..42a15f4d 100644 --- a/src/Chronos.Data/Workspaces/WorkspaceCopyJobHandler.cs +++ b/src/Chronos.Data/Workspaces/WorkspaceCopyJobHandler.cs @@ -465,6 +465,9 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService // The working state is the editor's meanwhile: it is held only while the media index and the positions move. using (await project.LockAsync(LockWait, ct).ConfigureAwait(false)) { + // The commit point: a cancel that came while the copy waited (a query it did not stop, the lease) wins here, + // so a cancelled copy never commits and its clean-up removes what it wrote. + ct.ThrowIfCancellationRequested(); Commit(project, project.ReadBundle(), media, row.Folder, row.DisplayTitle); RemoveStale(project, media, frames); } @@ -600,6 +603,9 @@ internal sealed class WorkspaceCopyJobHandler(ChronosDatabase db, ArchiveService // The working state is the editor's meanwhile: it is held only while the media index and the positions move. using (await project.LockAsync(LockWait, ct).ConfigureAwait(false)) { + // The commit point: a cancel that came while the copy waited (a query it did not stop, the lease) wins here, + // so a cancelled copy never commits and its clean-up removes what it wrote. + ct.ThrowIfCancellationRequested(); Commit(project, project.ReadBundle(), media, folder, sequence.DisplayTitle); RemoveStale(project, media, frames); }