fix(analysis): a deep pass that leaves the saved report records that report
A deep pass overtaken by a frames change that keeps the frame count, with a light analysis queued, leaves an analysis.json of that count in place rather than save its own. It then still recorded its own report: the deep status, summary, warning count and Auto values described a report that is not on disk, and the queued light analysis kept that summary until the next deep pass. SaveReport now says whether it saved; when it did not, the pass reads the saved report as a light analysis would and records that one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
2 files changed
+64
-10
No files matched your search
@@ -94,18 +94,23 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
// 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. A pass whose frames were added to, removed or renumbered since it read them records
|
||||
// nothing (FramesChangeAsync), and a light analysis of the frames as they are runs instead, here or where they
|
||||
// were changed; its report is saved only over none of the frames as they are (SaveReport).
|
||||
// were changed; its report is saved only over none of the frames as they are (SaveReport). What a deep pass records
|
||||
// then follows the report analysis.json holds: its own, or the one it left in place.
|
||||
await using (await writer.LockAsync(paths, sequence.Id, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var manifest = SequenceWriter.ReadLocked(folder, sequence.Id);
|
||||
var change = await FramesChangeAsync(sequence, manifest, cancellationToken).ConfigureAwait(false);
|
||||
if (deep) SaveReport(folder, report!, change == FramesChange.None && manifest.Versions.Frames == sequence.FramesVersion, manifest.Frames.Count);
|
||||
var saved = deep && SaveReport(folder, report!, change == FramesChange.None && manifest.Versions.Frames == sequence.FramesVersion,
|
||||
manifest.Frames.Count);
|
||||
if (change != FramesChange.None)
|
||||
return new AnalysisOutcome(sequence, frames.Count, 0, SettingsChanged: false, SettingsUnreadable: false, [], change);
|
||||
if (deep)
|
||||
{
|
||||
// A report left in place is read as a light analysis reads it, so the deep status, summary, warnings and
|
||||
// Auto values recorded here describe the file that readers and the report endpoint open.
|
||||
var now = await SequenceFrames.LoadAsync(db, archive, sequence, useProxies: false, options.Archive.Decoder, cancellationToken).ConfigureAwait(false);
|
||||
if (!Describes(report!, now)) report = null;
|
||||
if (!saved) report = ReadReport(folder, now);
|
||||
else if (!Describes(report!, now)) report = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -249,16 +254,19 @@ internal sealed class SequenceAnalyser(TitanoDatabase db, ProcessingOptions opti
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a deep pass's report as <c>analysis.json</c>, under the sequence lock, then drops its checkpoint. The report
|
||||
/// replaces the saved one when it measured the frames as they are (<paramref name="current"/>), or when the saved one
|
||||
/// describes them no better: none, unreadable, or of another frame count than <paramref name="frameCount"/>, the
|
||||
/// sidecar's. A pass overtaken by an upload, or by another process sharing the archive, would otherwise replace the
|
||||
/// report a later pass made of the frames as they are, and the next light analysis would drop that one's deep status.
|
||||
/// Saves a deep pass's report as <c>analysis.json</c>, under the sequence lock, then drops its checkpoint; returns
|
||||
/// whether it saved it. The report replaces the saved one when it measured the frames as they are
|
||||
/// (<paramref name="current"/>), or when the saved one describes them no better: none, unreadable, or of another frame
|
||||
/// count than <paramref name="frameCount"/>, the sidecar's. A pass overtaken by an upload, or by another process
|
||||
/// sharing the archive, would otherwise replace the report a later pass made of the frames as they are, and the next
|
||||
/// light analysis would drop that one's deep status.
|
||||
/// </summary>
|
||||
private static void SaveReport(SequencePaths folder, DeepAnalysisReport report, bool current, int frameCount)
|
||||
private static bool SaveReport(SequencePaths folder, DeepAnalysisReport report, bool current, int frameCount)
|
||||
{
|
||||
if (current || ReadReport(folder, frameCount) is null) report.Save(folder.AnalysisPath);
|
||||
var save = current || ReadReport(folder, frameCount) is null;
|
||||
if (save) report.Save(folder.AnalysisPath);
|
||||
Checkpoint(folder).Delete();
|
||||
return save;
|
||||
}
|
||||
|
||||
/// <summary>The deep pass's checkpoint, <c>.titano/analysis.partial</c>: kept until the pass has saved its report.</summary>
|
||||
|
||||
@@ -329,6 +329,52 @@ public sealed class AnalysisJobTests(TestContext context)
|
||||
Assert.Equal(analysed.AnalysisJson, row.AnalysisJson);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ADeepAnalysisThatLeavesTheReportInPlaceRecordsThatReport()
|
||||
{
|
||||
await using var fx = await ProcessingFixture.CreateAsync(context);
|
||||
var sequence = await fx.AddAsync(Flickering(12));
|
||||
var folder = fx.Folder(sequence);
|
||||
await fx.StartEngineAsync();
|
||||
var first = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.WaitForAsync(first.Id, JobState.Done);
|
||||
var measured = SequenceAnalyser.ReadReport(folder, 12)!;
|
||||
|
||||
// A deep analysis starts on the twelve frames on the only worker. Meanwhile another Titano sharing the archive files
|
||||
// them again, at the next frames version, and saves its own analysis of them; this index's scan indexes them, and
|
||||
// their light analysis waits in the queue.
|
||||
fx.Decoder.HoldFrame(0);
|
||||
var overtaken = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
|
||||
await fx.Decoder.Holding.Task.WaitAsync(TimeSpan.FromSeconds(60), fx.Ct);
|
||||
fx.Decoder.Hold = null;
|
||||
var manifest = ManifestStore.ReadSequence(folder.ManifestPath);
|
||||
ManifestStore.WriteSequence(folder.ManifestPath, manifest with
|
||||
{
|
||||
Versions = manifest.Versions with { Frames = manifest.Versions.Frames + 1 },
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
});
|
||||
Assert.Contains(sequence.Id, (await fx.Archive.ScanAsync()).Sequences);
|
||||
var theirs = measured with { HeroIndex = measured.HeroIndex == 5 ? 6 : 5 };
|
||||
theirs.Save(folder.AnalysisPath);
|
||||
var report = await File.ReadAllTextAsync(folder.AnalysisPath, fx.Ct);
|
||||
var light = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([sequence.Id]));
|
||||
fx.Decoder.Release();
|
||||
await fx.WaitForAsync(overtaken.Id, JobState.Done);
|
||||
|
||||
// The pass leaves that report in place, and records it rather than its own: the summary in the index is the one of
|
||||
// the file every reader opens, and the light analysis that follows keeps it.
|
||||
Assert.Equal(report, await File.ReadAllTextAsync(folder.AnalysisPath, fx.Ct));
|
||||
var summary = AnalysisSummary.From(theirs);
|
||||
Assert.NotEqual(AnalysisSummary.From(measured), summary);
|
||||
var row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
|
||||
Assert.True(row.Status.HasFlag(SequenceStatus.AnalyzedDeep), row.Status.ToString());
|
||||
Assert.Equal(summary, AnalysisSummary.FromJson(row.AnalysisJson!));
|
||||
await fx.WaitForAsync(light.Id, JobState.Done);
|
||||
row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
|
||||
Assert.True(row.Status.HasFlag(SequenceStatus.AnalyzedDeep), row.Status.ToString());
|
||||
Assert.Equal(summary, AnalysisSummary.FromJson(row.AnalysisJson!));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AnAnalysisOvertakenWhileALightAnalysisWaitsRecordsAndThatOneReplacesIt()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user