fix(sync): compare stand-ins again after a proxy download that did not finish

The agent recorded the server's update time for a cache of stand-in
thumbnails before the proxy download it queued, so a download that failed
(server restart, network drop) was never queued again once its backoff
ended: the server's sequence may never change again. A comparison that
offers proxies is now recorded only once their download is queued, and
dropped when that download ends other than done.

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:53 +00:00
1 parent 827b224ee3
commit 9ca10d96f4
2 files changed
+46 -3

No files matched your search

@@ -192,6 +192,41 @@ public sealed class SyncAgentTests(TestContext context)
Assert.Count(2, await DownloadsAsync(f));
}
[Test]
public async Task AStandInDownloadThatFailedIsQueuedAgainAfterItsBackoff()
{
await using var f = await SyncFixture.CreateAsync(context);
var remote = f.Remote.Add("Fog", f.NewPhotos(3), status: SequenceStatus.ThumbsBuilt);
remote.Undecodable = true;
var engine = await f.StartEngineAsync();
await f.RefreshAsync();
var first = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Fog", SyncDownloadMode.Proxies, null);
await f.Archive.WaitForAsync(first.Id, JobState.Done);
await using var agent = new SyncAgent(f.Sync, f.Remote, () => new SyncPolicy(KeepProxiesOffline: true), engine, EventsOnly);
agent.Start();
await WaitAsync(() => agent.Snapshot is not null, "first comparison");
// Two frames' proxies reach the server, but their download fails (the server restarts meanwhile).
foreach (var frame in remote.Frames.Take(2)) f.Remote.SentProxies[frame.Id] = frame.Proxy;
remote.UpdatedAt = DateTimeOffset.UtcNow.AddSeconds(1);
f.Remote.FailAssets = true;
await agent.RefreshAsync(f.Ct);
var failed = Assert.Contains(await DownloadsAsync(f), j => j.Id != first.Id);
await f.Archive.WaitForAsync(failed.Id, JobState.Failed);
// The server's sequence does not change again: once the backoff has passed, the download is queued anyway.
f.Remote.FailAssets = false;
await WaitAsync(async () =>
{
await agent.RefreshAsync(f.Ct);
return (await DownloadsAsync(f)).Count == 3;
}, "the download queued again");
var retry = Assert.Contains(await DownloadsAsync(f), j => j.Id != first.Id && j.Id != failed.Id);
await f.Archive.WaitForAsync(retry.Id, JobState.Done);
var opened = Assert.NotNull(f.Sync.OpenRemote(f.Server, remote.Id));
Assert.SequenceEqual([remote.Frames[0].Proxy.Length, remote.Frames[1].Proxy.Length, 64], opened.Files.Select(file => (int)new FileInfo(file!).Length));
}
private static async Task<IReadOnlyList<Job>> DownloadsAsync(SyncFixture f) =>
(await f.Db.Jobs.ListAsync(null, JobKind.Download, 100, null, f.Ct)).Items;