fix(proxies): ask again for preview-sized proxies and refuse unwanted ones
Earlier versions made the server's proxies of HEIF frames from their embedded
previews. Those carry the frame's capture time, so the proxy pass kept them
and the sequence stayed marked as having all its proxies; renders and
analysis then read thumbnail-sized files and no client or render node was
asked for a real one. The proxy pass now treats a proxy whose long edge falls
short of the policy's for the frame (its own size when smaller, a tenth of
slack, frames of unknown size not judged) as stale, and the server refuses
such a proxy when one is sent (422 proxy_too_small).
PUT /api/v1/frames/{id}/proxy also took a proxy of a frame the server
decodes itself, replacing its own proxy with any JPEG of the right capture
time; it now answers 422 proxy_not_wanted for those and for frames missing or
damaged. Its follow-up jobs are queued even when the sender disconnects once
the proxy is filed.
A render node cleared the server's Undecodable flag on every frame, so a
damaged frame the server's own render skips was downloaded and failed the
node's job. Only a format the server cannot decode and the node can loses the
flag now; other undecodable originals are neither fetched nor rendered unless
read from their proxy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
9 files changed
+112
-25
No files matched your search
@@ -78,6 +78,34 @@ public sealed class ProxyTests(TestContext context)
|
||||
Assert.False((await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!.Status.HasFlag(SequenceStatus.ProxiesBuilt));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AProxyMadeFromAPreviewIsAskedForAgain()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var (sequence, frames) = await HeifSequenceAsync(fx, 4032, 3024);
|
||||
var folder = fx.Paths.Sequence(sequence.Folder);
|
||||
var images = fx.Service.Images;
|
||||
// An earlier version made the frame's proxy here from the original's embedded preview: the frame's capture time,
|
||||
// a thumbnail's size.
|
||||
Directory.CreateDirectory(folder.Proxies);
|
||||
await File.WriteAllBytesAsync(folder.Proxy(0), Proxy(frames[0].CapturedAt!.Value, 5, 160, 120), fx.Ct);
|
||||
await fx.Db.Sequences.UpdateStatusAsync(sequence.Id, SequenceStatus.ProxiesBuilt, SequenceStatus.None, fx.Ct);
|
||||
|
||||
var proxies = await images.BuildProxiesAsync(fx.Archive, sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
|
||||
|
||||
Assert.Equal((0, 0, 2), (proxies.Built, proxies.Reused, proxies.Undecodable));
|
||||
Assert.FileMissing(folder.Proxy(0));
|
||||
Assert.False((await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!.Status.HasFlag(SequenceStatus.ProxiesBuilt), "asked for again");
|
||||
|
||||
// A client or render node sending one that small is refused; one of the policy's size (1920 px) is kept.
|
||||
var frame = frames[0] with { Width = 4032, Height = 3024 };
|
||||
Assert.Equal(ProxyStoreResult.TooSmall, images.StoreProxy(fx.Archive, sequence, frame, Proxy(frame.CapturedAt!.Value, 6, 160, 120)));
|
||||
Assert.Equal(ProxyStoreResult.Stored, images.StoreProxy(fx.Archive, sequence, frame, Proxy(frame.CapturedAt!.Value, 7, 1920, 1440)));
|
||||
var again = await images.BuildProxiesAsync(fx.Archive, sequence, force: false, 0, (_, _) => ValueTask.CompletedTask, fx.Ct);
|
||||
Assert.Equal((0, 1, 1), (again.Built, again.Reused, again.Undecodable));
|
||||
Assert.FileExists(folder.Proxy(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnArchiveWithoutProxiesRefusesThem()
|
||||
{
|
||||
@@ -90,8 +118,11 @@ public sealed class ProxyTests(TestContext context)
|
||||
Assert.FileMissing(fx.Paths.Sequence(sequence.Folder).Proxy(0));
|
||||
}
|
||||
|
||||
/// <summary>Two ingested frames whose originals the archive engine takes for HEIF (its decoders read none).</summary>
|
||||
private static async Task<(Sequence Sequence, IReadOnlyList<Frame> Frames)> HeifSequenceAsync(ArchiveFixture fx)
|
||||
/// <summary>
|
||||
/// Two ingested frames whose originals the archive engine takes for HEIF (its decoders read none), their size in the
|
||||
/// sidecar <paramref name="width"/> × <paramref name="height"/> when given.
|
||||
/// </summary>
|
||||
private static async Task<(Sequence Sequence, IReadOnlyList<Frame> Frames)> HeifSequenceAsync(ArchiveFixture fx, int? width = null, int? height = null)
|
||||
{
|
||||
Guid id = default;
|
||||
for (var i = 0; i < 2; i++)
|
||||
@@ -103,14 +134,17 @@ public sealed class ProxyTests(TestContext context)
|
||||
var sequence = (await fx.Db.Sequences.GetAsync(id, fx.Ct))!;
|
||||
var folder = fx.Paths.Sequence(sequence.Folder);
|
||||
var sidecar = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, sidecar with { Frames = [.. sidecar.Frames.Select(f => f with { Format = ImageFileFormat.Heif })] });
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, sidecar with
|
||||
{
|
||||
Frames = [.. sidecar.Frames.Select(f => f with { Format = ImageFileFormat.Heif, W = width ?? f.W, H = height ?? f.H })],
|
||||
});
|
||||
return (sequence, await fx.Db.Frames.ListBySequenceAsync(id));
|
||||
}
|
||||
|
||||
/// <summary>A 320 × 240 JPEG proxy with <paramref name="captured"/> in its Exif, as a client makes it.</summary>
|
||||
private static byte[] Proxy(DateTime captured, int seed)
|
||||
/// <summary>A JPEG proxy (320 × 240 unless sized) with <paramref name="captured"/> in its Exif, as a client makes it.</summary>
|
||||
private static byte[] Proxy(DateTime captured, int seed, int width = 320, int height = 240)
|
||||
{
|
||||
using var image = new ImageBuffer(320, 240);
|
||||
using var image = new ImageBuffer(width, height);
|
||||
var level = 0.2f + seed % 5 * 0.1f;
|
||||
for (var c = 0; c < 3; c++) image.Plane(c).Fill(level + c * 0.05f);
|
||||
var exif = ExifWriter.BuildJpegApp1(new FrameMetadata { CapturedAt = captured, Software = "Titano" });
|
||||
|
||||
@@ -69,9 +69,11 @@ public sealed class RenderNodeClientTests(TestContext context)
|
||||
var sequenceId = await UploadSequenceAsync(editor, Photos()[..3]);
|
||||
await Uploads.UploadAsync(editor, [0, 0, 0, 24, .. "ftypheic"u8, 0, 0, 0, 0, .. "mif1heic"u8, .. Uploads.Photo(2000, 9)], "IMG_0004.HEIC", sequenceId);
|
||||
var frames = await server.Database.Frames.ListBySequenceAsync(sequenceId);
|
||||
// Frame 1 is gone from the server, frame 2 was adopted and never hashed, frame 4 is a HEIF the server cannot decode.
|
||||
// Frame 1 is gone from the server, frame 2 was adopted and never hashed, frame 3 is damaged (the server could not
|
||||
// decode it) and frame 4 is a HEIF the server cannot decode.
|
||||
File.Delete(Path.Combine(server.Options.ArchivePath, frames[0].RelativePath));
|
||||
await server.Database.Frames.UpdateFlagsAsync([frames[0].Id], FrameFlags.Missing, FrameFlags.None);
|
||||
await server.Database.Frames.UpdateFlagsAsync([frames[2].Id, frames[3].Id], FrameFlags.Undecodable, FrameFlags.None);
|
||||
await using (var session = await server.Database.Database.OpenAsync(context.Cancellation))
|
||||
{
|
||||
await session.ExecuteAsync("UPDATE frames SET sha256 = NULL WHERE id = $1", [frames[1].Id], context.Cancellation);
|
||||
@@ -89,6 +91,9 @@ public sealed class RenderNodeClientTests(TestContext context)
|
||||
Assert.Equal("done", done.State, done.Error);
|
||||
Assert.DoesNotContain($"/api/v1/frames/{frames[0].Id}/original", requests.Paths);
|
||||
Assert.Contains($"/api/v1/frames/{frames[1].Id}/original", requests.Paths);
|
||||
// The damaged frame stays out, as in the server's own render; the HEIF renders from its original here.
|
||||
Assert.DoesNotContain($"/api/v1/frames/{frames[2].Id}/original", requests.Paths);
|
||||
Assert.Contains($"/api/v1/frames/{frames[3].Id}/original", requests.Paths);
|
||||
var sequence = (await server.Database.Sequences.GetAsync(sequenceId))!;
|
||||
var proxy = new ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).Proxy(frames[3].Index);
|
||||
Assert.Equal(frames[3].CapturedAt, MetadataReader.Read(proxy).CapturedAt, "the proxy the server asked for, with the frame's capture time");
|
||||
|
||||
@@ -70,6 +70,9 @@ public sealed class ProxyUploadTests(TestContext context)
|
||||
var upload = await Uploads.UploadAsync(editor, Proxy(new DateTime(2026, 9, 28, 18, 2, 11)), "IMG_0001.JPG", sessionKey: "roof");
|
||||
|
||||
Assert.False((await ManifestAsync(editor, upload.SequenceId)).Frames.Single().WantsProxy);
|
||||
// Nor takes one: renders and remote views keep the proxy the server makes itself.
|
||||
using var refused = await PutAsync(editor, upload.FrameId, Proxy(new DateTime(2026, 9, 28, 18, 2, 11)));
|
||||
await refused.ExpectErrorAsync(HttpStatusCode.UnprocessableEntity, "proxy_not_wanted");
|
||||
}
|
||||
|
||||
/// <summary>A HEIF file as far as signature sniffing goes (an <c>ftyp</c> box naming heic), with no pixels the server can read.</summary>
|
||||
|
||||
Reference in new issue
Block a user