Rapporto di diagnostica della raccolta (#39)
verifica / controlli (push) Successful in 18s
verifica / prove (push) Successful in 13m5s
verifica / installatore (push) Successful in 4m11s
verifica / immagine (push) Successful in 14m4s

Dopo una prova dal vivo andata male, Alberto deve poter mandare un solo file che
spieghi perché, senza che nessuno veda dati di altre persone. Attività ha ora il
pulsante «Diagnostica», che scarica il rapporto delle sessioni degli ultimi 14 giorni:
pagine aperte e forma degli indirizzi, risposte per tipo, stato e dimensione con ciò
che i lettori ne hanno fatto, struttura stretta delle forme sconosciute, ricette,
segnali, permessi negati, file in coda e scaricati, e il motivo di ogni arresto.

Nel rapporto entrano solo valori da elenchi chiusi, numeri, orari e forme: mai nomi,
indirizzi completi, codici, cursori, cookie o pezzi di risposte. Le forme degli
indirizzi e la regola delle chiavi-dato passano dalla sonda a Core, e la sonda le
richiama. Il registratore non lancia mai eccezioni verso la raccolta e tiene i file in
Dati/diagnostica per 14 giorni.

Prova che il rapporto non contiene valori, con controlli di mutazione; tre giri di
revisione avversaria (25 difetti confermati, tutti corretti).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-13 14:41:34 +01:00
1 parent bf03cb45a5
commit badd1681a0
55 files changed
+5395 -134

No files matched your search

+40 -2
View File
@@ -627,12 +627,15 @@ public sealed class EngineHost : IAsyncDisposable
}
s.Runtime.CurrentSession = context;
s.Diagnostics?.SessionStarted(record.Id, start, mood);
s.Runtime.HadSessionSinceStart = true;
Volatile.Write(ref _manualWaiting, false);
s.Runtime.NextSessionAt = null;
s.Events.Publish(EngineNotificationKind.StateChanged);
var outcome = SessionOutcome.Completed;
var cause = SessionStopCause.WorkDone;
SessionSummary? summary = null;
var interrupted = false;
try
{
@@ -642,25 +645,37 @@ public sealed class EngineHost : IAsyncDisposable
sessionCts.Cancel();
}
var summary = await _composer.RunAsync(context, outsideWindowTask, sessionCts.Token).ConfigureAwait(false);
summary = await _composer.RunAsync(context, outsideWindowTask, sessionCts.Token).ConfigureAwait(false);
if (summary.StoppedEarly || !s.Breaker.State.AllowsSiteActions || s.Runtime.IsPaused || s.Runtime.UserIsDriving)
{
outcome = StopOutcome();
cause = ct.IsCancellationRequested ? SessionStopCause.Shutdown : StopCause(summary);
}
else
{
// A shutdown between two recipes leaves the composer as if its work were done: say what it was.
cause = ct.IsCancellationRequested ? SessionStopCause.Shutdown
: s.Clock.Now >= plannedEnd ? SessionStopCause.PlannedEnd
: summary.BudgetsExhausted ? SessionStopCause.BudgetsExhausted
: SessionStopCause.WorkDone;
}
}
catch (OperationCanceledException) when (!ct.IsCancellationRequested)
{
outcome = StopOutcome();
cause = StopCause(null);
}
catch (OperationCanceledException)
{
outcome = SessionOutcome.Interrupted;
cause = SessionStopCause.Shutdown;
interrupted = true;
throw;
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
outcome = SessionOutcome.Failed;
cause = SessionStopCause.Failed;
await s.Events.WriteAsync(
EventSeverity.Error,
EngineEventCodes.RecipeFailed,
@@ -677,10 +692,29 @@ public sealed class EngineHost : IAsyncDisposable
s.Runtime.CurrentSession = null;
s.Runtime.Activity = null;
await EndSessionAsync(record, context, outcome, outsideWindowTask, interrupted).ConfigureAwait(false);
try
{
await EndSessionAsync(record, context, outcome, outsideWindowTask, interrupted).ConfigureAwait(false);
}
finally
{
s.Diagnostics?.SessionEnded(record.Id, s.Clock.Now, outcome, cause, summary?.StoppedEarlyBy);
}
}
}
/// <summary>
/// Why a session that did not reach its natural end stopped (diagnostic report): an open breaker first, then the
/// pause, then Alberto at the browser, then a recipe outcome; anything else is a cancellation. A shutdown of Febe
/// (the loop's token cancelled) is checked by the caller first: a real recipe returns «Cancelled» instead of throwing.
/// </summary>
private SessionStopCause StopCause(SessionSummary? summary) =>
!_s.Breaker.State.AllowsSiteActions ? SessionStopCause.BreakerOpen
: _s.Runtime.IsPaused ? SessionStopCause.Paused
: _s.Runtime.UserIsDriving ? SessionStopCause.UserDriving
: summary?.StoppedEarly == true ? SessionStopCause.StoppedEarly
: SessionStopCause.Cancelled;
private async Task EndSessionAsync(SessionRecord record, SessionContext context, SessionOutcome outcome, EngineTask? outsideWindowTask, bool interrupted)
{
var s = _s;
@@ -844,6 +878,10 @@ public sealed class EngineHost : IAsyncDisposable
private void OnBreakerChanged(object? sender, BreakerState state)
{
// The diagnostic report records the signal that stopped the breaker, also one the detector never saw (the
// session cookie lost, reported by the connection): a logout must not look like any other stop.
_s.Diagnostics?.BreakerChanged(state);
// Signals arrive on capture threads: the engine is never run inline on them (it may need the browser to answer).
// The composer also checks the breaker before every recipe, so the session stops at once either way.
CancellationTokenSource? session = null;
+7
View File
@@ -1,5 +1,6 @@
using System.Globalization;
using Febe.Core.Abstractions;
using Febe.Core.Collection.Diagnostics;
using Febe.Core.Domain;
using Febe.Core.Storage;
@@ -64,6 +65,12 @@ public sealed class EngineServices
/// <summary>Current engine and caution settings.</summary>
public EngineSettings Settings { get; private set; }
/// <summary>
/// The recorder of the diagnostic report (issue #39): told when sessions start and end, and why. Null: nothing is
/// recorded. Set by the composition before the engine starts.
/// </summary>
public CollectionDiagnostics? Diagnostics { get; set; }
/// <summary>
/// Loads settings, pause flag, gradual-start origin and breaker state from the database. When the gradual start has
/// no origin yet (first run after the first connection) it starts now.
+19 -2
View File
@@ -985,6 +985,7 @@ internal sealed class SessionComposer
else if (recheck.Reason is DenialReason.BreakerOpen or DenialReason.OutsideActiveWindow or DenialReason.Paused or DenialReason.UserIsDriving)
{
state.Stop = true;
state.StopStatus ??= outcome.Status;
}
break;
@@ -1002,6 +1003,7 @@ internal sealed class SessionComposer
}
state.Stop = true;
state.StopStatus ??= outcome.Status;
break;
case RecipeStatus.TargetNotFound:
@@ -1013,6 +1015,7 @@ internal sealed class SessionComposer
await RecordRecipeFailureAsync(kind, account, EngineEventCodes.TargetNotFound,
$"Non trovo nella pagina ciò che serve per {RecipeName(kind)}{Of(account)}: mi fermo e lo segnalo, senza cliccare a caso.", now).ConfigureAwait(false);
state.Stop = true;
state.StopStatus ??= outcome.Status;
break;
case RecipeStatus.UnrecognizedFormat:
@@ -1380,6 +1383,9 @@ internal sealed class SessionComposer
public bool Stop { get; set; }
/// <summary>The recipe status that first set <see cref="Stop"/>, when a recipe did (diagnostic report).</summary>
public RecipeStatus? StopStatus { get; set; }
public int Recipes { get; set; }
/// <summary>Next story check planned by the last visit of a profile not followed.</summary>
@@ -1388,9 +1394,20 @@ internal sealed class SessionComposer
/// <summary>Set while the stories of a visit run: their next check is the visit's.</summary>
public DateTimeOffset? PendingStoriesNext { get; set; }
public SessionSummary Summary() => new(Recipes, Stop);
public SessionSummary Summary() => new(Recipes, Stop)
{
StoppedEarlyBy = StopStatus,
BudgetsExhausted = Exhausted.Count > 0,
};
}
}
/// <summary>What a session did, for its row and its timeline line.</summary>
internal sealed record SessionSummary(int Recipes, bool StoppedEarly);
internal sealed record SessionSummary(int Recipes, bool StoppedEarly)
{
/// <summary>The recipe status that stopped the session early, when a recipe did (diagnostic report, issue #39).</summary>
public RecipeStatus? StoppedEarlyBy { get; init; }
/// <summary>Some budget categories were used up during the session and their work skipped.</summary>
public bool BudgetsExhausted { get; init; }
}
+39
View File
@@ -0,0 +1,39 @@
namespace Febe.Core.Engine;
/// <summary>
/// Why an engine session ended (issue #39, diagnostic report). Finer than <see cref="Domain.SessionOutcome"/>, which
/// puts most of these under «Stopped»; computed by <see cref="EngineHost"/> from what it already looks at, and never
/// stored in the database.
/// </summary>
public enum SessionStopCause
{
/// <summary>The planned length of the session was reached.</summary>
PlannedEnd,
/// <summary>Nothing else to do before the planned end.</summary>
WorkDone,
/// <summary>Ended before the planned end with some budget categories used up (their work was skipped).</summary>
BudgetsExhausted,
/// <summary>A recipe outcome stopped the session (see the recipe status that did).</summary>
StoppedEarly,
/// <summary>The circuit breaker was open: a stop signal of spec §7.6.</summary>
BreakerOpen,
/// <summary>Alberto paused the engine.</summary>
Paused,
/// <summary>Alberto took the browser.</summary>
UserDriving,
/// <summary>Cancelled for another reason.</summary>
Cancelled,
/// <summary>Febe was shutting down.</summary>
Shutdown,
/// <summary>An unexpected error closed the session.</summary>
Failed,
}