diff --git a/src/Titano.Data/Processing/SequenceAnalyser.cs b/src/Titano.Data/Processing/SequenceAnalyser.cs
index eb71487f..47593854 100644
--- a/src/Titano.Data/Processing/SequenceAnalyser.cs
+++ b/src/Titano.Data/Processing/SequenceAnalyser.cs
@@ -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
}
///
- /// Saves a deep pass's report as analysis.json, under the sequence lock, then drops its checkpoint. The report
- /// replaces the saved one when it measured the frames as they are (), or when the saved one
- /// describes them no better: none, unreadable, or of another frame count than , 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 analysis.json, 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
+ /// (), or when the saved one describes them no better: none, unreadable, or of another frame
+ /// count than , 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.
///
- 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;
}
/// The deep pass's checkpoint, .titano/analysis.partial: kept until the pass has saved its report.
diff --git a/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs b/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs
index 8fb0138c..fc26bb1e 100644
--- a/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs
+++ b/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs
@@ -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()
{