Entries of unknown outcome hold the account until settled; wipes keep their guards

Fifth review round (1eb0736):

- An entry now has three outcomes. Filled (confirmed): one-and-done is done
  for the day. Never placed: leg taken back, free to retry. Unknown (an ack
  or fill that never came back): the account — any mode — is held until a
  good sync at least 90s later shows it flat with realized P&L unchanged,
  then the leg is taken back and it may retry. Stop-after-all counts it in
  play meanwhile. This closes both the day-long bench of 52ed9c7 and the
  stacked re-entries of 1eb0736.
- Tradovate cancels an acked order whose fill didn't come within 30s (as
  TopstepX already does), so a retry can't sit beside a still-working one.
- A wipe keeps the rebuild's guards: wipeAccountData leaves the Cash History
  baseline, roll base, wipe hold, pre-wipe fund signature and the
  resolver's inferred size in account_meta; the routes forget history
  before wiping (so the stored rows are still there to read), and a wipe
  hold restored after a restart keeps its pre-wipe yardstick.
- Wipe routes take the set of typed accounts before wiping, so an account
  the resolver un-assigns mid-rebuild still counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-09-24 21:12:51 -05:00
co-authored by Claude Opus 5.5
parent 1eb0736fbe
commit 8e66631b0e
5 changed files with 114 additions and 25 deletions
+6 -3
View File
@@ -21,16 +21,19 @@ export async function POST(_req: Request, { params }: { params: Promise<{ id: st
const account = client.accountList.find((a) => a.id === accountId);
if (!account) continue;
wipeAccountData(accountId);
// Read before the wipe: the resolver may un-assign it mid-rebuild.
const ours = Boolean(getAccountConfig(accountId).accountType);
// Clear the in-memory view too — a failed refetch must leave the
// account visibly empty, not showing the data that was just wiped —
// and out of trading until a fetch rebuilds it.
// and out of trading until a fetch rebuilds it. First, so the client
// reads the stored rows it keeps as the rebuild's yardstick.
client.forgetHistory(accountId, account.name);
wipeAccountData(accountId);
await client.fetchDaysTraded([accountId]);
const loaded = client.historyReady(accountId) || !getAccountConfig(accountId).accountType;
const loaded = client.historyReady(accountId) || !ours;
return NextResponse.json({
ok: true,
entries: (client.dailyPnL[accountId] ?? []).length,
+9 -5
View File
@@ -22,17 +22,21 @@ export async function POST() {
await Promise.all(clients.map(async (client) => {
// Forgotten, the accounts read unloaded and stay out of trading
// until the refetch below (or, if it fails, a later one) lands.
const ids = client.accountList.map((account) => account.id);
// Taken before the wipe: the resolver may un-assign an account while
// the rebuild runs, and it still counts. Accounts with no type aren't
// traded, so they aren't failures.
const ours = client.accountList.filter((account) => getAccountConfig(account.id).accountType).map((a) => a.id);
for (const account of client.accountList) {
wipeAccountData(account.id);
// History first: the client reads the stored rows it keeps as the
// rebuild's yardstick before they go.
client.forgetHistory(account.id, account.name);
wipeAccountData(account.id);
wiped++;
}
await client.fetchDaysTraded();
// Counted from the result, not the fetch's own tally: a client with
// no session fetches nothing and reports no failures. Accounts with
// no type aren't traded, so they aren't failures either.
failedAccounts += ids.filter((id) => getAccountConfig(id).accountType && !client.historyReady(id)).length;
// no session fetches nothing and reports no failures.
failedAccounts += ours.filter((id) => !client.historyReady(id)).length;
}));
return NextResponse.json({ ok: true, wiped, failedAccounts });