fix(log): mark implausibly high FinancialDataLog entries as invalid#3884
Merged
Conversation
Between 2026-06-08 and 2026-06-15 ~3 969 FinancialDataLog rows were stamped valid=true while carrying a totalBalanceChf > 50 000 CHF — well above the expected operating-equity band of 20–30 k CHF. Add a one-shot data migration that retroactively sets valid=false on those rows so monitoring dashboards and anomaly alerts reflect the correct state of the period.
davidleomay
approved these changes
Jun 15, 2026
This was referenced Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Between 2026-06-08 13:12 UTC and 2026-06-15 10:30 UTC, approximately 3 969 `FinancialDataLog` rows were persisted with `valid = true` while carrying a `totalBalanceChf` well above the expected operating-equity band (20–30 k CHF).
The spike was caused by a transient accounting event: `plusBalanceChf` rose by > 200 k CHF while large orders were pending. Once the baseline had shifted to that elevated level, subsequent ticks produced balance deltas that fell within `financeLogTotalBalanceChangeLimit` (5 000 CHF), so the invalid flag was never triggered — even though the absolute total was implausible.
Verified on 2026-06-15 via `/gs/debug`:
```sql
SELECT COUNT(*), MIN(created), MAX(created)
FROM log
WHERE subsystem = 'FinancialDataLog'
AND created >= NOW() - INTERVAL '7 days'
AND (message::jsonb -> 'balancesTotal' ->> 'totalBalanceChf')::numeric > 50000
AND valid = true;
-- → 3 969 rows | 2026-06-08T13:12:39Z – 2026-06-15T10:30:34Z
```
Solution
One-shot data migration that retroactively sets `valid = false` on affected rows.
Threshold: `totalBalanceChf > 50 000 CHF` — conservative cut-off well above the historical normal band (~20–30 k) and well below the spike peak (~430 k CHF).
Design decisions
RepointAccountWalletForMergeMail); acts as an env-guard — no-op when rows don't exist (staging/dev)down()best-effortup()ranChecklist
up()— no table scan driftdown()implemented and limitation documentedprettier --checkpasses