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

@@ -151,6 +151,89 @@ public sealed class EditorSessionTests
}
}
[Test]
public async Task ARenderAfterFramesWereInsertedEmbedsThePositionsOfTheFramesTheUserChose()
{
var (session, source) = OpenShort();
await using (session)
{
Assert.True(session.SetExcluded([3], true));
Assert.True(session.SetHero(4));
Assert.True(await session.FlushAsync());
var frames = session.Content.Frames;
// Two earlier photos are inserted and the index moves the stored positions; the user renders without an edit.
InsertEarlier(source, 2);
source.Stored = source.Stored with { ExcludedFrames = [5], HeroFrame = 6 };
await session.EnsureFramesAsync();
var requests = session.RenderRequests(session.Project.Export);
Assert.Equal(frames.Count + 2, session.Content.Count, "the frames were read again");
var parameters = JsonSerializer.Deserialize(requests[0].ParametersJson!, ProtocolJson.Default.RenderJobParameters)!;
var embedded = ProjectSettings.FromJson(parameters.SettingsJson!);
Assert.SequenceEqual([5], embedded.ExcludedFrames);
Assert.Equal(6, embedded.HeroFrame);
Assert.Equal(frames[3].Id, session.Content.Frames[embedded.ExcludedFrames[0]].Id);
Assert.Equal(frames[4].Id, session.Content.Frames[embedded.HeroFrame!.Value].Id);
Assert.True(session.Undo());
Assert.Null(session.Project.HeroFrame);
Assert.SequenceEqual([5], session.Project.ExcludedFrames, "undo steps name the same frames");
// Frames that did not change are not read again.
var loads = source.Loads;
await session.EnsureFramesAsync();
Assert.Equal(loads, source.Loads);
}
}
[Test]
public async Task AServerSequenceWhoseFramesChangedIsOutdatedBeforeItsRender()
{
var sequence = EditorFixture.Sequence(12);
var content = EditorFixture.Content(sequence, deep: false);
var source = new FakeSequenceSource(sequence, content) { IsRemote = true };
var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20));
await using (session)
{
InsertEarlier(source, 1);
await session.EnsureFramesAsync();
Assert.True(source.IsOutdated);
Assert.True(session.IsReadOnly);
Assert.Equal(0, source.Loads, "its proxies are not the server's frames: nothing is read");
Assert.Equal(12, session.Content.Count);
}
}
[Test]
public async Task ReadsThatOverlapFollowTheFramesInTheOrderTheyWereRead()
{
var (session, source) = OpenShort();
await using (session)
{
Assert.True(session.SetExcluded([3], true));
Assert.True(await session.FlushAsync());
var frames = session.Content.Frames;
// A job ends after an earlier photo was inserted, and its read of the sequence is slow to complete.
InsertEarlier(source, 1);
source.Stored = source.Stored with { ExcludedFrames = [4] };
var slow = new TaskCompletionSource();
source.NextLoadGate = slow.Task;
var first = session.ReloadAsync();
// Another job ends after two more were inserted: its read waits for the first one and follows its frames.
InsertEarlier(source, 2);
source.Stored = source.Stored with { ExcludedFrames = [6] };
var second = session.ReloadAsync();
slow.SetResult();
await Task.WhenAll(first, second);
Assert.Equal(frames.Count + 3, session.Content.Count);
Assert.SequenceEqual([6], session.Project.ExcludedFrames);
Assert.Equal(frames[3].Id, session.Content.Frames[6].Id);
}
}
/// <summary>A short sequence without its analysis, whose frame ids are all different (the synthetic ids repeat every 64 frames).</summary>
private static (EditorSession Session, FakeSequenceSource Source) OpenShort()
{