Skip to content

fix(quotes): deactivate assets when positions close#838

Merged
afadil merged 1 commit intoafadil:mainfrom
triantos:fix/skip-closed-position-sync
Apr 13, 2026
Merged

fix(quotes): deactivate assets when positions close#838
afadil merged 1 commit intoafadil:mainfrom
triantos:fix/skip-closed-position-sync

Conversation

@triantos
Copy link
Copy Markdown
Contributor

Summary

  • When update_position_status_from_holdings detects a fully sold
    position (quantity = 0), set assets.is_active = false alongside
    the existing quote_sync_state.position_closed_date update.
  • When a position reopens (quantity > 0 after being closed), reactivate
    the asset via reactivate().
  • This stops the sync from attempting to fetch quotes for closed positions
    and prevents the health check from flagging them as stale. Previously,
    should_sync_asset() checked Asset.is_active (always true) while
    sync planning checked QuoteSyncState.position_closed_date, causing
    closed positions to pass the pre-filter and accumulate errors during
    the 30-day grace period.
  • Reactivation is also handled by resolve_or_create_asset on new
    activity creation, so same-day sell+rebuy is covered by both paths.

Test plan

  • cargo fmt, cargo clippy, cargo test all pass
  • Frontend: pnpm format:check, lint, type-check, test, build all pass
  • Verified no UI endpoints filter by assets.is_active — change only
    affects sync planning and health checks

…open

When update_position_status_from_holdings detects a position has been
fully sold (quantity = 0), set assets.is_active = false in addition to
marking the sync state as inactive. This prevents the health check from
flagging closed positions as having stale quotes, and stops the sync
from attempting to fetch quotes for assets no longer held.

When a position reopens (quantity > 0 after being closed), reactivate
the asset. The existing resolve_or_create_asset path also reactivates
on new activity creation, so both paths are covered.
@afadil afadil merged commit 443a0f9 into afadil:main Apr 13, 2026
3 checks passed
afadil added a commit that referenced this pull request Apr 14, 2026
…tus update

Swallowed errors via warn!() could leave Asset.is_active out of sync
with QuoteSyncState, reproducing the bug that #838 fixed. Use ? to
propagate consistently with the adjacent sync_state_store calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants