From 5e2acc9f603a9fe4406ee86f2affb47c65017fde Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 09:45:29 +0000 Subject: [PATCH] fix(analysis): one failed sequence is the job's error as logged; workers never fault while stopping "1 sequenze su 3" read wrong in Italian: a single failure now reports its own line (title and reason); the count is kept for two or more. A worker whose job could not be finished while the engine stops logs it instead of faulting, so disposing the engine never throws. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- i18n/en/Errors.resx | 2 +- src/Titano.Data/Jobs/JobEngine.cs | 5 +++-- src/Titano.Data/Processing/Jobs/AnalyseJobHandler.cs | 7 +++++-- tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/i18n/en/Errors.resx b/i18n/en/Errors.resx index fee81e90..13da03d2 100644 --- a/i18n/en/Errors.resx +++ b/i18n/en/Errors.resx @@ -4,7 +4,7 @@ 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - {0} of {1} sequences could not be analysed; see the job log.long; {0} failed count; {1} total count + {0} of {1} sequences could not be analysed; see the job log.long; {0} failed count (2 or more); {1} total count The archive could not be opened.long Enter a whole number from {0} to {1}. Enter a folder. diff --git a/src/Titano.Data/Jobs/JobEngine.cs b/src/Titano.Data/Jobs/JobEngine.cs index 0b883614..f9c2d250 100644 --- a/src/Titano.Data/Jobs/JobEngine.cs +++ b/src/Titano.Data/Jobs/JobEngine.cs @@ -220,9 +220,10 @@ public sealed class JobEngine : IAsyncDisposable { await RunAsync(job, shutdown).ConfigureAwait(false); } - catch (Exception ex) when (!shutdown.IsCancellationRequested) + catch (Exception ex) { - // The job's final state could not be stored; it stays running and is requeued at the next start. + // The job's final state could not be stored (also while stopping): it stays running and is requeued at the + // next start. The worker never faults, so disposing the engine never throws. Log.Error("jobs", $"{job.Kind} job {job.Id} could not be finished", ex); } } diff --git a/src/Titano.Data/Processing/Jobs/AnalyseJobHandler.cs b/src/Titano.Data/Processing/Jobs/AnalyseJobHandler.cs index 82a7c770..e1c27d07 100644 --- a/src/Titano.Data/Processing/Jobs/AnalyseJobHandler.cs +++ b/src/Titano.Data/Processing/Jobs/AnalyseJobHandler.cs @@ -30,6 +30,7 @@ internal sealed class AnalyseJobHandler(TitanoDatabase db, SequenceAnalyser anal var total = units.Sum(); var done = Enumerable.Range(0, next).Where(i => !retry.Contains(i)).Sum(i => units[i]); var failed = new List(); + string? failure = null; int[] order = [.. retry, .. Enumerable.Range(next, targets.Count - next)]; for (var k = 0; k < order.Length; k++) { @@ -49,7 +50,8 @@ internal sealed class AnalyseJobHandler(TitanoDatabase db, SequenceAnalyser anal { await chain.FlushAsync().ConfigureAwait(false); Core.Diagnostics.Log.Warning("processing", $"Analysis of sequence {targets[i]} failed", ex); - context.Log(Loc.L("Advisor.Log.Failed", await TitleAsync(targets[i], context.Cancellation).ConfigureAwait(false), ex.Message)); + failure = Loc.L("Advisor.Log.Failed", await TitleAsync(targets[i], context.Cancellation).ConfigureAwait(false), ex.Message); + context.Log(failure); failed.Add(i); } done += units[i]; @@ -57,7 +59,8 @@ internal sealed class AnalyseJobHandler(TitanoDatabase db, SequenceAnalyser anal // Failed targets of an earlier attempt not retried yet stay listed. await context.CheckpointAsync(Format(next, [.. failed, .. retry.Skip(k + 1)]), done, total).ConfigureAwait(false); } - if (failed.Count > 0) throw new InvalidOperationException(Loc.L("Errors.Analysis.Failed", failed.Count, targets.Count)); + // One failure is the job's error as it was logged; several are counted (the log names each). + if (failed.Count > 0) throw new InvalidOperationException(failed.Count == 1 ? failure : Loc.L("Errors.Analysis.Failed", failed.Count, targets.Count)); } private async Task TitleAsync(Guid sequenceId, CancellationToken cancellationToken) => diff --git a/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs b/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs index 7d5663a9..8fb31ae9 100644 --- a/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs +++ b/tests/Titano.Data.Tests/Processing/AnalysisJobTests.cs @@ -127,7 +127,7 @@ public sealed class AnalysisJobTests(TestContext context) var job = await fx.EnqueueAsync(ProcessingJobs.LightAnalysis([a.Id, b.Id, c.Id])); var failed = await fx.WaitForAsync(job.Id, JobState.Failed); - Assert.Equal(Loc.L("Errors.Analysis.Failed", 1, 3), failed.Error); + Assert.True(failed.Error!.StartsWith(Loc.L("Advisor.Log.Failed", b.DisplayTitle, string.Empty), StringComparison.Ordinal), failed.Error); Assert.Equal("3;1", failed.Checkpoint); Assert.SequenceEqual([true, false, true], await AnalysedAsync(fx, a, b, c));