fix(editor): read inserted frames before a render embeds the project

A render queued before the editor had seen frames inserted under it (a sync
download, an import of earlier photos, a scan without an event) embedded the
project's positions in the old frame order. Render now checks first that the
frames read are still the sequence's (ISequenceSource.FramesCurrentAsync: the
row's frames version on this PC, the manifest on a server). On this PC the
sequence is read again and the positions follow the frames; a server
sequence whose frames changed turns outdated and the render is not queued.

Reads of the sequence no longer overlap: a read waits for the one under way,
saves that meet new frames read them through the same slot, and they save
the project as it is once its positions followed. The frame on screen stays
on its photo when frames are inserted or removed before it.

Tests: the event-loss test waits for the listener's subscription before
dropping the stream, and the conflict tests flush once more after the
choice when a retry started before it was still failing.

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 19:59:45 +00:00
1 parent 99a0f37973
commit 827b224ee3
11 files changed
+351 -31

No files matched your search

@@ -156,17 +156,7 @@ public sealed class ProjectStoreTests(TestContext context)
// Three photos taken before the others are found in the folder (a sync download, an import or a scan
// inserts them the same way): the index moves the stored positions with their frames.
var sequence = EditorFixture.Sequence(3);
var first = content.Frames[0].CapturedAt!.Value;
for (var i = 0; i < 3; i++)
{
using var image = sequence.Render(i);
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i] with { CapturedAt = first.AddMinutes(i - 3) });
File.WriteAllBytes(Path.Combine(root, "Synthetic", $"EARLY_{i + 1}.JPG"),
JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90, App1Segments = [exif[4..]] }));
}
var archive = (await db.Archives.GetAsync(content.Sequence.ArchiveId, context.Cancellation))!;
await new ArchiveService(db, options).Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, context.Cancellation);
await InsertEarlierAsync(db, root, content, options, 3);
var moved = ProjectSettings.FromJson((await db.Sequences.GetAsync(sequenceId))!.SettingsJson!);
Assert.SequenceEqual([8], moved.ExcludedFrames);
Assert.Equal(9, moved.HeroFrame);
@@ -195,6 +185,36 @@ public sealed class ProjectStoreTests(TestContext context)
}
}
[Test]
public async Task ARenderAfterEarlierPhotosArriveEmbedsTheFramesTheUserChose()
{
var (db, sequenceId, root) = await ArchiveAsync(10);
await using (db)
{
var options = new ArchiveServiceOptions { Owner = "test", LeaseWait = TimeSpan.FromSeconds(20) };
await using var source = new LocalSequenceSource(db, sequenceId, DecoderFactory.CreateClient(null), null, options);
var content = await source.LoadAsync(context.Cancellation);
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
await using (session)
{
Assert.True(session.SetExcluded([5], true));
Assert.True(await session.FlushAsync());
Assert.True(await source.FramesCurrentAsync(context.Cancellation));
// Earlier photos arrive while the editor is open; the user renders without another edit.
await InsertEarlierAsync(db, root, content, options, 3);
Assert.False(await source.FramesCurrentAsync(context.Cancellation));
await session.EnsureFramesAsync(context.Cancellation);
var request = session.RenderRequests(session.Project.Export)[0];
Assert.True(await source.FramesCurrentAsync(context.Cancellation));
Assert.Equal(13, session.Content.Count);
var embedded = ProjectSettings.FromJson(ProcessingJobs.ReadRender(request.ParametersJson).Parameters.SettingsJson!);
Assert.SequenceEqual([content.Frames[5].Id], embedded.ExcludedFrames.Select(i => session.Content.Frames[i].Id), "the photo the user excluded");
}
}
}
[Test]
public async Task ASaveThatDoesNotReachTheIndexThrows()
{
@@ -249,6 +269,25 @@ public sealed class ProjectStoreTests(TestContext context)
}
}
/// <summary>
/// Writes <paramref name="count"/> photos taken before the sequence's first frame into its folder and scans the
/// archive: they are inserted in front, and the index moves the stored positions with their frames.
/// </summary>
private async Task InsertEarlierAsync(TitanoDatabase db, string root, SequenceContent content, ArchiveServiceOptions options, int count)
{
var sequence = EditorFixture.Sequence(count);
var first = content.Frames[0].CapturedAt!.Value;
for (var i = 0; i < count; i++)
{
using var image = sequence.Render(i);
var exif = ExifWriter.BuildJpegApp1(sequence.Metadata[i] with { CapturedAt = first.AddMinutes(i - count) });
File.WriteAllBytes(Path.Combine(root, "Synthetic", $"EARLY_{i + 1}.JPG"),
JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 90, App1Segments = [exif[4..]] }));
}
var archive = (await db.Archives.GetAsync(content.Sequence.ArchiveId, context.Cancellation))!;
await new ArchiveService(db, options).Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, context.Cancellation);
}
/// <summary>A temporary archive with one adopted folder of synthetic JPEGs, indexed.</summary>
private async Task<(TitanoDatabase Db, Guid SequenceId, string Root)> ArchiveAsync(int frames)
{