fix(analysis): a deep run checks its report against the frames as they are when it records
A deep analysis kept the report it had just made, measured from the frames loaded at its start. Proxies that arrived during a long run make its verdict on those frames' originals stale (every later reader drops the report), yet the run applied its advice and recorded AnalyzedDeep, HasWarnings and the unreadable frames' warnings. The light analysis the proxies queued could have finished on another worker before, and nothing ran it again. The run now loads the frames again under the sequence lock and keeps its report only while it describes them (SequenceAnalyser.ReadReport's rule); the Auto values are applied under that same lock as the status (ProjectStore.UpdateLockedAsync), so a light analysis either ran before and is not undone, or runs after. Its scan stamps are recorded only while the index holds the sidecar's frames. Test: a deep analysis of HEIF files without an Exif thumbnail, during which their proxies arrive, records no deep status and leaves the warnings and Auto values of the light analysis that read the proxies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+124
-52
No files matched your search
@@ -52,43 +52,49 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, probed, proxies: true, cancellationToken).ConfigureAwait(false));
|
||||
var metadata = frames.LightFrames();
|
||||
|
||||
DeepAnalysisReport? report;
|
||||
DeepAnalysisReport? report = null;
|
||||
if (deep)
|
||||
{
|
||||
// Proxies may have arrived during the pass: the advice below follows the frames as they are at its end.
|
||||
// Proxies may have arrived during the pass: the flags below follow the frames as they are at its end, and the
|
||||
// report is checked against them under the lock.
|
||||
(report, var decoded) = await AnalyseDeepAsync(archive, frames, metadata, folder, progress, cancellationToken).ConfigureAwait(false);
|
||||
frames = WithTiers(frames, await _tiers.RecordAsync(archive, sequence, decoded, proxies: true, cancellationToken).ConfigureAwait(false));
|
||||
metadata = [.. metadata.Select((m, i) => m with { Flags = frames.Frames[i].Flags })];
|
||||
}
|
||||
else
|
||||
{
|
||||
report = ReadReport(folder, frames);
|
||||
}
|
||||
var light = LightAnalyzer.Analyze(metadata);
|
||||
var context = SequenceContext.FromFrames(frames.Frames, options.AdvisorCodecs);
|
||||
|
||||
bool changed, unreadable = false;
|
||||
try
|
||||
{
|
||||
// The frame rate follows the user's "fit to N seconds" when one is set (BRIEF §10.3).
|
||||
changed = await projects.UpdateAsync(paths, sequence,
|
||||
settings => Advisor.Apply(settings, Advisor.Recommend(light, report, context with { TargetDurationSeconds = settings.Timing.FitToSeconds })),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("processing", $"The project of {sequence.DisplayTitle} cannot be read", ex);
|
||||
(changed, unreadable) = (false, true);
|
||||
}
|
||||
|
||||
if (changed) await options.NotifyAsync(sequence.Id, ProcessingOptions.SettingsChange, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
int warnings;
|
||||
// Under the sequence lock, which a deep pass of the same sequence also takes to record its report: a light pass
|
||||
// then either sees that report or runs before it is recorded, and never clears what it recorded.
|
||||
// then either sees that report or runs before it is recorded, and never clears what it recorded. The report counts
|
||||
// only while it describes the frames as they are under the lock (ReadReport), so a deep pass loads them again: a
|
||||
// proxy that arrived while it ran (for hours) makes its verdict on that frame's original stale. The light analysis
|
||||
// the proxy queued then either ran before this, and the advice, status and warnings stay without the report as it
|
||||
// left them, or runs after.
|
||||
await using (await writer.LockAsync(paths, sequence.Id, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
report ??= ReadReport(folder, frames);
|
||||
if (deep)
|
||||
{
|
||||
var now = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, options.Archive.Decoder, cancellationToken).ConfigureAwait(false);
|
||||
if (!Describes(report!, now)) report = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
report = ReadReport(folder, frames);
|
||||
}
|
||||
try
|
||||
{
|
||||
// The frame rate follows the user's "fit to N seconds" when one is set (BRIEF §10.3).
|
||||
changed = await projects.UpdateLockedAsync(paths, sequence,
|
||||
settings => Advisor.Apply(settings, Advisor.Recommend(light, report, context with { TargetDurationSeconds = settings.Timing.FitToSeconds })),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (InvalidDataException ex)
|
||||
{
|
||||
Core.Diagnostics.Log.Warning("processing", $"The project of {sequence.DisplayTitle} cannot be read", ex);
|
||||
(changed, unreadable) = (false, true);
|
||||
}
|
||||
warnings = Advisor.Recommend(light, report, context).Findings.Count(f => f.Severity >= FindingSeverity.Warning);
|
||||
var set = SequenceStatus.AnalyzedLight | (report is null ? SequenceStatus.None : SequenceStatus.AnalyzedDeep)
|
||||
| (warnings > 0 ? SequenceStatus.HasWarnings : SequenceStatus.None);
|
||||
@@ -96,12 +102,17 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
var clear = (report is null ? SequenceStatus.AnalyzedDeep : SequenceStatus.None) | (warnings > 0 ? SequenceStatus.None : SequenceStatus.HasWarnings);
|
||||
var manifest = SequenceWriter.ReadLocked(folder, sequence.Id);
|
||||
var status = (manifest.Status | set) & ~clear;
|
||||
if (status != manifest.Status) ManifestStore.WriteSequence(folder.ManifestPath, manifest with { Status = status, UpdatedAt = DateTimeOffset.UtcNow });
|
||||
if (status != manifest.Status)
|
||||
{
|
||||
manifest = manifest with { Status = status, UpdatedAt = DateTimeOffset.UtcNow };
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, manifest);
|
||||
}
|
||||
var summary = deep && report is not null ? AnalysisSummary.From(report).ToJson() : null;
|
||||
await db.Sequences.RecordAnalysisAsync(sequence.Id, set, clear, warnings, summary, cancellationToken).ConfigureAwait(false);
|
||||
await indexer.RecordStampsAsync(archive, folder, sequence.Id, cancellationToken).ConfigureAwait(false);
|
||||
await indexer.RecordStampsInStepAsync(archive, folder, manifest, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (changed) await options.NotifyAsync(sequence.Id, ProcessingOptions.SettingsChange, cancellationToken).ConfigureAwait(false);
|
||||
var presets = deep ? SequencePresets.Generate(light, report, context) : [];
|
||||
return new AnalysisOutcome(sequence, frames.Count, warnings, changed, unreadable, presets);
|
||||
}
|
||||
@@ -111,17 +122,21 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
/// frame it found unreadable has been read from its proxy since (one sent for an original this host cannot decode,
|
||||
/// BRIEF §2.3), so that verdict and the frame's missing measurements no longer hold.
|
||||
/// </summary>
|
||||
public static DeepAnalysisReport? ReadReport(SequencePaths folder, SequenceFrames frames)
|
||||
public static DeepAnalysisReport? ReadReport(SequencePaths folder, SequenceFrames frames) =>
|
||||
ReadReport(folder, frames.Count) is { } report && Describes(report, frames) ? report : null;
|
||||
|
||||
/// <summary>Whether <paramref name="report"/> describes <paramref name="frames"/> as this host reads them now (<see cref="ReadReport(SequencePaths, SequenceFrames)"/>).</summary>
|
||||
private static bool Describes(DeepAnalysisReport report, SequenceFrames frames)
|
||||
{
|
||||
var report = ReadReport(folder, frames.Count);
|
||||
if (report is null || frames.Proxied is not { } proxied) return report;
|
||||
if (report.FrameCount != frames.Count) return false;
|
||||
if (frames.Proxied is not { } proxied) return true;
|
||||
HashSet<int> measured = report.ProxyFrames is { } read ? [.. read] : [];
|
||||
foreach (var index in report.Issues.Undecodable)
|
||||
{
|
||||
if (index < frames.Count && proxied[index] && !measured.Contains(index) && (frames.Frames[index].Flags & SequenceFrames.NotAnalysed) == 0)
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
return report;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The saved deep report when it covers <paramref name="frameCount"/> frames; null when absent, stale or unreadable.</summary>
|
||||
|
||||
Reference in new issue
Block a user