fix(editor): server jobs, stale proxies and read-only accounts in the remote editor

- A server sequence whose cached frames are no longer the server's (a load, a 409
  merge or a frames change event finds other frame ids) turns read-only and says
  why; opening it, or a sequence without cached proxies, queues the proxy
  download and opens it when done. Signed out reads "Connect to the server".
- Server jobs show queued, running (with a bar), paused and analysing glyphs in
  the header with Cancel; a failed or cancelled one raises a toast with Retry.
  Progress alone no longer refreshes the whole editor.
- The server job list is read by state and kind to its last page; "Add to queue"
  sets the job's priority; the event listener survives any failure and always
  releases its frames and connection.
- An account that may render but not edit picks the preset to render without
  changing the project; preset cards and their batch boxes say why they wait.
- Export tab of a server sequence: no local encoder, notices or folder; no Jobs
  history link. Sync at 12 px beside a folder that keeps 96 px and trims.
- Restore's Undo puts back the project from before the restore, only while that
  restore is the editor's last change.
- Export "Sync" of a render that ends while the session is down is queued for the
  saved session's server; skips are logged; sync follows the engine before it
  starts.
- Capture: sequence-remote-export, -running and -readonly, and
  sequence-export-copies.

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-05 22:15:34 +00:00
1 parent 2813184b85
commit 757695f037
27 files changed
+932 -173

No files matched your search

+187 -36
View File
@@ -3,6 +3,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Titano.App.Infrastructure;
using Titano.App.Jobs;
using Titano.App.Shell;
using Titano.Core.Advice;
using Titano.Core.Analysis;
@@ -42,6 +43,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private readonly Dictionary<Guid, Job> _jobs = [];
private readonly AsyncRelayCommand _analyse;
private readonly AsyncRelayCommand _render;
private readonly AsyncRelayCommand _cancelServerJob;
private PreviewRenderer _renderer;
private int _currentIndex;
private EditorTab _selectedTab;
@@ -64,7 +66,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private bool _previewBusy;
private RenderCorrections? _correctionsValue;
private ExportPlan? _plan;
private int _planVersion;
private bool _planned;
private string? _renderPreset;
private IReadOnlyList<TimelineMarker> _markers = [];
private IThumbnailSource _thumbnails;
private int _playLimit;
@@ -89,6 +93,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
_analyse = new AsyncRelayCommand(AnalyseAsync, () => !IsLocked && !IsAnalysing);
OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsLocked);
_render = new AsyncRelayCommand(() => RenderAsync(JobPriority.User, batch: false), () => CanRender);
_cancelServerJob = new AsyncRelayCommand(CancelServerJobAsync, () => ServerJob is not null);
UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsLocked && Session.History.CanUndo);
RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsLocked && Session.History.CanRedo);
PlayCommand = new RelayCommand(() => TogglePlay(limit: 0));
@@ -111,6 +116,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
session.ContentChanged += OnContentChanged;
session.SaveFailed += OnSaveFailed;
session.Source.JobChanged += OnJobChanged;
session.Source.ReadOnlyChanged += OnReadOnlyChanged;
shell.Services.Sync.Changed += OnSyncChanged;
UpdateMarkers();
RequestCorrections();
@@ -129,21 +135,56 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>A server sequence edited with proxies (the header says where it lives).</summary>
public bool IsRemote => Session.IsRemote;
/// <summary>"Studio NAS" beside the title of a server sequence.</summary>
public string? RemoteText => IsRemote ? Shell.Services.Server.ServerName ?? Loc.L("Server.Label.Server") : null;
/// <summary>The server a server sequence lives on ("Studio NAS"); null for a sequence of this PC.</summary>
public string? ServerName => IsRemote ? Shell.Services.Server.ServerName ?? Loc.L("Server.Label.Server") : null;
public string? RemoteToolTip => IsRemote ? Loc.L("Tooltips.Editor.Remote", RemoteText ?? string.Empty) : null;
/// <summary>"Studio NAS" beside the title of a server sequence; "Studio NAS · read-only" when it is only shown.</summary>
public string? RemoteText => !IsRemote ? null
: IsOutdated ? Loc.L("Editor.Remote.Outdated", ServerName)
: IsReadOnly ? Loc.L("Editor.Remote.ReadOnly", ServerName)
: ServerName;
/// <summary>"Render · 46 %" while an analysis or render of a server sequence runs on the server (the job bar shows this PC's jobs).</summary>
public string? RemoteToolTip => !IsRemote ? null
: IsOutdated ? Loc.L("Tooltips.Editor.Outdated", ServerName)
: IsReadOnly ? Loc.L("Tooltips.Editor.RemoteReadOnly", ServerName)
: Loc.L("Tooltips.Editor.Remote", ServerName);
/// <summary>
/// "Render · 46 %", "Render · queued": the analysis or render of a server sequence the server runs or holds (the job
/// bar shows this PC's jobs); null when there is none.
/// </summary>
public string? ServerJobText => ServerJob is { } job ? EditorText.ServerJob(job) : null;
/// <summary>Frames, speed and time left of the server job.</summary>
public string? ServerJobToolTip => ServerJob is { } job ? EditorText.ServerJobDetail(job, RemoteText ?? string.Empty) : null;
public string? ServerJobToolTip => ServerJob is { } job ? EditorText.ServerJobDetail(job, ServerName ?? string.Empty) : null;
/// <summary>The glyph of the server job (DESIGN §4): ◐ an analysis running, ● a render running, ○ waiting, paused.</summary>
public StatusKind ServerJobKind => ServerJob switch
{
{ State: JobState.Running, Kind: JobKind.DeepAnalyse or JobKind.LightAnalyse } => StatusKind.Analysing,
{ State: JobState.Running } => StatusKind.Running,
{ State: JobState.Paused } => StatusKind.Paused,
_ => StatusKind.Queued,
};
/// <summary>The server job runs and reports how far it is (its progress bar shows).</summary>
public bool HasServerJobProgress => ServerJob is { State: JobState.Running, ProgressTotal: > 0 };
/// <summary>Fraction of the server job done (0–1).</summary>
public double ServerJobProgress => ServerJob is { State: JobState.Running, ProgressTotal: > 0 } job ? (double)job.ProgressDone / job.ProgressTotal : 0;
/// <summary>Cancels the server job (BRIEF §11.5: cancel is always available); the toast that follows offers Retry.</summary>
public ICommand CancelServerJobCommand => _cancelServerJob;
public string? CancelServerJobToolTip => IsRemote ? Loc.L("Tooltips.Editor.ServerJob.Cancel", ServerName) : null;
/// <summary>The Export "Sync" option: available, or why not.</summary>
public ExportSyncGate SyncGate { get => _syncGate; private set => Set(ref _syncGate, value); }
private Job? ServerJob => IsRemote ? _jobs.Values.Where(j => j.State == JobState.Running).OrderBy(j => j.Started).FirstOrDefault() : null;
/// <summary>The server job the header shows: one running, else one paused, else the oldest waiting.</summary>
private Job? ServerJob => IsRemote
? _jobs.Values.OrderBy(j => j.State switch { JobState.Running => 0, JobState.Paused => 1, _ => 2 }).ThenBy(j => j.Started ?? j.Created).FirstOrDefault()
: null;
/// <summary>
/// "3,600 frames · Canon EOS R5 · 2 s interval · 2 h 00 m · 3 warnings"; on the Export tab what the video will be:
@@ -334,19 +375,28 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>An analysis or render of this sequence is running: settings wait, viewing tools stay live.</summary>
public bool IsBusy => _jobs.Values.Any(j => j.State == JobState.Running);
/// <summary>A deep analysis of this sequence is queued or running (Analyse would queue it twice).</summary>
/// <summary>A deep analysis of this sequence is queued, running or paused (Analyse would queue it twice).</summary>
public bool IsAnalysing => _jobs.Values.Any(j => j.Kind == JobKind.DeepAnalyse);
/// <summary>The project is shown, not changed: a server sequence for an account without the Edit right.</summary>
/// <summary>
/// The project is shown, not changed: a server sequence for an account without the Edit right, or one whose frames
/// changed on the server (<see cref="IsOutdated"/>).
/// </summary>
public bool IsReadOnly => Session.IsReadOnly;
/// <summary>The frames on the server are no longer the proxies this PC shows: nothing is saved or rendered until they are fetched again.</summary>
public bool IsOutdated => Session.Source.IsOutdated;
/// <summary>Changes to the project wait (a job runs) or are not allowed (<see cref="IsReadOnly"/>); viewing tools stay live.</summary>
public bool IsLocked => IsReadOnly || IsBusy;
public bool IsEditable => !IsLocked;
/// <summary>Why the controls that change the project are disabled; null while they are not.</summary>
public string? LockedToolTip => IsReadOnly ? Loc.L("Tooltips.Editor.ReadOnly") : IsBusy ? Loc.L("Tooltips.Editor.Busy") : null;
public string? LockedToolTip => IsOutdated ? Loc.L("Tooltips.Editor.Outdated", ServerName)
: IsReadOnly ? Loc.L("Tooltips.Editor.ReadOnly")
: IsBusy ? Loc.L("Tooltips.Editor.Busy")
: null;
/// <summary>What Analyse does and costs ("about 6 min" from the speed of the last analysis), or why it is disabled.</summary>
public string AnalyseToolTip => LockedToolTip
@@ -369,29 +419,55 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public IReadOnlyList<Choice> RenderChoices { get; }
/// <summary>The export preset the Render button renders (choosing another one sets it).</summary>
/// <summary>
/// The export preset the Render button renders: choosing another one sets it in the project, or, for an account that
/// may render but not edit (<see cref="IsReadOnly"/>), only in this editor.
/// </summary>
public Choice? SelectedRenderChoice
{
get => RenderChoices.FirstOrDefault(c => string.Equals((string)c.Value, Plan?.Export.PresetId ?? EditorSettings.ExportPreset.Effective(Session.Project, null),
StringComparison.OrdinalIgnoreCase));
get
{
var id = (IsReadOnly ? _renderPreset : null) ?? Plan?.Export.PresetId ?? EditorSettings.ExportPreset.Effective(Session.Project, null);
return RenderChoices.FirstOrDefault(c => string.Equals((string)c.Value, id, StringComparison.OrdinalIgnoreCase));
}
set
{
if (value?.Value is not string id) return;
Session.Edit(p => p with { Export = p.Export with { Preset = p.Export.Preset.WithManual(id), Overrides = new ExportOverrides() } });
if (!IsReadOnly)
{
Session.Edit(p => p with { Export = p.Export with { Preset = p.Export.Preset.WithManual(id), Overrides = new ExportOverrides() } });
return;
}
if (string.Equals(id, _renderPreset, StringComparison.OrdinalIgnoreCase)) return;
_renderPreset = id;
OnPropertyChanged();
RequestPlan();
}
}
/// <summary>
/// The export Render renders: the project's, or with the preset chosen in the Render menu of a read-only session
/// (the project keeps its own; the batch stays the project's).
/// </summary>
public ExportSettings RenderExport => IsReadOnly && _renderPreset is { } id
? Session.ExportFor(id) with { Batch = Session.Project.Export.Batch }
: Session.Project.Export;
/// <summary>"Render · 4K archive".</summary>
public string RenderText => Loc.L("Editor.Render", Plan?.PresetName ?? string.Empty);
public string RenderToolTip => RenderBlockedReason ?? (IsRemote ? Loc.L("Tooltips.Editor.RenderServer", RemoteText ?? string.Empty) : Loc.L("Tooltips.Editor.Render"));
public string RenderToolTip => RenderBlockedReason ?? (IsRemote ? Loc.L("Tooltips.Editor.RenderServer", ServerName) : Loc.L("Tooltips.Editor.Render"));
/// <summary>The ▾ part of Render: another preset for the project, or only for this render when the project cannot change.</summary>
public string RenderChoiceToolTip => Loc.L(IsReadOnly ? "Tooltips.Editor.RenderChoiceReadOnly" : "Tooltips.Editor.RenderChoice");
public bool CanRender => RenderBlockedReason is null;
/// <summary>Why the project's export cannot be rendered now, localised; null when it can.</summary>
public string? RenderBlockedReason => Plan switch
{
_ when IsRemote && !Shell.Services.Sync.CanRender => Loc.L("Tooltips.Editor.Render.NoRight", RemoteText ?? string.Empty),
_ when IsRemote && !Shell.Services.Sync.CanRender => Loc.L("Tooltips.Editor.Render.NoRight", ServerName),
_ when IsOutdated => Loc.L("Tooltips.Editor.Outdated", ServerName),
null when _planned => Loc.L("Tooltips.Editor.Render.NoSource"),
null => Loc.L("Tooltips.Editor.Render.Planning"),
{ NameError: { } error } => Loc.L("Tooltips.Editor.Render.NameError", error),
@@ -437,10 +513,10 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// </summary>
public async Task RenderAsync(JobPriority priority, bool batch)
{
var export = batch ? Session.Project.Export : Session.Project.Export with { Batch = [] };
var export = batch ? RenderExport : RenderExport with { Batch = [] };
var requests = Session.RenderRequests(export);
foreach (var request in requests) await Session.SubmitAsync(request with { Priority = priority });
if (IsRemote) Shell.Notify(Loc.L("Editor.Render.QueuedServer", RemoteText ?? string.Empty), requests[0].Label);
if (IsRemote) Shell.Notify(Loc.L("Editor.Render.QueuedServer", ServerName), requests[0].Label);
else Shell.Notify(Loc.L("Editor.Render.Queued"), requests[0].Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
}
@@ -449,6 +525,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
_analyse.RaiseCanExecuteChanged();
_render.RaiseCanExecuteChanged();
_cancelServerJob.RaiseCanExecuteChanged();
foreach (var tab in Tabs) tab.RefreshCommands();
CommandManager.InvalidateRequerySuggested();
}
@@ -525,6 +602,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Session.ContentChanged -= OnContentChanged;
Session.SaveFailed -= OnSaveFailed;
Session.Source.JobChanged -= OnJobChanged;
Session.Source.ReadOnlyChanged -= OnReadOnlyChanged;
Shell.Services.Sync.Changed -= OnSyncChanged;
foreach (var tab in Tabs) tab.Dispose();
base.Dispose();
@@ -624,16 +702,16 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
foreach (var tab in Tabs) tab.OnCorrectionsChanged();
}
private void RequestPlan() => _ = RunPlanAsync(Planner, Session.Project);
private void RequestPlan() => _ = RunPlanAsync(Planner, Session.Project, RenderExport, ++_planVersion);
private async Task RunPlanAsync(ExportPlanner planner, ProjectSettings project)
private async Task RunPlanAsync(ExportPlanner planner, ProjectSettings project, ExportSettings export, int version)
{
ExportPlan? plan = null;
try
{
await _plans.Schedule(_ =>
{
plan = planner.Plan(project);
plan = planner.Plan(project, export);
return Task.CompletedTask;
});
}
@@ -641,13 +719,11 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
Log.Warning("editor", "Planning the export failed", ex);
}
if (_disposed || !ReferenceEquals(planner, Planner) || !ReferenceEquals(project, Session.Project)) return;
// A later request (a new project, another render choice) owns the plan.
if (_disposed || !ReferenceEquals(planner, Planner) || version != _planVersion) return;
_planned = true;
Plan = plan;
OnPropertyChanged(nameof(RenderText));
OnPropertyChanged(nameof(RenderToolTip));
OnPropertyChanged(nameof(RenderBlockedReason));
OnPropertyChanged(nameof(CanRender));
OnRenderStateChanged();
OnPropertyChanged(nameof(SelectedRenderChoice));
OnPropertyChanged(nameof(Summary));
foreach (var tab in Tabs) tab.OnPlanChanged();
@@ -793,24 +869,72 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
await Session.SubmitAsync(Session.AnalysisRequest());
// The Jobs screen lists this PC's jobs; a server's analysis shows beside the title.
if (IsRemote) Shell.Notify(Loc.L("Editor.Analyse.QueuedServer", RemoteText ?? string.Empty), Title);
if (IsRemote) Shell.Notify(Loc.L("Editor.Analyse.QueuedServer", ServerName), Title);
else Shell.Notify(Loc.L("Editor.Analyse.Queued"), Title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
}
private void OnJobChanged(Job job)
{
if (!job.TargetIds.Contains(Session.Content.Sequence.Id) || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render)) return;
if (!Concerns(job)) return;
_dispatcher.BeginInvoke(() =>
{
if (_disposed) return;
var wasActive = _jobs.ContainsKey(job.Id);
Track(job);
// Progress alone (several times a second on a server) only moves the server job's text and bar.
if (Track(job)) OnBusyChanged();
else OnServerJobChanged();
LearnAnalysisSpeed(job);
OnBusyChanged();
if (wasActive && job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render ? job : null);
if (!wasActive) return;
if (job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render ? job : null);
else if (IsRemote && job.State is JobState.Failed or JobState.Cancelled) ReportServerJobEnded(job);
});
}
/// <summary>
/// The frames of the server sequence changed while it is open (any thread): everything that changes the project is
/// disabled and saying why, and a toast offers to fetch the proxies again.
/// </summary>
private void OnReadOnlyChanged() => _dispatcher.BeginInvoke(() =>
{
if (_disposed) return;
OnPropertyChanged(nameof(IsReadOnly));
OnPropertyChanged(nameof(IsOutdated));
OnPropertyChanged(nameof(RemoteText));
OnPropertyChanged(nameof(RemoteToolTip));
OnPropertyChanged(nameof(RenderChoiceToolTip));
OnRenderStateChanged();
OnBusyChanged();
if (!IsOutdated) return;
var (id, title) = (Session.Content.Sequence.Id, Title);
Shell.ShowToast(new Toast
{
Title = Loc.L("Editor.Outdated.Title", ServerName),
Message = title,
ActionText = Loc.L("Editor.Outdated.Fetch"),
ActionToolTip = Loc.L("Tooltips.Editor.Outdated.Fetch"),
ActionCommand = new AsyncRelayCommand(() => Shell.Sequence.FetchProxiesAsync(id, title)),
});
});
/// <summary>A server job of this sequence failed or was cancelled: what happened, and Retry (BRIEF §11.5).</summary>
private void ReportServerJobEnded(Job job)
{
var server = ServerName ?? string.Empty;
Shell.ShowToast(new Toast
{
Title = Loc.L("Editor.ServerJob.Ended", JobText.Kind(job.Kind), Loc.L("Jobs.State." + job.State), server),
Message = job.Error ?? job.TargetLabel ?? Title,
ActionText = Loc.L("Jobs.Action.Retry"),
ActionToolTip = Loc.L("Tooltips.Editor.ServerJob.Retry", server),
ActionCommand = new AsyncRelayCommand(() => Session.Source.RetryJobAsync(job.Id, CancellationToken.None), () => !_disposed),
});
}
private async Task CancelServerJobAsync()
{
if (ServerJob is { } job) await Session.Source.CancelJobAsync(job.Id, CancellationToken.None);
}
/// <summary>The session, the sync links or the rights changed (any thread): whether the Export "Sync" option applies.</summary>
private void OnSyncChanged() => _dispatcher.BeginInvoke(() => _ = OnSyncChangedAsync());
@@ -827,11 +951,19 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
}
}
private void Track(Job job)
/// <summary>An analysis or render of this sequence.</summary>
private bool Concerns(Job job) =>
job.TargetIds.Contains(Session.Content.Sequence.Id) && job.Kind is JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render;
/// <summary>Keeps the jobs of this sequence that wait, run or are paused.</summary>
/// <returns>Whether a job joined or left them or changed state (progress alone does not count).</returns>
private bool Track(Job job)
{
if (!job.TargetIds.Contains(Session.Content.Sequence.Id) || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render)) return;
if (job.State is JobState.Queued or JobState.Running) _jobs[job.Id] = job;
else _jobs.Remove(job.Id);
if (!Concerns(job)) return false;
if (job.State is not (JobState.Queued or JobState.Running or JobState.Paused)) return _jobs.Remove(job.Id);
var changed = !_jobs.TryGetValue(job.Id, out var known) || known.State != job.State;
_jobs[job.Id] = job;
return changed;
}
/// <summary>Seconds per frame of the latest finished deep analysis (any sequence): the cost Analyse announces.</summary>
@@ -878,12 +1010,31 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
OnPropertyChanged(nameof(LockedToolTip));
OnPropertyChanged(nameof(AnalyseToolTip));
OnPropertyChanged(nameof(OptimiseAllToolTip));
OnPropertyChanged(nameof(ServerJobText));
OnPropertyChanged(nameof(ServerJobToolTip));
OnServerJobChanged();
foreach (var tab in Tabs) tab.OnBusyChanged();
RefreshCommands();
}
private void OnServerJobChanged()
{
if (!IsRemote) return;
OnPropertyChanged(nameof(ServerJobText));
OnPropertyChanged(nameof(ServerJobToolTip));
OnPropertyChanged(nameof(ServerJobKind));
OnPropertyChanged(nameof(HasServerJobProgress));
OnPropertyChanged(nameof(ServerJobProgress));
_cancelServerJob.RaiseCanExecuteChanged();
}
/// <summary>What Render renders and whether it can (the plan, the rights or the frames changed).</summary>
private void OnRenderStateChanged()
{
OnPropertyChanged(nameof(RenderText));
OnPropertyChanged(nameof(RenderToolTip));
OnPropertyChanged(nameof(RenderBlockedReason));
OnPropertyChanged(nameof(CanRender));
}
/// <summary>A rendered preview as frozen bitmaps and overlays in picture pixels (built off the UI thread).</summary>
private sealed record PreviewResult(ImageSource Corrected, ImageSource Original, Rect Crop, IReadOnlyList<Point> Horizon, IReadOnlyList<MotionVector> Vectors,
ImageSource? Waveform)