Fix false positive inactive hints for SimpleFin accounts during chunked imports (#573)

* Add tests and logic for zero balance handling and inactivity detection

- Updated `SimplefinItem::ImporterInactiveTest` to include cases for chunked imports, credit cards, and loans.
- Added logic to skip zero balance detection for liability accounts (e.g., credit cards, loans).
- Ensured zero balance runs are counted only once per sync to avoid false positives during chunked imports.

* Add nil safety

---------

Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
This commit is contained in:
LPW
2026-01-08 05:44:38 -05:00
committed by GitHub
parent 7866598057
commit e121969f2c
2 changed files with 87 additions and 16 deletions

View File

@@ -158,6 +158,16 @@ class SimplefinItem::Importer
return
end
# Skip zero balance detection for liability accounts (CreditCard, Loan) where
# 0 balance with no holdings is normal (paid off card/loan)
account_type = simplefin_account.current_account&.accountable_type
return if %w[CreditCard Loan].include?(account_type)
# Only count each account once per sync run to avoid false positives during
# chunked imports (which process the same account multiple times)
zero_balance_seen_keys << key if zeroish_balance && no_holdings
return if zero_balance_seen_keys.count(key) > 1
if zeroish_balance && no_holdings
stats["zero_runs"][key] = stats["zero_runs"][key].to_i + 1
# Cap to avoid unbounded growth
@@ -173,6 +183,11 @@ class SimplefinItem::Importer
end
end
# Track accounts that have been flagged for zero balance in this sync run
def zero_balance_seen_keys
@zero_balance_seen_keys ||= []
end
# Track seen error fingerprints during a single importer run to avoid double counting
def seen_errors
@seen_errors ||= Set.new