fix(sync): send wanted proxies of unverified originals and recount them

Wanted proxies were matched to this PC's originals by SHA-256 only, and
frames adopted from a folder stay unhashed until verified. A desktop that
uploaded an adopted HEIC folder counted none of the proxies the server asked
for, showed the link in sync and sent none of them. The upload now keeps the
hash it computes for each original the index has none for and makes the
proxies from those too; the comparison counts a wanted frame no hash matched
against an unhashed original this PC reads by size (the server names its copy
by its own template, so not by name).

The wanted count was recomputed only when frame or render counters moved, so
proxies a render node sent left the row "Local ahead" with an upload that
sent nothing, and proxies the server started asking for later were never
counted. A link whose copy may make proxies for the server now keeps the
server's update time of the last comparison (sync_links.diff_remote_updated_at,
migration 0006) and is compared again when it moved.

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 11:06:53 +00:00
1 parent f215b99ca5
commit 17311cc459
9 files changed
+198 -18

No files matched your search

+22 -9
View File
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Globalization;
using System.Net;
using Titano.Core.Archiving;
@@ -50,12 +51,16 @@ internal sealed class SyncTransfers(SyncService sync)
var progress = new TransferProgress(context, frames.Count, frames.Count - pending.Count);
await progress.ReportAsync().ConfigureAwait(false);
var skipped = 0;
// The SHA-256 of each original the index has none for (a folder adopted and not verified), as its upload computes
// it: the proxies the server asks for are matched to this PC's originals by content. Every such original is
// pending, so each one still here is hashed.
var hashes = new ConcurrentDictionary<Guid, string>();
// Without a server sequence the originals go out one by one under this sequence's session key until the
// server has filed one, which creates the sequence (an original it already holds elsewhere creates nothing).
while (remoteId is null && pending.TryDequeue(out var first))
{
var sent = await UploadFrameAsync(context, remote, null, SyncService.SessionKey(local.Id), paths.FromRelative(first.RelativePath), first, ct)
var sent = await UploadFrameAsync(context, remote, null, SyncService.SessionKey(local.Id), paths.FromRelative(first.RelativePath), first, hashes, ct)
.ConfigureAwait(false);
if (sent is null) skipped++;
else if (sent.SequenceId != Guid.Empty)
@@ -70,11 +75,11 @@ internal sealed class SyncTransfers(SyncService sync)
await Parallel.ForEachAsync(pending, Workers(sync.Options.Uploads, ct), async (frame, token) =>
{
if (await UploadFrameAsync(context, remote, target, null, paths.FromRelative(frame.RelativePath), frame, token).ConfigureAwait(false) is null)
if (await UploadFrameAsync(context, remote, target, null, paths.FromRelative(frame.RelativePath), frame, hashes, token).ConfigureAwait(false) is null)
Interlocked.Increment(ref skipped);
await progress.StepAsync().ConfigureAwait(false);
}).ConfigureAwait(false);
await SendProxiesAsync(context, remote, target, local, paths, frames).ConfigureAwait(false);
await SendProxiesAsync(context, remote, target, local, paths, frames, hashes).ConfigureAwait(false);
if (created) await sync.PushAllAsync(remote, target, ct).ConfigureAwait(false);
await sync.RecompareAsync(remote, target, ct).ConfigureAwait(false);
@@ -83,17 +88,23 @@ internal sealed class SyncTransfers(SyncService sync)
/// <summary>
/// The proxies the server asks for (<see cref="ManifestFrame.WantsProxy"/>) that this PC's decoders can make from its
/// originals, made as the server's proxy policy says with the server's capture data, and sent. One the server refuses
/// is counted in the job log; a server that makes no proxies, or an account that may not send them, ends the pass; a
/// originals (by their archived SHA-256, or the one <paramref name="hashes"/> holds for an original the index has none
/// for), made as the server's proxy policy says with the server's capture data, and sent. One the server refuses is
/// counted in the job log; a server that makes no proxies, or an account that may not send them, ends the pass; a
/// server busy or out of reach fails the job like an original would.
/// </summary>
private async Task SendProxiesAsync(JobContext context, ISyncRemote remote, Guid remoteId, Sequence local, ArchivePaths paths, IReadOnlyList<Frame> frames)
private async Task SendProxiesAsync(JobContext context, ISyncRemote remote, Guid remoteId, Sequence local, ArchivePaths paths, IReadOnlyList<Frame> frames,
IReadOnlyDictionary<Guid, string> hashes)
{
var ct = context.Cancellation;
var manifest = await remote.GetManifestAsync(remoteId, ct).ConfigureAwait(false);
var wanted = manifest.Frames.Where(f => f.WantsProxy).ToList();
if (manifest.Proxies is not { } spec || wanted.Count == 0) return;
var originals = frames.Where(f => f.Sha256 is not null).GroupBy(f => f.Sha256!.ToLowerInvariant()).ToDictionary(g => g.Key, g => g.First(), StringComparer.Ordinal);
var originals = new Dictionary<string, Frame>(StringComparer.Ordinal);
foreach (var frame in frames)
{
if ((frame.Sha256 ?? hashes.GetValueOrDefault(frame.Id)) is { } sha) originals.TryAdd(sha.ToLowerInvariant(), frame);
}
var records = (await remote.ListFramesAsync(remoteId, ct).ConfigureAwait(false)).ToDictionary(f => f.Id);
var camera = new SidecarCamera { Make = local.CameraMake, Model = local.CameraModel, Serial = local.CameraSerial };
var decoder = sync.Options.Archive.Decoder;
@@ -443,10 +454,11 @@ internal sealed class SyncTransfers(SyncService sync)
/// <summary>
/// Hashes the original again and sends it into <paramref name="sequenceId"/> (or the sequence of
/// <paramref name="sessionKey"/>); null (logged) when it is gone or no longer the archived file.
/// <paramref name="sessionKey"/>); null (logged) when it is gone or no longer the archived file. The hash of an
/// original the index has none for goes into <paramref name="hashes"/>.
/// </summary>
private static async Task<CompleteUploadResponse?> UploadFrameAsync(JobContext context, ISyncRemote remote, Guid? sequenceId, string? sessionKey, string path,
Frame frame, CancellationToken cancellationToken)
Frame frame, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken)
{
if (!File.Exists(path))
{
@@ -454,6 +466,7 @@ internal sealed class SyncTransfers(SyncService sync)
return null;
}
var sha = await TitanoClient.HashFileAsync(path, cancellationToken).ConfigureAwait(false);
if (frame.Sha256 is null) hashes[frame.Id] = sha;
if (frame.Sha256 is { } archived && !archived.Equals(sha, StringComparison.OrdinalIgnoreCase))
{
context.Log($"{frame.FileName}: changed since it was archived, not uploaded");