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:
6 files changed
+123
-19
No files matched your search
@@ -39,6 +39,12 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
/// <summary>Proxy and thumbnail downloads fail with a server error.</summary>
|
||||
public bool FailAssets { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Assets (frame id, kind) the sequence's flags offer that the server has not drawn yet: frames added since its last
|
||||
/// thumbnail or proxy pass answer 404 until that pass ends, as the real endpoints do.
|
||||
/// </summary>
|
||||
public HashSet<(Guid Frame, string Kind)> Undrawn { get; } = [];
|
||||
|
||||
/// <summary>Proxies clients sent, by frame id (for sequences the server cannot decode).</summary>
|
||||
public Dictionary<Guid, byte[]> SentProxies { get; } = [];
|
||||
|
||||
@@ -174,6 +180,7 @@ internal sealed class FakeSyncRemote : ISyncRemote
|
||||
"original" when CorruptOnce == frameId => [.. frame.Bytes.Select(b => (byte)~b)],
|
||||
"original" => frame.Bytes,
|
||||
"proxy" or "thumb" when FailAssets => throw new TitanoApiException(HttpStatusCode.InternalServerError, new ApiError("internal", "failed")),
|
||||
"proxy" or "thumb" when Undrawn.Contains((frameId, kind)) => throw NotFound(),
|
||||
// A proxy a client or render node sent is served as soon as it is filed, like the manifest says.
|
||||
"proxy" when SentProxies.TryGetValue(frameId, out var sent) => sent,
|
||||
"proxy" when (sequence.Status & SequenceStatus.ProxiesBuilt) != 0 => frame.Proxy,
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -420,6 +420,41 @@ public sealed class SyncTransferTests(TestContext context)
|
||||
Assert.False((await f.EntryAsync("Fog")).Link!.ProxiesStale);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ACacheMadeBeforeTheServerDrewItsNewFramesStaysStaleUntilItHasTheirProxies()
|
||||
{
|
||||
await using var f = await SyncFixture.CreateAsync(context);
|
||||
var remote = f.Remote.Add("Harbour", f.NewPhotos(2));
|
||||
await f.RefreshAsync();
|
||||
var engine = await f.StartEngineAsync();
|
||||
var job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Proxies, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
Assert.False((await f.EntryAsync("Harbour")).Link!.ProxiesStale);
|
||||
|
||||
// Two photos reach the server. Its proxy flag stays set until its next proxy pass, which has not drawn them yet:
|
||||
// the first has its thumbnail only, the second nothing at all.
|
||||
var added = f.NewPhotos(2).Select(photo => remote.AddFrame(photo)).ToList();
|
||||
f.Remote.Undrawn.UnionWith([(added[0].Id, "proxy"), (added[1].Id, "proxy"), (added[1].Id, "thumb")]);
|
||||
await f.RefreshAsync();
|
||||
job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Proxies, null);
|
||||
await f.Archive.WaitForAsync(job.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.Take(3).Select(file => (int)new FileInfo(file!).Length));
|
||||
Assert.Null(opened.Files[3]);
|
||||
Assert.True((await f.EntryAsync("Harbour")).Link!.ProxiesStale, "a thumbnail or a missing file stands in for a proxy the server offers");
|
||||
|
||||
// The pass draws them: the frames stay as they were, the server's sequence records the pass.
|
||||
f.Remote.Undrawn.Clear();
|
||||
remote.UpdatedAt = DateTimeOffset.UtcNow.AddSeconds(1);
|
||||
await f.RefreshAsync();
|
||||
Assert.True((await f.EntryAsync("Harbour")).Link!.ProxiesStale);
|
||||
job = await f.Sync.EnqueueDownloadAsync(engine, f.Server, remote.Id, "Harbour", SyncDownloadMode.Proxies, null);
|
||||
await f.Archive.WaitForAsync(job.Id, JobState.Done);
|
||||
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("Harbour")).Link!.ProxiesStale);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheServersRendersAreFetchedIntoTheLocalExports()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user