fix(sync): keep a proxy cache stale while any frame lacks its proxy

A proxy download marked the cache filled whenever the server's sequence had
ProxiesBuilt, even when frames added since the server's last proxy pass got
a thumbnail or nothing (the flag offers their proxies, the endpoints answer
404 until the pass draws them), and frames without any cached file were not
counted at all. The agent never compared such a cache again, so the editor
kept thumbnails or blank frames until the frames changed.

The cache now counts as filled only when every frame, missing or damaged
ones aside, is cached as a proxy. On a server with ProxiesBuilt, a download
that left stand-ins is queued again once the server's update time moves, so
a frame the server cannot serve yet is not fetched at every refresh.

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 21:37:07 +00:00
1 parent d064719c11
commit 098e5b27f6
6 files changed
+123 -19

No files matched your search

@@ -192,6 +192,45 @@ public sealed class SyncAgentTests(TestContext context)
Assert.Count(2, await DownloadsAsync(f));
}
[Test]
public async Task FramesTheServerHadNotDrawnAreFetchedAgainOnceItDid()
{
await using var f = await SyncFixture.CreateAsync(context);
var remote = f.Remote.Add("Construction cam", f.NewPhotos(2));
var engine = await f.StartEngineAsync();
await f.RefreshAsync();
var first = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Construction cam", 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");
// A photo reaches the server, whose proxy flag stays set until its next proxy pass draws the photo: the refresh
// that follows the upload caches nothing for it.
var added = remote.AddFrame(f.NewPhotos(1)[0]);
f.Remote.Undrawn.UnionWith([(added.Id, "proxy"), (added.Id, "thumb")]);
await agent.RefreshAsync(f.Ct);
var refresh = Assert.Contains(await DownloadsAsync(f), j => j.Id != first.Id);
await f.Archive.WaitForAsync(refresh.Id, JobState.Done);
Assert.Null(Assert.NotNull(f.Sync.OpenRemote(f.Server, remote.Id)).Files[2]);
Assert.True((await f.EntryAsync("Construction cam")).Link!.ProxiesStale);
// Nothing is fetched again while the server's sequence stands still.
await agent.RefreshAsync(f.Ct);
Assert.Count(2, await DownloadsAsync(f));
// The pass draws the photo and records the sequence's state.
f.Remote.Undrawn.Clear();
remote.UpdatedAt = DateTimeOffset.UtcNow.AddSeconds(1);
await agent.RefreshAsync(f.Ct);
var drawn = Assert.Contains(await DownloadsAsync(f), j => j.Id != first.Id && j.Id != refresh.Id);
await f.Archive.WaitForAsync(drawn.Id, JobState.Done);
var opened = Assert.NotNull(f.Sync.OpenRemote(f.Server, remote.Id));
Assert.SequenceEqual(remote.Frames.Select(r => (long)r.Proxy.Length), opened.Files.Select(file => new FileInfo(file!).Length));
Assert.False((await f.EntryAsync("Construction cam")).Link!.ProxiesStale);
await agent.RefreshAsync(f.Ct);
Assert.Count(3, await DownloadsAsync(f));
}
[Test]
public async Task AStandInDownloadThatFailedIsQueuedAgainAfterItsBackoff()
{