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

+15 -1
View File
@@ -254,7 +254,11 @@ public static class SequenceEndpoints
_ => ApiErrors.NotFound(context, "analysis"),
};
/// <summary>The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence.</summary>
/// <summary>
/// The full deep-analysis report (<c>.titano/analysis.json</c>) a client's editor shows for a server sequence, while it
/// describes the frames as the server reads them now (<see cref="DeepReports.ReadCurrentAsync"/>): one that found
/// frames unreadable before their proxies arrived answers 404 <c>analysis</c>, so no editor advises excluding them.
/// </summary>
private static async Task<IResult> ReportAsync(HttpContext context, Guid id, TitanoDatabase db, ServerArchive archive)
{
if (await db.Sequences.GetAsync(id, context.RequestAborted) is not { } sequence) return ApiErrors.NotFound(context, "sequence");
@@ -262,6 +266,16 @@ public static class SequenceEndpoints
var path = new Core.Archiving.ArchivePaths(archive.Root).Sequence(sequence.Folder).AnalysisPath;
var file = new FileInfo(path);
if (!file.Exists || file.LinkTarget is not null || !ArchivePathGuard.IsInside(archive.Root, path)) return ApiErrors.NotFound(context, "analysis");
try
{
if (await DeepReports.ReadCurrentAsync(db, archive.Current, sequence, Core.Imaging.Decoders.DecoderFactory.CreateServer(), context.RequestAborted) is null)
return ApiErrors.NotFound(context, "analysis");
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException)
{
// archive.json cannot be read now, so whether the proxies count is not known.
return ApiErrors.NotFound(context, "analysis");
}
var etag = string.Create(CultureInfo.InvariantCulture, $"a-{file.Length}-{file.LastWriteTimeUtc.Ticks}");
return FileResponses.Serve(context, file, 0, file.Length, "application/json; charset=utf-8", "no-cache", etag) ?? ApiErrors.NotFound(context, "analysis");
}
@@ -7,8 +7,8 @@ namespace Titano.Server.Storage;
/// <summary>
/// Proxies are files under the sequence's <c>proxies/</c> folder; a thumbnail is the JPEG byte range of its entry in
/// <c>thumbs.pack</c>. A thumbnail made from a different original (the frame was renumbered or replaced) counts as not
/// built yet, like a missing one, and so does a proxy whose capture time is another frame's
/// (<see cref="ArchiveImages.IsProxyOf"/>).
/// built yet, like a missing one, and so does a proxy whose capture time is another frame's, or one smaller than the
/// archive's policy sent for a frame the server cannot decode (<see cref="ServerProxies.HasProxy"/>).
/// </summary>
internal sealed class ArchiveAssetLocator : IFrameAssetLocator
{
@@ -17,13 +17,17 @@ internal sealed class ArchiveAssetLocator : IFrameAssetLocator
public ValueTask<AssetLocation?> LocateAsync(Archive archive, Sequence sequence, Frame frame, FrameAsset asset, CancellationToken cancellationToken)
{
var paths = new ArchivePaths(archive.RootPath).Sequence(sequence.Folder);
return ValueTask.FromResult(asset == FrameAsset.Proxy ? Proxy(paths, frame) : Thumbnail(paths, frame));
return ValueTask.FromResult(asset == FrameAsset.Proxy ? Proxy(archive, paths, frame) : Thumbnail(paths, frame));
}
private static AssetLocation? Proxy(SequencePaths paths, Frame frame)
private static AssetLocation? Proxy(Archive archive, SequencePaths paths, Frame frame)
{
var file = new FileInfo(paths.Proxy(frame.Index));
return file.Exists && ArchiveImages.IsProxyOf(file.FullName, frame.CapturedAt) ? new AssetLocation(file.FullName, 0, file.Length, Jpeg) : null;
if (!file.Exists) return null;
var own = ServerProxies.CannotDecode(frame.Format)
? ServerProxies.HasProxy(paths, frame, ServerProxies.Spec(archive))
: ArchiveImages.IsProxyOf(file.FullName, frame.CapturedAt, frame.Width, frame.Height, policy: null);
return own ? new AssetLocation(file.FullName, 0, file.Length, Jpeg) : null;
}
private static AssetLocation? Thumbnail(SequencePaths paths, Frame frame)
+18 -7
View File
@@ -34,10 +34,20 @@ public static class ServerProxies
}
/// <summary>
/// Every frame of <paramref name="sequence"/> in index order, as a manifest lists it: a proxy is there when the server
/// built them all or one was sent for the frame (<see cref="ArchiveImages.IsProxyOf"/>: one left at its index by a
/// frame renumbered since is another photo's); it is wanted for a frame the server cannot decode that has none (and is
/// not missing), unless <paramref name="spec"/> is null.
/// Whether the proxy of <paramref name="frame"/>, one the server cannot decode, is in <paramref name="folder"/>: the
/// frame's own (<see cref="ArchiveImages.IsProxyOf"/>: one left at its index by a frame renumbered since is another
/// photo's) and as large as <paramref name="spec"/> asks (null: the archive makes none, or its manifest cannot be read
/// now, so the size is not judged).
/// </summary>
public static bool HasProxy(SequencePaths folder, Frame frame, ProxySpec? spec) =>
ArchiveImages.IsProxyOf(folder.Proxy(frame.Index), frame.CapturedAt, frame.Width, frame.Height,
spec is null ? null : new ProxyPolicy { LongEdge = spec.LongEdge, Quality = spec.Quality });
/// <summary>
/// Every frame of <paramref name="sequence"/> in index order, as a manifest lists it. A frame the server cannot decode
/// has its proxy when its own is there (<see cref="HasProxy"/>), whatever the sequence's built status says (frames
/// added or renumbered since keep it until the next proxy pass), and wants one otherwise (unless it is missing or
/// damaged, or <paramref name="spec"/> is null); any other frame has one when the server built them all.
/// </summary>
public static async Task<List<ManifestFrame>> FramesAsync(TitanoDatabase db, Archive archive, Sequence sequence, ProxySpec? spec,
CancellationToken cancellationToken)
@@ -52,9 +62,10 @@ public static class ServerProxies
var batch = await db.Frames.ListBySequenceAsync(sequence.Id, after, Page, cancellationToken);
foreach (var f in batch)
{
var sent = !proxies && CannotDecode(f.Format) && ArchiveImages.IsProxyOf(folder.Proxy(f.Index), f.CapturedAt);
var wanted = spec is not null && !proxies && !sent && CannotDecode(f.Format) && (f.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) == 0;
frames.Add(new ManifestFrame(f.Id, f.Index, f.FileName, f.Size, f.Sha256 ?? string.Empty, proxies || sent, thumbs, (long)f.Flags, wanted));
var elsewhere = CannotDecode(f.Format);
var has = elsewhere ? HasProxy(folder, f, spec) : proxies;
var wanted = spec is not null && elsewhere && !has && (f.Flags & (FrameFlags.Missing | FrameFlags.Corrupt)) == 0;
frames.Add(new ManifestFrame(f.Id, f.Index, f.FileName, f.Size, f.Sha256 ?? string.Empty, has, thumbs, (long)f.Flags, wanted));
}
if (batch.Count < Page) return frames;
after = batch[^1].Index;