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

@@ -18,6 +18,7 @@ namespace Titano.App.Tests.Editor;
internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Guid> frames) : IRemoteSequenceApi
{
private readonly Lock _gate = new();
private readonly TaskCompletionSource _subscribed = new(TaskCreationOptions.RunContinuationsAsynchronously);
private Channel<ServerEvent> _events = Channel.CreateUnbounded<ServerEvent>();
/// <summary>The server's frames in order (another list when frames are added or removed on the server).</summary>
@@ -55,6 +56,9 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
public bool Disposed { get; private set; }
/// <summary>Completes once the editor's listener has opened an event stream (the stream open then is the one it reads).</summary>
public Task Subscribed => _subscribed.Task;
/// <summary>A job of the server, as <c>GET /jobs/{id}</c> returns it.</summary>
public JobDto Job(Guid id, string kind, string state, Guid? target = null, long done = 0, long total = 0) =>
new(id, kind, [target ?? sequence.Id], sequence.DisplayTitle, state, "user", done, total, null, null, null, null, 0, null, DateTimeOffset.UtcNow,
@@ -168,6 +172,7 @@ internal sealed class FakeRemoteSequenceApi(Sequence sequence, IReadOnlyList<Gui
public async IAsyncEnumerable<ServerEvent> EventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
{
var events = Volatile.Read(ref _events).Reader;
_subscribed.TrySetResult();
while (await events.WaitToReadAsync(cancellationToken))
{
while (events.TryRead(out var e)) yield return e;