fix(quotes): deactivate assets when positions close#838
Merged
afadil merged 1 commit intoafadil:mainfrom Apr 13, 2026
Merged
Conversation
…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
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.
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.
Summary
update_position_status_from_holdingsdetects a fully soldposition (quantity = 0), set
assets.is_active = falsealongsidethe existing
quote_sync_state.position_closed_dateupdate.the asset via
reactivate().and prevents the health check from flagging them as stale. Previously,
should_sync_asset()checkedAsset.is_active(always true) whilesync planning checked
QuoteSyncState.position_closed_date, causingclosed positions to pass the pre-filter and accumulate errors during
the 30-day grace period.
resolve_or_create_asseton newactivity creation, so same-day sell+rebuy is covered by both paths.
Test plan
cargo fmt,cargo clippy,cargo testall passpnpm format:check,lint,type-check,test,buildall passassets.is_active— change onlyaffects sync planning and health checks