fix(sync): resolve conflicts against the versions shown, isolate failures, renders on request

- Conflicts are settled against the versions the user was shown; a later change on
  either side refuses the choice and compares again. Title, tags, rating and notes
  changed differently on both sides are a conflict too (no silent tag union).
- Links are written under the engine's gate and forgotten only after a 404; linked
  local copies are read by id; unlinked copies with the same originals are linked
  by content.
- A failure on one sequence is recorded on its link; the others are still compared.
- Downloads hash unverified local copies first and restore originals missing here.
- Background proxy downloads give way to the user's requests; "Keep proxies offline"
  refreshes the caches of sequences opened with proxies, checks free space and backs
  off after a failure.
- Renders travel on request: Send exports (chunked, hash-verified upload keeping the
  render id; new POST /sequences/{id}/renders endpoints) and Get exports.
- Server screen: stable row buttons, mockup column grid, Tab through rows, conflict
  rows first on the card colour, localised conflict detail, Save both confirmation,
  Pause metered uploads, culture switch, Library one-word sync glyphs.

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-03 10:26:56 +00:00
1 parent 3601e0a47f
commit 2d40a613b9
48 files changed
+2498 -465

No files matched your search

+33 -7
View File
@@ -27,8 +27,8 @@ public sealed record SyncAgentOptions
/// and every <see cref="SyncAgentOptions.RefreshInterval"/>; the sequences named by the server's <c>sequenceChanged</c>
/// events (WebSocket) compared again within a second, except those an upload or download is working on (it compares
/// them when it ends); failures retried with exponential backoff; and, with
/// <see cref="SyncPolicy.KeepProxiesOffline"/>, proxy downloads queued for every server sequence without local
/// originals whose cache is stale. Dispose to stop.
/// <see cref="SyncPolicy.KeepProxiesOffline"/>, background downloads that bring stale proxy caches of the sequences
/// this PC opened with proxies up to date (a failed one waits with the same backoff). Dispose to stop.
/// </summary>
public sealed class SyncAgent : IAsyncDisposable
{
@@ -43,6 +43,11 @@ public sealed class SyncAgent : IAsyncDisposable
private readonly Channel<bool> _refreshWake = Channel.CreateBounded<bool>(new BoundedChannelOptions(1) { FullMode = BoundedChannelFullMode.DropWrite });
private readonly Channel<bool> _eventWake = Channel.CreateBounded<bool>(new BoundedChannelOptions(1) { FullMode = BoundedChannelFullMode.DropWrite });
private readonly ConcurrentDictionary<Guid, byte> _changed = new();
/// <summary>Proxy downloads this agent queued, by server id, and the failures of each sequence's last ones.</summary>
private readonly Dictionary<Guid, Guid> _proxyJobs = [];
private readonly Dictionary<Guid, (int Failures, DateTime NotBefore)> _proxyFailures = [];
private readonly SemaphoreSlim _refreshing = new(1, 1);
private Task _running = Task.CompletedTask;
private SyncSnapshot? _snapshot;
@@ -200,8 +205,9 @@ public sealed class SyncAgent : IAsyncDisposable
var due = ids.Where(id => !busy.Contains(id)).ToList();
if (due.Count > 0) await _sync.RefreshSequencesAsync(_remote, due, _policy(), cancellationToken).ConfigureAwait(false);
}
catch (Exception ex) when (ex is not OperationCanceledException)
catch (Exception ex) when (!cancellationToken.IsCancellationRequested)
{
// Includes timeouts reported as cancellation: the loop goes on and a full comparison catches up.
Log.Warning(LogCategory, $"Comparing changed sequences of {Server} failed", ex);
RequestRefresh();
}
@@ -212,14 +218,34 @@ public sealed class SyncAgent : IAsyncDisposable
}
}
/// <summary>Queues (background priority) the proxies of server sequences without local originals whose cache is stale.</summary>
/// <summary>
/// Queues (background priority) the proxies of server sequences this PC keeps proxies of, without local originals,
/// whose cache is stale; a sequence whose last download failed waits for its backoff.
/// </summary>
private async Task QueueProxiesAsync(SyncSnapshot snapshot, CancellationToken cancellationToken)
{
foreach (var (remoteId, jobId) in _proxyJobs.ToList())
{
var job = await _sync.Database.Jobs.GetAsync(jobId, cancellationToken).ConfigureAwait(false);
if (job?.State is JobState.Queued or JobState.Running or JobState.Paused) continue;
_proxyJobs.Remove(remoteId);
if (job?.State == JobState.Failed)
{
var failures = _proxyFailures.GetValueOrDefault(remoteId).Failures + 1;
_proxyFailures[remoteId] = (failures, DateTime.UtcNow + Backoff(failures));
}
else
{
_proxyFailures.Remove(remoteId);
}
}
foreach (var entry in snapshot.Entries)
{
if (entry is not { Local: null, Transfer: null, Link: { ServerHasProxies: true, ProxiesStale: true } link }) continue;
await _sync.EnqueueDownloadAsync(_engine!, Server, link.RemoteId, link.Title, SyncDownloadMode.Proxies, null, JobPriority.Background, cancellationToken)
.ConfigureAwait(false);
if (entry is not { Local: null, Transfer: null, Link: { ProxiesCached: > 0, ServerHasProxies: true, ProxiesStale: true } link }) continue;
if (_proxyFailures.TryGetValue(link.RemoteId, out var failed) && DateTime.UtcNow < failed.NotBefore) continue;
var job = await _sync.EnqueueDownloadAsync(_engine!, Server, link.RemoteId, link.Title, SyncDownloadMode.Proxies, null, JobPriority.Background,
cancellationToken).ConfigureAwait(false);
_proxyJobs[link.RemoteId] = job.Id;
}
}