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

@@ -508,6 +508,57 @@ public abstract class PartialRowWriterTests(TestContext context) : DatabaseTest(
Assert.Empty((await fx.ScanAsync()).Sequences);
}
[Test]
public async Task AFramesVersionAnotherIndexReachedForOtherFramesIsIndexedPastIt()
{
var fx = await FixtureAsync();
var sequence = await IndexedAsync(fx);
var folder = fx.Paths.Sequence("a");
async Task<Sequence> UploadAsync(string name, int minute)
{
var staged = fx.Stage(Start.AddMinutes(minute), seed: 90 + minute);
await fx.Service.Ingest.CommitAsync(new IngestRequest(fx.Archive.Id, sequence.Id, null, null, staged.Path, name, staged.Size, staged.Sha256, null, null),
fx.Ct);
return (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
}
await UploadAsync("IMG_0004.JPG", 1);
// A desktop sharing this server's archive, with its own index of the four photos.
await using var desktopDb = await TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(Context.CreateTempDirectory("desktop"), "titano.db")), fx.Ct);
var desktop = new ArchiveService(desktopDb, new ArchiveServiceOptions { Owner = "desktop", LeaseWait = TimeSpan.FromSeconds(20) });
var desktopArchive = await desktop.OpenAsync(fx.Archive.RootPath, fx.Ct);
Task<ScanSummary> DesktopScanAsync() => desktop.Indexer.ScanAsync(desktopArchive, ScanMode.Incremental, null, _ => ValueTask.CompletedTask, fx.Ct);
await DesktopScanAsync();
// The server takes a fifth photo before the desktop scans again.
var uploaded = await UploadAsync("IMG_0005.JPG", 2);
Assert.Equal(uploaded.FramesVersion - 1, (await desktopDb.Sequences.GetAsync(sequence.Id, fx.Ct))!.FramesVersion);
// The sidecar is damaged; the desktop's scan rebuilds it from the photos at the first version, the fifth photo under
// an id of its own, and writes it one version past its own row: the version the server holds for the photo as it
// filed it.
await File.WriteAllTextAsync(folder.ManifestPath, "{", fx.Ct);
Assert.SequenceEqual([sequence.Id], (await DesktopScanAsync()).Sequences);
var rebuilt = ManifestStore.ReadSequence(folder.ManifestPath);
Assert.Equal(uploaded.FramesVersion, rebuilt.Versions.Frames);
Assert.NotEqual((await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct))[^1].Id, rebuilt.Frames[^1].Id);
// The server's scan finds other frames at the version it holds: it indexes them one version past it, in both places,
// so an editor holding that version for the photo as it was is refused.
Assert.SequenceEqual([sequence.Id], (await fx.ScanAsync()).Sequences);
var indexed = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.Equal(uploaded.FramesVersion + 1, indexed.FramesVersion);
Assert.Equal(indexed.FramesVersion, ManifestStore.ReadSequence(folder.ManifestPath).Versions.Frames);
Assert.SequenceEqual(rebuilt.Frames.Select(f => f.Id), (await fx.Db.Frames.ListBySequenceAsync(sequence.Id, cancellationToken: fx.Ct)).Select(f => f.Id));
var edit = await fx.Db.Sequences.EditAsync(sequence.Id, new SequenceEdit { Rating = 2 }, null, uploaded.FramesVersion, fx.Ct);
Assert.Equal(SequenceEditOutcome.Conflict, edit.Outcome);
// The desktop follows, and neither index finds anything more to do.
Assert.SequenceEqual([sequence.Id], (await DesktopScanAsync()).Sequences);
Assert.Equal(indexed.FramesVersion, (await desktopDb.Sequences.GetAsync(sequence.Id, fx.Ct))!.FramesVersion);
Assert.Empty((await fx.ScanAsync()).Sequences);
Assert.Empty((await DesktopScanAsync()).Sequences);
}
[Test]
public async Task AVerifyStampedWhileASettingsEditCommitsLeavesTheEdit()
{