fix(archive): an equal frames version over other frames counts as a frames change

Each index of a shared archive bumps a sidecar put back behind its own row
to one version past that row, which can be the version another index holds
for other frames (a desktop rebuilding a damaged sidecar while the server is
one upload ahead). That index then took the sidecar's frames as unchanged:
it kept the project's positions and what covered the frames, and clients and
editors holding that version saw nothing. When the versions match, a scan
now also compares the row's frame ids and order with the sidecar's; other
frames are read again under the lease and written one version past the row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 23:29:55 +00:00
1 parent 06a1db7ae1
commit 92f4403c76
2 files changed
+77 -5

No files matched your search

+26 -5
View File
@@ -105,9 +105,10 @@ public sealed class ArchiveIndexer
/// <summary>
/// Writes a sequence's sidecar into the index (row, frames, session keys) and records the folder stamps. Frames
/// inserted before indexed ones take the project's frame positions along (<see cref="ProjectPositions"/>). The frames
/// version never goes back: a sidecar read under the lease that is behind the locked row (an older copy put back by
/// hand or by a file-sync tool) is written again one version past the row, so editors and clients holding the row's
/// version see the change.
/// version never goes back, nor names other frames than it did: a sidecar read under the lease that is behind the
/// locked row (an older copy put back by hand or by a file-sync tool), or at the row's version over other frames
/// (another index of the archive bumped a copy put back to it, <see cref="OtherFramesAsync"/>), is written again one
/// version past the row, so editors and clients holding the row's version see the change.
/// </summary>
/// <param name="listed">The folder as the scan listed it before reading <paramref name="manifest"/> without the sequence
/// lease; null when the caller holds the lease and read the sidecar under it.</param>
@@ -131,7 +132,11 @@ public sealed class ArchiveIndexer
if (listed is not null && (FileStamp.Of(sequence.ManifestPath) != listed.Sidecar
|| (existing is not null && existing.FramesVersion != manifest.Versions.Frames)))
return null;
if (existing is not null && existing.FramesVersion > manifest.Versions.Frames)
// Under the lease, the row's own version may also name other frames: another index of the archive bumped a copy
// put back to it (OtherFramesAsync). A caller without the lease compared them before its read (FramesMovedAsync).
if (existing is not null && (existing.FramesVersion > manifest.Versions.Frames
|| (listed is null && existing.FramesVersion == manifest.Versions.Frames
&& await OtherFramesAsync(tx, existing, manifest, cancellationToken).ConfigureAwait(false))))
{
manifest = manifest with
{
@@ -387,7 +392,23 @@ public sealed class ArchiveIndexer
/// </summary>
private async Task<bool> FramesMovedAsync(SequenceManifest manifest, CancellationToken cancellationToken) =>
await _db.Sequences.GetAsync(manifest.Id, cancellationToken).ConfigureAwait(false) is { } indexed
&& indexed.FramesVersion != manifest.Versions.Frames;
&& await OtherFramesAsync(_db, indexed, manifest, cancellationToken).ConfigureAwait(false);
/// <summary>
/// Whether the index row <paramref name="indexed"/> holds other frames than <paramref name="manifest"/>: another frames
/// version, or the same version over other frames (ids, or their order). Each index of a shared archive bumps a sidecar
/// put back behind its own row one version past that row (<see cref="SyncAsync"/>), and another index may hold that
/// very version for the frames as they were before: that index still sees the change, and bumps past it in turn.
/// </summary>
private static async Task<bool> OtherFramesAsync(TitanoRepositories db, Sequence indexed, SequenceManifest manifest, CancellationToken cancellationToken)
{
if (indexed.FramesVersion != manifest.Versions.Frames) return true;
var rows = await db.Frames.ListPositionsAsync(indexed.Id, cancellationToken).ConfigureAwait(false);
if (rows.Count != manifest.Frames.Count) return true;
var listed = new Dictionary<int, Guid>(manifest.Frames.Count);
foreach (var frame in manifest.Frames) listed[frame.I] = frame.Id;
return rows.Any(row => !listed.TryGetValue(row.Index, out var id) || id != row.FrameId);
}
/// <summary>A sidecar for a folder that has none; ids of a sequence the index already knew at this folder are kept.</summary>
private async Task<SequenceManifest> AdoptAsync(SequencePaths sequence, Locations locations, CancellationToken cancellationToken)