An independent review of the phase found nine defects. The ones that could lose money or orders: - Exits at the close of equity_meanrev are now planned orders written in the same transaction that claims the decision, so a restart can neither lose them nor send them twice. A sell with a deadline starts aggressive. - Resume also finds a planned order not yet linked to its execution (restart between sending and linking) and closes it before re-planning. - An account is "ready" only after adopting the guard's stops, checking the key, reconciling, resuming and aligning stops. Until then nothing is decided on it or sent to it, and the loop retries its startup each minute. The guard's note is deleted only when every stop it placed is in the ledger. - Each account's turn is cut after 45 s (60 s for a retried startup), so a slow broker no longer silences the heartbeat until the guard kills a healthy engine; the beat is also withheld when the scheduler has been silent for 30 minutes. Smaller ones: a stock decision made after the open is marked late; the Telegram loops survive unexpected errors; a long absence is shown on the Panoramica until "Ho visto" (SPEC 5.6); plain-http heartbeats are only accepted to home-network addresses; the soak report gives a daily close 30 minutes to be decided before expecting it. ADR 0012 point 12 records these choices; #51 and the two screen criteria are ticked in the roadmap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3d174931e9
commit
2185a0b36b
16 files changed
+397
-90
No files matched your search
@@ -56,6 +56,9 @@ internal sealed partial class AnubisHost(
|
||||
ILogger<AnubisHost> logger,
|
||||
ServerOverrides? overrides = null) : BackgroundService
|
||||
{
|
||||
/// <summary>A scheduler silent this long is stuck: the engine stops beating, so the guard steps in.</summary>
|
||||
public static readonly TimeSpan SchedulerSilence = TimeSpan.FromMinutes(30);
|
||||
|
||||
private readonly TimeSpan _interval = overrides?.DatabaseCheckInterval ?? TimeSpan.FromSeconds(5);
|
||||
private readonly Lock _gate = new();
|
||||
|
||||
@@ -318,6 +321,10 @@ internal sealed partial class AnubisHost(
|
||||
|
||||
// The drill's fault is honored only under a guard, which never passes it to an engine it restarts.
|
||||
Fault = Guard is null ? null : environment.GetValueOrDefault(GuardChannel.FaultVariable),
|
||||
|
||||
// The decisions run in the scheduler: a scheduler silent for half an hour is stuck (its longest jobs take
|
||||
// minutes), and the guard must hear it (SPEC 9.3).
|
||||
OthersAlive = () => scheduler.LastBeatUtc is not { } beat || clock.UtcNow - beat < SchedulerSilence,
|
||||
}
|
||||
: null;
|
||||
if (_trading is not null)
|
||||
|
||||
@@ -17,6 +17,14 @@
|
||||
var phoneMoves = moves.Select((m, i) => (m, i)).Where(x => !x.m.Calendar).Take(2).Select(x => x.i).ToHashSet();
|
||||
var v = p.Accounts;
|
||||
}
|
||||
@if (_absence is { } away)
|
||||
{
|
||||
<div class="notice notice-attention absence" role="status">
|
||||
<Icon Name="alert" Size="16" />
|
||||
<span>Sono stato spento per @Anubis.Trading.DiaryText.Duration(away.Length), fino a @Format.ShortDate(away.EndedAt, Shell.Now, Shell.Zone, withTime: false).ToLowerInvariant() alle @TimeZoneInfo.ConvertTime(away.EndedAt, Shell.Zone).ToString("HH:mm", System.Globalization.CultureInfo.InvariantCulture). Ho ripreso i lavori saltati con le regole del recupero: cosa ho fatto e cosa ho lasciato perdere è nel <a href="/diario?tipo=sistema">diario</a>.</span>
|
||||
<form method="post" action="/azioni/assenza/@away.Id/vista"><AntiforgeryToken /><button class="btn btn-small" type="submit">Ho visto</button></form>
|
||||
</div>
|
||||
}
|
||||
@if (!o.CapitalSet && !Shell.IsDemo)
|
||||
{
|
||||
<p class="notice notice-attention" role="status"><Icon Name="alert" Size="16" /><span>Primo passo: decidi quanto capitale affidare al bot in <a href="/impostazioni#conti">Impostazioni, Conti e chiavi</a>. Lì puoi anche inserire le chiavi dei conti di prova. Finché non c'è capitale, le strategie osservano soltanto.</span></p>
|
||||
@@ -388,6 +396,7 @@
|
||||
private string _period = "avvio";
|
||||
private int? _runningDays;
|
||||
private decimal? _worst;
|
||||
private Anubis.Trading.Absence? _absence;
|
||||
|
||||
[CascadingParameter]
|
||||
public HttpContext? HttpContext { get; set; }
|
||||
@@ -406,6 +415,9 @@
|
||||
_worst = _panorama.Limits[1].Worst is { } share ? -share * (await Anubis.Risk.RiskSettings.LoadAsync(services.Settings, ct)).DrawdownStop : null;
|
||||
using var aggregates = Shell.Aggregates();
|
||||
_runningDays = aggregates?.RootElement.GetProperty("giorno").GetInt32();
|
||||
|
||||
// SPEC 5.6: an absence longer than a day stays at the top until the user says they have seen it.
|
||||
_absence = Shell.IsDemo ? null : await new Anubis.Trading.AbsenceBook(services.Db, Host.Clock).DeclaredAsync(ct);
|
||||
}
|
||||
|
||||
private static string Statement(Overview o)
|
||||
|
||||
@@ -39,12 +39,24 @@ internal static partial class Forms
|
||||
signed.MapPost("/telegram/togli", RemoveTelegramAsync);
|
||||
signed.MapPost("/segnale-di-vita", SaveHeartbeatAsync);
|
||||
signed.MapPost("/segnale-di-vita/togli", RemoveHeartbeatAsync);
|
||||
signed.MapPost("/assenza/{id:guid}/vista", AbsenceSeenAsync);
|
||||
signed.MapPost("/laboratorio", PlanTrialAsync);
|
||||
signed.MapPost("/strategie/{strategy}/{choice}", StrategyStageAsync);
|
||||
signed.MapPost("/rischio/limiti", SetLimitsAsync);
|
||||
signed.MapPost("/rischio/{key}", SetRiskSettingAsync);
|
||||
}
|
||||
|
||||
/// <summary>The notice of a long absence (SPEC 5.6) goes away once the user has seen it.</summary>
|
||||
private static async Task<IResult> AbsenceSeenAsync(Guid id, AnubisHost host, CancellationToken ct)
|
||||
{
|
||||
if (!host.IsDemo && host.Services is { } services)
|
||||
{
|
||||
await new Anubis.Trading.AbsenceBook(services.Db, host.Clock).AcknowledgeAsync(id, ct).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return Results.Redirect("/");
|
||||
}
|
||||
|
||||
private static string Back(IFormCollection form, string fallback)
|
||||
{
|
||||
var back = form["ritorno"].ToString();
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Anubis.Server;
|
||||
/// Telegram and the sign of life (SPEC 14): the queue sent every few seconds, the commands read as they arrive, the
|
||||
/// call to the checking service every minute, the morning summary and the optional periodic status.
|
||||
/// </summary>
|
||||
internal sealed class TelegramServices : IDisposable
|
||||
internal sealed partial class TelegramServices : IDisposable
|
||||
{
|
||||
/// <summary>The secret that keeps the address of the checking service when the configuration does not give one.</summary>
|
||||
public const string HeartbeatSecret = "HEARTBEAT_URL";
|
||||
@@ -22,6 +22,7 @@ internal sealed class TelegramServices : IDisposable
|
||||
private readonly SettingsStore _settings;
|
||||
private readonly SecretStore _secrets;
|
||||
private readonly TimeZoneInfo _zone;
|
||||
private readonly Microsoft.Extensions.Logging.ILogger _logger;
|
||||
|
||||
public TelegramServices(AnubisHost host, Database db, IClock clock, SettingsStore settings, SecretStore secrets, string? configuredHeartbeat, HttpMessageHandler? handler,
|
||||
Microsoft.Extensions.Logging.ILogger logger)
|
||||
@@ -32,6 +33,7 @@ internal sealed class TelegramServices : IDisposable
|
||||
_settings = settings;
|
||||
_secrets = secrets;
|
||||
_zone = host.Config.TimeZone;
|
||||
_logger = logger;
|
||||
_http = handler is null ? new HttpClient() : new HttpClient(handler, disposeHandler: false);
|
||||
|
||||
// Longer than the wait of the commands' long polling.
|
||||
@@ -95,7 +97,16 @@ internal sealed class TelegramServices : IDisposable
|
||||
{
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await Sender.SendDueAsync(cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await Sender.SendDueAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// A busy or unreachable database, or anything else: the queue keeps its messages for the next pass.
|
||||
LogSendFailed(_logger, ex);
|
||||
}
|
||||
|
||||
await Task.Delay(SendEvery, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -156,4 +167,7 @@ internal sealed class TelegramServices : IDisposable
|
||||
var text = await Desk.StatusAsync(cancellationToken).ConfigureAwait(false);
|
||||
await _db.WriteAsync(s => NotificationSender.EnqueueAsync(s, _clock, "periodic_status", text, cancellationToken), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Microsoft.Extensions.Logging.LoggerMessage(Level = Microsoft.Extensions.Logging.LogLevel.Error, Message = "Sending the Telegram queue failed")]
|
||||
private static partial void LogSendFailed(Microsoft.Extensions.Logging.ILogger logger, Exception exception);
|
||||
}
|
||||
Reference in new issue
Block a user