fix(projects): sidecars stay the truth when they cannot be read, are missing or newer
A project record that could not be read once, or a missing .chronos/projects, marked projects deleted for good and made a second Main; an index meeting Main with no mirror state took its own stale settings column as an outside change and reverted the pushed head; a newer-format or unreadable head made every project call fail or rewrote the record's head over the real history. Now: - Deletion is never inferred from absence or a read failure: an unreadable record holds its project back (listed as indexed, nothing written for it, no second Main), a row marked deleted is revived when its live record says so, and projects the archive has no folder for are written back from the index. - Appends re-read the record under the lease and refuse when its head is not the index's; Main is only made when the sequence has none anywhere. - An index with no mirror state decides from project.json and the record's new mirrored member (older records: the head's ancestry), never from its own column. - A newer-format Main head is listed and pulled but never mirrored, merged or built on; pushes must parse strictly and fit the one 64 MB version limit (TooLarge otherwise). - Duplicate version numbers and name/Main clashes are contained per project, so a scan or rebuild never stops. - Delete moves the folder first, then writes the deleted record in the trash. - The home's read-back for workspace pruning and Remove local copy reads the version files (IProjectHome.HoldsAsync), not the index. - A read-only archive is read without writing: its projects open from the sidecars and a sequence with no Main gets one in the index only, written back once writable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
50e28fd63d
commit
d940fc7c61
6 files changed
+1247
-158
No files matched your search
@@ -33,6 +33,18 @@ public interface IProjectHome
|
||||
/// <summary>A version of the project by id; null when the home has none.</summary>
|
||||
Task<ProjectVersion?> GetVersionAsync(Guid projectId, Guid versionId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the home holds <paramref name="version"/> durably, read back from where it keeps it and matching its content
|
||||
/// hash: what a workspace asks before it drops its own copy. A home that keeps no other copy answers from
|
||||
/// <see cref="GetVersionAsync"/>.
|
||||
/// </summary>
|
||||
async Task<bool> HoldsAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(version);
|
||||
return await GetVersionAsync(projectId, version.Id, cancellationToken).ConfigureAwait(false) is { } held
|
||||
&& string.Equals(held.ContentHash, version.ContentHash, StringComparison.OrdinalIgnoreCase) && ProjectContent.Verifies(held.SettingsJson, held.ContentHash);
|
||||
}
|
||||
|
||||
/// <summary>The versions numbered above <paramref name="afterNumber"/>, oldest first, at most <paramref name="limit"/>.</summary>
|
||||
Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken);
|
||||
|
||||
@@ -91,6 +103,16 @@ public sealed class ArchiveProjectHome(ChronosDatabase db, ProjectService projec
|
||||
return version is not null && version.ProjectId == projectId ? version : null;
|
||||
});
|
||||
|
||||
/// <summary>Read back from the version's file in the archive, never from the index's row (<see cref="ProjectService.StoredAsync"/>).</summary>
|
||||
public Task<bool> HoldsAsync(Guid projectId, ProjectVersion version, CancellationToken cancellationToken) =>
|
||||
Reach(async () =>
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(version);
|
||||
var project = await Own(projectId, cancellationToken).ConfigureAwait(false);
|
||||
return project.DeletedAt is null && ProjectContent.Verifies(version.SettingsJson, version.ContentHash)
|
||||
&& await projects.StoredAsync(projectId, version, cancellationToken).ConfigureAwait(false);
|
||||
});
|
||||
|
||||
public Task<IReadOnlyList<ProjectVersion>> VersionsAfterAsync(Guid projectId, int afterNumber, int limit, CancellationToken cancellationToken) =>
|
||||
Reach(async () =>
|
||||
{
|
||||
@@ -151,5 +173,10 @@ public sealed class ArchiveProjectHome(ChronosDatabase db, ProjectService projec
|
||||
// Another index of the archive moved the sequence: this one finds it at its next scan.
|
||||
throw new HomeUnavailableException(ex.Message, ex);
|
||||
}
|
||||
catch (ProjectsUnreadableException ex)
|
||||
{
|
||||
// A record or a version this Chronos cannot read now (damaged, held open, of a newer Chronos): nothing was written.
|
||||
throw new HomeUnavailableException(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user