From a368dc8bf0529b7311858c195da48592b052a497 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Tue, 3 Nov 2026 11:24:15 +0100 Subject: [PATCH] fix(projects): phase 5a fix round 2 of the projects engine The sidecars stay the truth of a sequence's projects in the cases round 1's checkers found still open, and no version or setting is lost on the way: - An index-only Main meeting a Main another index made is written back as another project, and Main passes to theirs in one transaction through a free temporary name, so ux_projects_name and ux_projects_main never fail (the SqliteException used to escape ListAsync and leave the index and the sidecars disagreeing). A refusal is logged; the next reconcile settles it. - The reconcile takes Main from the records, in step with the index, when another index passed it on: exactly one Main per sequence, names from the records where free. - A project folder with versions and no record, of a project no index row names (a creation cut before its record), no longer holds the sequence back forever: it is left as it is and indexed once its record arrives. - A record behind the index (a projects folder put back from an older backup) is made whole from the index: its missing versions and the record are written again, at every catch-up and before any append, rename or delete. Only a record ahead of the index or naming another version is refused, with a message that says so. - An index meeting Main walks the chain down to the version the record names as mirrored (a bound, since that record write may lag project.json), so a lagging record never makes an External that reverts a newer push. When the record names a mirrored ancestor, settings written since merge with the unmirrored versions, as for an index that knows its mirror. - The catch-up merge's External + Merge pair is resumable: an External head whose parent is a push no mirror wrote is finished into its Merge version next time, by this index or one rebuilt from the sidecars. - A project deleted at the home has no head there, so a workspace copy of it reads Gone, never In sync; Remove local copy without discard says the project was deleted in the library. - DatabaseExceptions are contained per sequence in the archive scan's project reconcile and in ProjectService reads. Tests: SQLite (PostgreSQL-ready) for each scenario, including a cut between the two catch-up versions, a 40,000-exclusion version through save, push and rebuild, and the App's Remove local copy of a project deleted at home. Co-Authored-By: Claude Opus 5.5 --- i18n/en/Errors.resx | 1 + i18n/it/Errors.it.resx | 1 + src/Chronos.App/Workspace/WorkspaceHost.cs | 5 + src/Chronos.Data/Archiving/ArchiveIndexer.cs | 5 + src/Chronos.Data/Projects/IProjectHome.cs | 5 +- src/Chronos.Data/Projects/ProjectIndexer.cs | 70 ++++- src/Chronos.Data/Projects/ProjectService.cs | 279 ++++++++++++++---- .../Workspace/WorkspaceHostTests.cs | 19 ++ .../Projects/ProjectMergeTests.cs | 56 ++++ .../Projects/ProjectRecoveryTests.cs | 264 +++++++++++++++++ 10 files changed, 635 insertions(+), 70 deletions(-) diff --git a/i18n/en/Errors.resx b/i18n/en/Errors.resx index c1581591..e6c1f139 100644 --- a/i18n/en/Errors.resx +++ b/i18n/en/Errors.resx @@ -53,6 +53,7 @@ Its local copy could not be removed now: Remove local copy takes it later.long {0} did not match its source after it was copied.{0} file path A file of this project in the workspace cannot be read; the log names it. + This project was deleted in the library; nothing was removed. Discard changes removes its local copy. The workspace drive needs {0} GB more for this copy.{0} gigabytes missing The last edit could not be stored yet; it is tried again, try once more in a moment. The library's copy of this project does not match what was sent; nothing was removed. diff --git a/i18n/it/Errors.it.resx b/i18n/it/Errors.it.resx index 84954535..82039775 100644 --- a/i18n/it/Errors.it.resx +++ b/i18n/it/Errors.it.resx @@ -53,6 +53,7 @@ La sua copia locale ora non è stata rimossa: Rimuovi copia locale la toglie più tardi. {0} non corrispondeva all'originale dopo la copia. Un file di questo progetto nello spazio di lavoro non è leggibile; il log lo indica. + Questo progetto è stato eliminato nella libreria; non è stato rimosso nulla. Scarta modifiche rimuove la sua copia locale. Al disco dello spazio di lavoro servono altri {0} GB per questa copia. L'ultima modifica non è ancora stata memorizzata; viene ritentata, riprova tra un momento. La copia di questo progetto nella libreria non corrisponde a quanto inviato; non è stato rimosso nulla. diff --git a/src/Chronos.App/Workspace/WorkspaceHost.cs b/src/Chronos.App/Workspace/WorkspaceHost.cs index 45374e7c..c1e18d3f 100644 --- a/src/Chronos.App/Workspace/WorkspaceHost.cs +++ b/src/Chronos.App/Workspace/WorkspaceHost.cs @@ -600,6 +600,11 @@ public sealed class WorkspaceHost held = basis is not null && await home.HoldsAsync(projectId, head, cancellationToken).ConfigureAwait(false) && (basis.Id == head.Id || await home.HoldsAsync(projectId, basis, cancellationToken).ConfigureAwait(false)); } + catch (ProjectException ex) when (ex.Reason is ProjectError.NotFound or ProjectError.SequenceNotFound) + { + // Deleted at the home (its trash keeps every version sent): this copy goes only when its user discards it. + throw new WorkspaceException(Loc.L("Errors.Workspace.DeletedAtHome"), ex); + } catch (Exception ex) when (ex is HomeUnavailableException or ProjectException or DatabaseException) { throw new WorkspaceException(Loc.L("Errors.Workspace.Offline"), ex); diff --git a/src/Chronos.Data/Archiving/ArchiveIndexer.cs b/src/Chronos.Data/Archiving/ArchiveIndexer.cs index 7eb22a7d..0fc05c19 100644 --- a/src/Chronos.Data/Archiving/ArchiveIndexer.cs +++ b/src/Chronos.Data/Archiving/ArchiveIndexer.cs @@ -368,6 +368,11 @@ public sealed class ArchiveIndexer { Log.Warning("projects", $"The projects of {row.Folder} could not be read back; the next project operation tries again", ex); } + catch (DatabaseException ex) + { + // The index refused a project of this sequence: the scan goes on with the others, and the next project operation tries again. + Log.Warning("projects", $"The projects of {row.Folder} could not be indexed; the next project operation tries again", ex); + } } /// Indexes one folder; returns its sequence and the sidecar bytes when they were read and not rewritten since (for the snapshot). diff --git a/src/Chronos.Data/Projects/IProjectHome.cs b/src/Chronos.Data/Projects/IProjectHome.cs index 098ec3b8..d34d1222 100644 --- a/src/Chronos.Data/Projects/IProjectHome.cs +++ b/src/Chronos.Data/Projects/IProjectHome.cs @@ -27,7 +27,10 @@ public interface IProjectHome /// A new project named from (a version of any project of the sequence), or from Main's head. Task CreateAsync(string name, Guid? fromVersionId, string? author, CancellationToken cancellationToken); - /// The project's newest version. + /// + /// The project's newest version; a project deleted at the home has none (, + /// ), so a workspace's copy of it reads as gone, never as in step. + /// Task HeadAsync(Guid projectId, CancellationToken cancellationToken); /// A version of the project by id; null when the home has none. diff --git a/src/Chronos.Data/Projects/ProjectIndexer.cs b/src/Chronos.Data/Projects/ProjectIndexer.cs index 84401b38..a32ce0a9 100644 --- a/src/Chronos.Data/Projects/ProjectIndexer.cs +++ b/src/Chronos.Data/Projects/ProjectIndexer.cs @@ -53,11 +53,21 @@ internal sealed class ProjectIndexer(ChronosDatabase db) } catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException) { - Log.Warning("projects", $"The project in {directory} cannot be read; it stays as the index has it", ex); - // Its folder names it (, or -