fix(proxies): get proxies of undecodable originals from clients and nodes

The server decodes with managed decoders only, so HEIF originals had no
proxies, thumbnails from their small previews and no pixels for analysis or
managed renders, and nothing could send it proxies (ENG-05). Manifests now
carry the archive's proxy spec and, per frame, its flags and whether the
server wants its proxy. PUT /api/v1/frames/{id}/proxy (Edit or RenderNode)
stores a JPEG of at most 64 MiB that decodes and whose Exif capture time is
the frame's, then queues thumbnails and the proxy pass. An upload from the
desktop makes and sends the wanted proxies after the originals and counts
them as local changes; a render node sends those it can make from the
originals it fetched once the job is done. The server never makes such a
proxy from a preview, drops one left by a renumbered frame, takes thumbnails
from a proxy, and analyses and renders those frames from their proxies.

Render nodes fetched every frame of the manifest: frames missing, corrupt or
excluded on the server failed the download, and originals not hashed yet
failed the SHA-256 check (ENG-07). Nodes now skip those frames, fetch unhashed
originals into the job folder with a size check, judge decodability with their
own decoders, and use the proxy of a frame they cannot decode.

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 09:58:58 +00:00
1 parent 078cac75e4
commit 9588ed7f4b
28 files changed
+1005 -94

No files matched your search

@@ -1,10 +1,14 @@
using System.Collections.Concurrent;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Titano.Core.Archiving;
using Titano.Core.Codecs.Jpeg;
using Titano.Core.Diagnostics.Synthetic;
using Titano.Core.Export;
using Titano.Core.Imaging;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Localization;
using Titano.Core.Metadata;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Data.Archiving;
@@ -57,6 +61,40 @@ public sealed class RenderNodeClientTests(TestContext context)
Assert.False(Directory.EnumerateFileSystemEntries(Path.Combine(cache, "jobs")).Any(), "job folder removed");
}
[Test]
public async Task ANodeSkipsMissingFramesFetchesUnhashedOnesAndSendsTheProxiesAskedFor()
{
await using var server = await TestServer.StartAsync(context);
var (editor, _, token) = await server.UserAsync("alberto", "editor", renderNode: true);
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.
File.Delete(Path.Combine(server.Options.ArchivePath, frames[0].RelativePath));
await server.Database.Frames.UpdateFlagsAsync([frames[0].Id], FrameFlags.Missing, 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);
await session.ExecuteAsync("UPDATE frames SET format = $1 WHERE id = $2", [(int)ImageFileFormat.Heif, frames[3].Id], context.Cancellation);
}
var job = await CreateRenderAsync(server, editor, sequenceId);
var requests = new RecordPaths(new SocketsHttpHandler());
using var client = new TitanoClient(server.HttpBase, new CertificatePinning([]), "studio-pc", requests) { Token = token };
// This PC decodes HEIF (WIC with the HEIF extension on Windows).
await using var node = Node(client, context.CreateTempDirectory("node"), decoder: new ImageDecoder([new SolidHeif(), new ManagedDecoderProvider()]));
Assert.True(await node.RunOnceAsync(context.Cancellation), "a job was claimed");
var done = await JobApiTests.GetAsync(editor, job.Id);
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);
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");
Assert.Equal((96, 64), MetadataReader.Read(proxy).OrientedSize);
}
[Test]
public async Task ANodeReportsWhyItCouldNotRender()
{
@@ -263,8 +301,8 @@ public sealed class RenderNodeClientTests(TestContext context)
Assert.FileExists(part[..^".part".Length]);
}
private static RenderNodeClient Node(TitanoClient client, string cache, TimeSpan? poll = null, TimeSpan? heartbeat = null) =>
new(client, new ProcessingOptions { Archive = new ArchiveServiceOptions { Decoder = DecoderFactory.CreateServer() } },
private static RenderNodeClient Node(TitanoClient client, string cache, TimeSpan? poll = null, TimeSpan? heartbeat = null, ImageDecoder? decoder = null) =>
new(client, new ProcessingOptions { Archive = new ArchiveServiceOptions { Decoder = decoder ?? DecoderFactory.CreateServer() } },
new RenderNodeOptions
{
ClientName = "studio-pc",
@@ -314,6 +352,35 @@ public sealed class RenderNodeClientTests(TestContext context)
}
}
/// <summary>Records the path of every request.</summary>
private sealed class RecordPaths(HttpMessageHandler inner) : DelegatingHandler(inner)
{
private readonly ConcurrentQueue<string> _paths = new();
public IReadOnlyCollection<string> Paths => _paths;
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
_paths.Enqueue(request.RequestUri!.AbsolutePath);
return base.SendAsync(request, cancellationToken);
}
}
/// <summary>Decodes every HEIF as a mid-grey 96 × 64 frame, as a native HEIF decoder would decode a real one.</summary>
private sealed class SolidHeif : IImageDecoderProvider
{
public string Name => "heif-test";
public DecodeTier? TierFor(ImageFileFormat format) => format == ImageFileFormat.Heif ? DecodeTier.Native : null;
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
{
var image = new ImageBuffer(96, 64);
for (var c = 0; c < 3; c++) image.Plane(c).Fill(0.2f);
return new DecodedImage(image, DecodeTier.Native, Name, 96, 64);
}
}
/// <summary>Counts the node's claims the server answered.</summary>
private sealed class CountClaims(HttpMessageHandler inner) : DelegatingHandler(inner)
{