fix(analysis): save a deep report under the sequence lock, never over a more current one

A deep pass saved analysis.json as soon as it finished, before it checked
that its frames were still the sequence's. A pass overtaken by an upload, or
by another Titano sharing the archive, replaced the report a later pass had
made of the frames as they are: the report endpoint answered 404 and the
next light analysis dropped that pass's deep status. The report now waits in
memory and is saved under the sequence lock, when its frames are current or
the saved report describes the frames as they are no better; the checkpoint
is deleted only then.

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 23:28:45 +00:00
1 parent 2cdc44abe4
commit 52515897a4
2 files changed
+62 -8

No files matched your search

@@ -292,6 +292,43 @@ public sealed class AnalysisJobTests(TestContext context)
Assert.Equal(advice, await ProjectJsonAsync(fx, folder));
}
[Test]
public async Task ADeepAnalysisOvertakenByOneOfTheFramesAsTheyAreLeavesThatOnesReport()
{
await using var fx = await ProcessingFixture.CreateAsync(context);
var sequence = await fx.AddAsync(Flickering(12));
var folder = fx.Folder(sequence);
await fx.StartEngineAsync(workers: 2);
// A deep analysis starts on twelve frames; while it runs, a thirteenth photo is indexed and a second deep analysis,
// on the other worker, analyses all thirteen and records its report.
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;
await fx.AddAsync(Flickering(13), first: 12);
var current = await fx.EnqueueAsync(ProcessingJobs.DeepAnalysis([sequence.Id]));
await fx.WaitForAsync(current.Id, JobState.Done);
var report = await File.ReadAllTextAsync(folder.AnalysisPath, fx.Ct);
Assert.Equal(13, SequenceAnalyser.ReadReport(folder, 13)!.FrameCount);
var analysed = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.True(analysed.Status.HasFlag(SequenceStatus.AnalyzedDeep), analysed.Status.ToString());
fx.Decoder.Release();
var done = await fx.WaitForAsync(overtaken.Id, JobState.Done);
// The first pass measured twelve: it leaves the report of the thirteen in place, so the light analysis it queues
// keeps the deep status and its summary.
Assert.Contains(Loc.L("Advisor.Log.FramesChanged", sequence.DisplayTitle), done.LogTail);
Assert.Equal(report, await File.ReadAllTextAsync(folder.AnalysisPath, fx.Ct));
Assert.FileMissing(Path.Combine(folder.MetaDirectory, DeepAnalysisCheckpointFile.FileName));
var light = Assert.Contains(await LightJobsAsync(fx), j => j.TargetIds.Contains(sequence.Id));
await fx.WaitForAsync(light.Id, JobState.Done);
var row = (await fx.Db.Sequences.GetAsync(sequence.Id, fx.Ct))!;
Assert.True(row.Status.HasFlag(SequenceStatus.AnalyzedDeep), row.Status.ToString());
Assert.True(ManifestStore.ReadSequence(folder.ManifestPath).Status.HasFlag(SequenceStatus.AnalyzedDeep), "sidecar status");
Assert.Equal(analysed.AnalysisJson, row.AnalysisJson);
}
[Test]
public async Task AnAnalysisOvertakenWhileALightAnalysisWaitsRecordsAndThatOneReplacesIt()
{