Finish an interrupted rebuild and replay the past without acting on it

The independent review found that a rebuild cut halfway was never finished
(stops canceled or lowered), that old stop executions replayed from the broker
queued a real sale, that a pending "close all" survived the restore, and that
reconciliation and corporate actions touched accounts not rebuilt yet. The
rebuild now keeps its starting point until it ends, protects the bot before the
first row, meets the splits at their date and leaves the ledger alone until it
is done. Dividends count the shares of after a split. A failed restore of a
missing SQLite file leaves no empty database, and a failed migration can be
tried again from the choice page.

refs #69 #75

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 22:15:34 +01:00
1 parent 24e20584d4
commit 5ef54b6f2a
17 files changed
+613 -80

No files matched your search

+47 -1
View File
@@ -136,7 +136,53 @@ internal sealed partial class AnubisHost(
/// For an error-page choice that writes into a missing SQLite file: the only place where a known installation gets a
/// new one. Called while the choice holds <see cref="ExclusiveAsync"/>.
/// </summary>
internal Database OpenForChoice() => _db ??= Database.Open(Config.Db!, allowCreate: SqliteFileMissing);
internal Database OpenForChoice()
{
if (_db is null)
{
_createdByChoice = SqliteFileMissing;
_db = Database.Open(Config.Db!, allowCreate: _createdByChoice);
}
return _db;
}
private bool _createdByChoice;
/// <summary>
/// A choice that failed or was cut halfway leaves nothing open that could create the missing file, and what it had
/// begun to write steps aside: moved and not deleted, because in the meantime the true file may have come back.
/// </summary>
internal async Task AbandonChoiceAsync()
{
if (!_createdByChoice || _db is null)
{
return;
}
await _db.DisposeAsync().ConfigureAwait(false);
_db = null;
_createdByChoice = false;
var path = Config.Db!.SqlitePath!;
var aside = path + ".incompleto-" + clock.UtcNow.ToString("yyyyMMdd-HHmmss", System.Globalization.CultureInfo.InvariantCulture);
foreach (var part in new[] { "", "-wal", "-shm" })
{
try
{
if (File.Exists(path + part))
{
File.Move(path + part, aside + part, overwrite: true);
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
LogStepFailed(logger, ex);
}
}
}
/// <summary>The choice is done: the database it opened is the one in use.</summary>
internal void KeepChoice() => _createdByChoice = false;
/// <summary>Holds the loop still while an error-page choice works on the database.</summary>
internal async Task<IDisposable> ExclusiveAsync(CancellationToken cancellationToken)