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

@@ -159,7 +159,7 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
Assert.Same(conflict, session.Conflict);
Assert.False(await session.FlushAsync(), "the change waits for the choice");
Assert.True(session.ResolveConflict(keepMine: true));
Assert.True(await session.FlushAsync());
Assert.True(await FlushAfterChoiceAsync(session));
Assert.Null(session.Conflict);
var stored = ProjectSettings.FromJson(api.SettingsJson!);
@@ -181,7 +181,7 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
await found.Task.WaitAsync(TimeSpan.FromSeconds(10));
Assert.True(session.ResolveConflict(keepMine: false));
Assert.True(await session.FlushAsync());
Assert.True(await FlushAfterChoiceAsync(session));
var stored = ProjectSettings.FromJson(api.SettingsJson!);
Assert.Equal((0.3, -0.2, (int?)2), (stored.Exposure.ExposureOffsetEv, stored.Camera.OffsetY, stored.HeroFrame),
"the server's values where both changed; the editor's other change is saved");
@@ -469,6 +469,8 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
await using (source)
{
await source.LoadAsync(context.Cancellation);
// The listener reads the stream open when it subscribes: it must have subscribed for the drop to reach it.
await api.Subscribed.WaitAsync(TimeSpan.FromSeconds(10), context.Cancellation);
api.DropEvents();
api.Frames = [.. remote.Frames.Skip(1).Select(f => f.Id)];
api.FramesVersion = 2;
@@ -478,6 +480,30 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
}
}
[Test]
public async Task ARenderIsRefusedOnceTheServersFramesChangedWithoutAnEvent()
{
var (source, api, remote) = Open();
await using (source)
{
await source.LoadAsync(context.Cancellation);
// A new frames version over the same frames: they are still this PC's.
api.FramesVersion = 2;
Assert.True(await source.FramesCurrentAsync(context.Cancellation));
Assert.False(source.IsOutdated);
// A server scan inserts an earlier photo and sends no event: the check before a render finds it.
api.Frames = [Guid.CreateVersion7(), .. remote.Frames.Select(f => f.Id)];
api.FramesVersion = 3;
Assert.False(await source.FramesCurrentAsync(context.Cancellation));
Assert.True(source.IsOutdated);
var refused = await Assert.ThrowsAsync<ProxiesOutdatedException>(() =>
source.SubmitAsync(ProcessingJobs.Render(remote.Sequence, new ExportSettings(), 1920, 1080), context.Cancellation));
Assert.Equal(Loc.L("Editor.Error.FramesChanged"), refused.Message);
Assert.Empty(api.Posted);
}
}
[Test]
public async Task AConflictFoundOnOtherFramesIsNotMergedOntoThem()
{
@@ -591,6 +617,13 @@ public sealed class RemoteSequenceSourceTests(TestContext context)
lock (seen) return seen[^1];
}
/// <summary>
/// Stores the change after the user settled a conflict. The test's thread is not the saver's: a retry that started
/// before the choice may still be failing on the old basis, and a flush that arrives meanwhile reports it, so one more
/// flush (on the UI thread the choice cannot land inside a retry) is answered by the attempt made after the choice.
/// </summary>
private static async Task<bool> FlushAfterChoiceAsync(EditorSession session) => await session.FlushAsync() || await session.FlushAsync();
private static async Task WaitAsync(Func<bool> condition)
{
for (var i = 0; i < 200; i++)