fix(proxies): judge proxies by one rule and record tiers and reports as they stand

- ArchiveImages.IsProxyOf compares capture times to the microsecond the index
  keeps (sidecars and Exif keep 100 ns ticks), and for frames read through
  proxies also applies the policy's size rule, so the proxy pass, uploads,
  thumbnails, renders, analyses, tiers, manifests and downloads agree.
- Proxy headers are cached per file while length and write time are unchanged
  (and the file has settled), so manifests cost a stat per proxy.
- FrameTiers.RecordAsync checks proxy presence when it writes the sidecar and
  returns the sequence's frames as they are, so a deep analysis or render that
  ran while proxies arrived no longer flags the frames preview-only again, and
  the analysis advises from the current flags.
- Server manifests ignore ProxiesBuilt for frames the server cannot decode, so
  frames added since the last proxy pass are asked for their proxies.
- GET /sequences/{id}/analysis/report answers 404 for a report that found
  frames unreadable before their proxies arrived (DeepReports.ReadCurrentAsync).
- The deep checkpoint key marks only frames read from proxies, so checkpoints
  written by earlier versions still resume.

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 16:52:30 +00:00
1 parent b4f1fa32d5
commit 4014b0e669
16 files changed
+514 -99

No files matched your search

@@ -32,10 +32,14 @@ public sealed class RemoteEditingTests(TestContext context)
var sequence = (await server.Database.Sequences.GetAsync(frame.SequenceId))!;
var path = new ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).AnalysisPath;
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
const string report = """{"version":1,"frameCount":1}""";
var report = Reports.Minimal(1).ToJson();
await File.WriteAllTextAsync(path, report, context.Cancellation);
Assert.Equal(report, await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation));
// One made for other frames is not this sequence's report.
await File.WriteAllTextAsync(path, Reports.Minimal(2).ToJson(), context.Cancellation);
Assert.Null(await client.GetAnalysisReportAsync(frame.SequenceId, context.Cancellation), "another frame count");
var gone = await Assert.ThrowsAsync<TitanoApiException>(() => client.GetAnalysisReportAsync(Guid.CreateVersion7(), context.Cancellation));
Assert.Equal(HttpStatusCode.NotFound, gone.Status);
}
+20
View File
@@ -0,0 +1,20 @@
using Titano.Core.Analysis.Deep;
namespace Titano.Server.Tests;
/// <summary>Deep-analysis reports as a server keeps them in <c>.titano/analysis.json</c>.</summary>
internal static class Reports
{
/// <summary>A report of <paramref name="frames"/> frames that found <paramref name="undecodable"/> unreadable and measured nothing else.</summary>
public static DeepAnalysisReport Minimal(int frames, params int[] undecodable) => new()
{
FrameCount = frames,
Flicker = new FlickerSummary(0, 0, null, 0, 0, 1),
Exposure = new ExposureSummary(0, 0, null, null, 0, []),
WhiteBalance = new WhiteBalanceSummary(0, 0, null, null),
Shake = new ShakeSummary(0, 0, 0, 0, false, 0),
Motion = new MotionSummary(0, null, null, null),
Sky = new SkySummary(DayNight.Unknown, 0, 0, 0, null, false, null),
Issues = new FrameIssues(undecodable, [], [], [], []),
};
}
@@ -3,6 +3,7 @@ using System.Net.Http.Headers;
using Titano.Core.Codecs.Jpeg;
using Titano.Core.Imaging;
using Titano.Core.Metadata;
using Titano.Core.Model;
using Titano.Protocol;
using Titano.Server.Storage;
using Titano.Testing;
@@ -87,6 +88,69 @@ public sealed class ProxyUploadTests(TestContext context)
await Http.BytesEqualAsync(proxy, editor.GetByteArrayAsync($"/api/v1/frames/{frame.Id}/proxy"));
}
[Test]
public async Task FramesAddedAfterEveryProxyArrivedAreAskedForTheirs()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var first = await Uploads.UploadAsync(editor, Heif(1), "IMG_0001.HEIC", sessionKey: "roof");
var frame = Assert.NotNull(await server.Database.Frames.GetAsync(first.FrameId));
using (var stored = await PutAsync(editor, frame.Id, Proxy(frame.CapturedAt!.Value)))
await stored.ExpectAsync(HttpStatusCode.NoContent);
// A frame comes after the proxy pass found every proxy there: until the next pass the status still says so, yet
// the new frame is asked for its proxy and the first keeps its own.
var second = await Uploads.UploadAsync(editor, Heif(2), "IMG_0002.HEIC", sessionKey: "roof");
Assert.Equal(first.SequenceId, second.SequenceId);
await server.Database.Sequences.UpdateStatusAsync(first.SequenceId, SequenceStatus.ProxiesBuilt, SequenceStatus.None, context.Cancellation);
var frames = (await ManifestAsync(editor, first.SequenceId)).Frames;
Assert.Equal((false, true), Wanted(frames.Single(f => f.Id == first.FrameId)));
Assert.Equal((true, false), Wanted(frames.Single(f => f.Id == second.FrameId)));
}
[Test]
public async Task AProxyTheServerMadeIsServedForAFrameTimedToTheTick()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
// Seven sub-second digits: the sidecar, and the proxy made from it, keep them all; the index keeps six.
var upload = await Uploads.UploadAsync(editor, Proxy(new DateTime(2026, 9, 28, 18, 2, 11).AddTicks(1_234_567)), "IMG_0001.JPG", sessionKey: "roof");
// The proxy pass the upload queued makes the frame's proxy, and the server serves it.
var until = DateTime.UtcNow + TimeSpan.FromSeconds(30);
while (true)
{
using var proxy = await editor.GetAsync($"/api/v1/frames/{upload.FrameId}/proxy");
if (proxy.StatusCode == HttpStatusCode.OK) break;
Assert.True(DateTime.UtcNow < until, $"proxy not served: {(int)proxy.StatusCode}");
await Task.Delay(100);
}
}
[Test]
public async Task AReportThatFoundAFrameUnreadableBeforeItsProxyCameIsNotServed()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (editor, _, _) = await server.UserAsync("alberto", "editor");
var upload = await Uploads.UploadAsync(editor, Heif(1), "IMG_0001.HEIC", sessionKey: "roof");
var frame = Assert.NotNull(await server.Database.Frames.GetAsync(upload.FrameId));
var sequence = Assert.NotNull(await server.Database.Sequences.GetAsync(upload.SequenceId));
// A deep analysis ran before the proxy came and found no pixels in the HEIF original.
var path = new Core.Archiving.ArchivePaths(server.Options.ArchivePath).Sequence(sequence.Folder).AnalysisPath;
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
Reports.Minimal(1, undecodable: 0).Save(path);
var url = $"/api/v1/sequences/{sequence.Id}/analysis/report";
using (var before = await editor.GetAsync(url))
await before.ExpectAsync(HttpStatusCode.OK);
// Once the frame is read from its proxy, that verdict and its advice to exclude the frame no longer hold, even
// before a light analysis has dropped the deep status.
using (var stored = await PutAsync(editor, frame.Id, Proxy(frame.CapturedAt!.Value)))
await stored.ExpectAsync(HttpStatusCode.NoContent);
using var after = await editor.GetAsync(url);
Assert.Equal("analysis", (await after.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found")).Details);
}
[Test]
public async Task FramesTheServerDecodesAskForNoProxy()
{