fix(editor): name the frames version in the remote editor's saves

The desktop editor of a server sequence relied on the server's
sequenceChanged event to go read-only when frames changed. Scans publish
none, and an event missed while the socket reconnected was never noticed,
so a save made meanwhile passed the settings-version check and wrote
positions in the old order over the ones the server had moved.

The PATCH now carries expectedFramesVersion, the frames version of the
proxies the editor holds. On 409 the editor reads the manifest: other
frames make it outdated (read-only, Get proxies; the edit stays pending),
the same frames at a new version retry at that version. After a lost event
socket the frames are compared again. Servers that predate the field
ignore it.

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:14:04 +00:00
1 parent 31dea66270
commit 678a827b42
3 files changed
+73 -10

No files matched your search

+14 -6
View File
@@ -31,7 +31,8 @@ namespace Titano.App.Editor;
/// local archive. Analyses and renders are server jobs; their state and progress come from the server's events.
/// Project settings name frames by position, so the cached frames must be the server's: a load that finds other frames
/// throws <see cref="ProxiesOutdatedException"/>, and frames that change on the server while the sequence is open make
/// it <see cref="IsOutdated"/> (read-only, nothing saved or rendered).
/// it <see cref="IsOutdated"/> (read-only, nothing saved or rendered). Saves name the frames version the editor's frames
/// are at, so the server refuses one made against frames it no longer has even before its event arrives.
/// </summary>
public sealed class RemoteSequenceSource : ISequenceSource
{
@@ -150,19 +151,24 @@ public sealed class RemoteSequenceSource : ISequenceSource
if (changedThere && ProjectMerge.Conflicts(basis, project, stored) is { Count: > 0 } conflicts)
throw new ProjectConflictException(Loc.L("Editor.Error.SaveConflict"), stored, conflicts);
var hero = merged.HeroFrame == stored.HeroFrame ? (Guid?)null : HeroFrameId(merged);
// The positions name the frames this editor holds: the server refuses them (409 frames_conflict) once its
// frames changed, also before its event says so. A server that predates the check ignores it.
var request = new UpdateSequenceRequest(null, null, null, null, merged.ToJson(), version, hero, Volatile.Read(ref _framesVersion));
try
{
var updated = await Call(() => _api.UpdateSequenceAsync(Id, new UpdateSequenceRequest(null, null, null, null, merged.ToJson(), version, hero),
cancellationToken));
var updated = await Call(() => _api.UpdateSequenceAsync(Id, request, cancellationToken));
Volatile.Write(ref _stored, new Stored(merged, updated.SettingsVersion));
return merged;
}
catch (TitanoApiException ex) when (ex.Status == HttpStatusCode.Conflict)
{
// Changed on the server since this editor read it: merge again on top of the server's settings.
if (attempt == SaveAttempts) throw new EditorException(Loc.L("Editor.Error.SaveConflict"), ex);
// Changed on the server since this editor read it, its settings or its frames: other frames make the
// editor outdated (its proxies are not the server's), otherwise the edit merges again on top of the
// server's settings, at the frames version they are at.
var manifest = await Call(() => _api.GetManifestAsync(Id, cancellationToken));
if (!SameFrames(manifest)) throw Outdated();
if (attempt == SaveAttempts) throw new EditorException(Loc.L("Editor.Error.SaveConflict"), ex);
Volatile.Write(ref _framesVersion, manifest.FramesVersion);
Volatile.Write(ref _stored, new Stored(Parse(manifest.SettingsJson), manifest.SettingsVersion));
}
}
@@ -219,7 +225,7 @@ public sealed class RemoteSequenceSource : ISequenceSource
/// <summary>
/// Follows the server's events until the editor closes, reconnecting with a growing delay (job states lost meanwhile
/// are read back from the jobs). Nothing that fails on the way ends it.
/// are read back from the jobs, and the frames are compared again). Nothing that fails on the way ends it.
/// </summary>
private async Task ListenAsync(CancellationToken cancellationToken)
{
@@ -244,6 +250,8 @@ public sealed class RemoteSequenceSource : ISequenceSource
var delay = Math.Min(MaxBackoff.Ticks, MinBackoff.Ticks << Math.Min(failures++, 10));
await Task.Delay(TimeSpan.FromTicks(delay), cancellationToken).ConfigureAwait(false);
await RefreshTrackedAsync(cancellationToken).ConfigureAwait(false);
// A frames change announced while the socket was down is found now rather than at the next save.
if (Volatile.Read(ref _framesVersion) >= 0) await CheckFramesAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{