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

+22 -17
View File
@@ -51,25 +51,26 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
return tiers;
}
/// <inheritdoc cref="RecordAsync(Archive, Sequence, IReadOnlyDictionary{Guid, FileTier}, IReadOnlyDictionary{Guid, bool}?, CancellationToken)"/>
public Task<IReadOnlyList<SidecarFrame>> RecordAsync(Archive archive, Sequence sequence, IReadOnlyDictionary<Guid, FileTier> tiers,
CancellationToken cancellationToken) => RecordAsync(archive, sequence, tiers, null, cancellationToken);
/// <summary>
/// Records <paramref name="tiers"/> (by frame id) where they change what the sidecar says, and returns the frames that
/// changed as they are now. Frames no longer in the sequence are ignored.
/// Records <paramref name="tiers"/> (by frame id) where they change what the sidecar says, and returns the sequence's
/// frames as the sidecar has them afterwards (none when there was nothing to record). Frames no longer in the
/// sequence are ignored. The <see cref="FrameFlags.PreviewOnly"/> flag of a frame whose original this host reads
/// through its proxy follows whether its own proxy is there when the sidecar is written
/// (<see cref="ArchiveImages.IsProxyOf"/>, <see cref="SequenceFrames.WithProxy"/>), not when the caller looked: proxies
/// arrive while analyses and renders run, and another worker may have recorded them already.
/// </summary>
/// <param name="proxied">By frame id, for frames whose original this host reads through its proxy, whether the frame's
/// own proxy is there now (<see cref="SequenceFrames.WithProxy"/>); their <see cref="FrameFlags.PreviewOnly"/> follows
/// it even where no tier is recorded.</param>
/// <param name="proxies">Whether every such frame follows its proxy even where no tier is recorded (analyses and the
/// proxy pass); otherwise only the frames in <paramref name="tiers"/> do.</param>
/// <exception cref="ArchiveOfflineException">The archive is offline or read-only.</exception>
public async Task<IReadOnlyList<SidecarFrame>> RecordAsync(Archive archive, Sequence sequence, IReadOnlyDictionary<Guid, FileTier> tiers,
IReadOnlyDictionary<Guid, bool>? proxied, CancellationToken cancellationToken)
bool proxies, CancellationToken cancellationToken)
{
if (tiers.Count == 0 && proxied is not { Count: > 0 }) return [];
if (tiers.Count == 0 && !proxies) return [];
var paths = new ArchivePaths(archive.RootPath);
ArchiveVolume.EnsureWritable(paths);
var folder = paths.Sequence(sequence.Folder);
var changed = new List<SidecarFrame>();
ProxyPolicy? policy = null;
var manifest = await writer.UpdateAsync(paths, sequence.Id, sequence.Folder, m =>
{
changed.Clear();
@@ -79,10 +80,15 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
{
var frame = m.Frames[i];
frames[i] = frame;
bool? hasProxy = proxied is not null && proxied.TryGetValue(frame.Id, out var found) ? found : null;
var tier = tiers.GetValueOrDefault(frame.Id);
if (tier is null && !proxies) continue;
bool? proxied = (frame.Flags & FrameFlags.Missing) == 0 && ArchiveImages.NeedsProxy(writer.Options.Decoder, frame.Format)
? ArchiveImages.IsProxyOf(folder.Proxy(frame.I), frame.CapturedAt, frame.W, frame.H,
policy ??= ManifestStore.ReadArchive(paths.ManifestPath).ProxyPolicy)
: null;
SidecarFrame updated;
if (tiers.TryGetValue(frame.Id, out var tier)) updated = SequenceFrames.WithTier(frame, tier, DecodesNatively(frame.Format), hasProxy == true);
else if (hasProxy is { } proxy) updated = SequenceFrames.WithProxy(frame, proxy);
if (tier is not null) updated = SequenceFrames.WithTier(frame, tier, DecodesNatively(frame.Format), proxied == true);
else if (proxied is { } own) updated = SequenceFrames.WithProxy(frame, own);
else continue;
if (updated.Tier == frame.Tier && updated.Flags == frame.Flags && updated.PreviewW == frame.PreviewW && updated.PreviewH == frame.PreviewH)
continue;
@@ -98,14 +104,13 @@ internal sealed class FrameTiers(TitanoDatabase db, SequenceWriter writer, Archi
UpdatedAt = DateTimeOffset.UtcNow,
};
}, cancellationToken).ConfigureAwait(false);
if (changed.Count == 0) return [];
if (changed.Count == 0) return manifest.Frames;
await db.Frames.UpdateTiersAsync(changed.ConvertAll(f => new FrameTierFields(f.Id, f.Flags, f.PreviewW ?? 0, f.PreviewH ?? 0)), cancellationToken)
.ConfigureAwait(false);
var folder = paths.Sequence(sequence.Folder);
if (await db.Sequences.GetAsync(sequence.Id, cancellationToken).ConfigureAwait(false) is { } existing)
await db.Sequences.UpsertAsync(SequenceMapping.ToSequence(manifest, archive.Id, folder, existing), cancellationToken).ConfigureAwait(false);
await indexer.RecordStampsAsync(archive, folder, sequence.Id, cancellationToken).ConfigureAwait(false);
return changed;
return manifest.Frames;
}
/// <summary>