Files
Febe/src/Febe.Core/Engine/Contracts.cs
T
Alby96andClaude Opus 5.5 9d959f910b Storico chiuso dal controllo del profilo: il motore lo chiude subito, con la sua riga
Se un profilo sta tutto nella prima pagina, il controllo del profilo segnava lo
storico come completato ma non cambiava lo stato e non scriveva righe. Dalla
sessione dopo l'account usciva dai candidati dello Storico, quindi nessuno lo
chiudeva più: restava «Storico in corso» per sempre, senza riga e senza avviso.
Con due account in «Storico in corso» succedeva sempre (rilievo F1 della revisione).

- Il controllo del profilo lo dice al motore con BackfillFinished, solo per un
  account «Storico in corso»: chi tiene solo i post nuovi non ha uno storico da
  annunciare.
- Il motore chiude lo storico anche dopo il controllo del profilo, con la stessa
  FinishBackfillAsync, e prosegue con l'account aggiornato.
- La fase dello Storico rilegge gli account invece di usare quelli di inizio
  sessione: altrimenti tornava a scorrere lo storico appena chiuso e scriveva una
  seconda riga.
- A inizio sessione il motore chiude gli account rimasti «Storico in corso» con lo
  storico già completato (Febe fermata a metà, o lasciati così dalla 0.1.0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 16:00:04 +02:00

129 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Febe.Core.Abstractions;
namespace Febe.Core.Engine;
/// <summary>The fixed set of recipes (spec §6.3).</summary>
public enum RecipeKind
{
/// <summary>Giro dei seguiti: home, stories bar, recent posts of followed profiles.</summary>
FollowingSweep,
/// <summary>Storie di un account.</summary>
AccountStories,
/// <summary>Controllo del profilo.</summary>
ProfileCheck,
/// <summary>Storico: one or more history pages, resuming from the stored point.</summary>
Backfill,
/// <summary>Raccolta in evidenza.</summary>
Highlight,
/// <summary>Taggati.</summary>
Tagged,
/// <summary>Reel.</summary>
Reels,
/// <summary>Post singolo: complete data or refresh an expired address.</summary>
SinglePost,
/// <summary>Elenco dei seguiti: only on request.</summary>
FollowingList,
}
/// <summary>What the scheduler asks a recipe to do.</summary>
/// <param name="Kind">Recipe.</param>
/// <param name="AccountId">Febe account id (database id, not the Instagram id); null for FollowingSweep and FollowingList.</param>
/// <param name="EntryId">For SinglePost: the entry whose data or addresses must be refreshed.</param>
/// <param name="HighlightId">For Highlight: the Instagram id of the collection.</param>
/// <param name="MaxPages">For Backfill, Tagged, Reels and FollowingList: how many pages at most in this run.</param>
/// <param name="Manual">True for «Controlla ora» (spec §7.8).</param>
public sealed record RecipeRequest(
RecipeKind Kind,
long? AccountId = null,
long? EntryId = null,
string? HighlightId = null,
int? MaxPages = null,
bool Manual = false);
/// <summary>How a recipe run ended.</summary>
public enum RecipeStatus
{
/// <summary>Finished its purpose (reached known content, the end of the list, or MaxPages).</summary>
Completed,
/// <summary>The Governor refused a counted action: stopped in order.</summary>
Denied,
/// <summary>A stop signal (spec §7.6) was seen: stopped where it was, page left as is.</summary>
StoppedBySignal,
/// <summary>A target of the target map was not found: stopped and reported, no random clicks.</summary>
TargetNotFound,
/// <summary>Responses had an unrecognized shape (spec §6.4).</summary>
UnrecognizedFormat,
/// <summary>The account is not reachable (private not followed, missing, blocked).</summary>
AccountUnreachable,
/// <summary>Cancelled (engine paused, Alberto took the browser, shutdown).</summary>
Cancelled,
/// <summary>Unexpected error; message says what happened.</summary>
Failed,
}
/// <summary>Result of a recipe run, used by the scheduler to plan what comes next.</summary>
public sealed record RecipeOutcome(
RecipeStatus Status,
int CountedActions,
int NewEntries,
string? Message = null)
{
/// <summary>Followed accounts the stories bar flagged as having active stories (FollowingSweep).</summary>
public IReadOnlyList<long> AccountsWithStories { get; init; } = [];
/// <summary>Accounts where the sweep saw new posts (FollowingSweep).</summary>
public IReadOnlyList<long> AccountsWithNewPosts { get; init; } = [];
/// <summary>
/// Backfill: true when the beginning of the profile has been reached. ProfileCheck: true when the check found the
/// whole profile of an account «Storico in corso» on its first page (its history is complete as well).
/// </summary>
public bool BackfillFinished { get; init; }
}
/// <summary>Information about the session in progress, handed to every recipe.</summary>
public interface ISessionContext
{
long SessionId { get; }
/// <summary>Speed factor drawn once per session (log-normal, median 1, σ 0.2, [0.7, 1.5]); multiplies every wait.</summary>
double Mood { get; }
/// <summary>Planned end of the session; recipes should finish what they are doing and stop after it.</summary>
DateTimeOffset PlannedEnd { get; }
}
/// <summary>Runs one recipe. The real implementation drives the browser; the simulation uses a fake world.</summary>
public interface IRecipeRunner
{
Task<RecipeOutcome> RunAsync(RecipeRequest request, ISessionContext session, CancellationToken ct);
/// <summary>Puts the browser on the empty rest page (end of session, pauses, night).</summary>
Task RestAsync(CancellationToken ct);
}
/// <summary>Daily byte budget for CDN downloads (category «dati scaricati», spec §7.4).</summary>
public interface IDataBudget
{
/// <summary>Bytes still available today (after ramp-up and halving), never negative.</summary>
Task<long> RemainingTodayAsync(CancellationToken ct);
/// <summary>Records bytes actually downloaded.</summary>
Task RecordAsync(long bytes, long? accountId, CancellationToken ct);
}