Fix the defects found by the Phase 6 review (refs #47 #48 #49 #51 #52 #54)

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:
Alby96andClaude Opus 5.5 committed 2026-11-11 21:10:28 +01:00
1 parent 3d174931e9
commit 2185a0b36b
16 files changed
+397 -90

No files matched your search

+18 -14
View File
@@ -200,23 +200,27 @@ public sealed class ServerTests
ServerHarness.UsePostgres(env, empty);
}
await using var server = await ServerHarness.StartAsync("docker", env, dataDir: data, waitReady: false);
await server.WaitForAsync(HostMode.IdentityProblem);
Assert.AreEqual(IdentityVerdict.EmptyDatabase, server.Host.Status.Identity!.Verdict);
using (var restore = await server.PostFormAsync("/", "/azioni/servizio/ripristina", ("password", ServerHarness.AdminPassword), ("salvataggio", backup.Name)))
// The server stops before its data folder is removed: a running one may still hold the database file.
await using (var server = await ServerHarness.StartAsync("docker", env, dataDir: data, waitReady: false))
{
Assert.AreEqual("/", ServerHarness.Location(restore));
await server.WaitForAsync(HostMode.IdentityProblem);
Assert.AreEqual(IdentityVerdict.EmptyDatabase, server.Host.Status.Identity!.Verdict);
using (var restore = await server.PostFormAsync("/", "/azioni/servizio/ripristina", ("password", ServerHarness.AdminPassword), ("salvataggio", backup.Name)))
{
Assert.AreEqual("/", ServerHarness.Location(restore));
}
await server.WaitForAsync(HostMode.Ready);
// SPEC 15.1: back with "Ferma tutto" on, a new fingerprint, and nobody signed in.
var state = await server.Host.Services!.Settings.GetAsync(SettingsStore.BotState.Key);
Assert.AreEqual("stopped", state.Value);
var row = await Installation.ReadRowAsync(server.Host.Services.Db);
Assert.IsTrue(row!.ProtectedRestart);
Assert.AreEqual(row.Fingerprint, Installation.ReadFile(new DataDirectory(data))!.Fingerprint);
Assert.AreEqual(0, await server.Host.Services.Db.ReadAsync(s => s.CountAsync("SELECT COUNT(*) FROM sessions")));
}
await server.WaitForAsync(HostMode.Ready);
// SPEC 15.1: back with "Ferma tutto" on, a new fingerprint, and nobody signed in.
var state = await server.Host.Services!.Settings.GetAsync(SettingsStore.BotState.Key);
Assert.AreEqual("stopped", state.Value);
var row = await Installation.ReadRowAsync(server.Host.Services.Db);
Assert.IsTrue(row!.ProtectedRestart);
Assert.AreEqual(row.Fingerprint, Installation.ReadFile(new DataDirectory(data))!.Fingerprint);
Assert.AreEqual(0, await server.Host.Services.Db.ReadAsync(s => s.CountAsync("SELECT COUNT(*) FROM sessions")));
TempFolder.Delete(data);
}