Fix runtime error when an option universe is removed and re-added in the same time step#9626
Merged
jhonabreul merged 8 commits intoJul 20, 2026
Conversation
jhonabreul
marked this pull request as ready for review
July 17, 2026 15:56
… in the same time step
…re-issuing them on removal
jhonabreul
marked this pull request as draft
July 17, 2026 22:04
jhonabreul
marked this pull request as ready for review
July 20, 2026 13:29
Martin-Molinero
approved these changes
Jul 20, 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.
Description
Removing a non-user-defined universe (e.g. an option chain universe via
RemoveSecurity(canonicalSymbol)) and adding a new universe with an equal configuration (e.g.AddOptionfor the same underlying) within the same time step caused an unhandled runtime error that stopped the algorithm:Cause: the removed universe is disposed synchronously, but its subscription removal is deferred to the next
SubscriptionSynchronizerloop. The new universe's subscription request then finds the slot still occupied by the stale subscription and throws.The fix:
Subscription.AddSubscriptionRequestno longer throws on universe subscription collisions: it returnsfalse, like it already did for user-defined universes.DisposeRequested,DataManagerparks the request instead of dropping it.DataManagerre-issues the parked request, creating the new universe's subscription in the now-free slot. It keeps the request's original start time (already adjusted to the previous tradable date) so the first selection happens right away, the same day.RemoveAllSubscriptions.Related Issue
N/A (reported by a user: a monthly-rebalancing options algorithm that removes its option subscriptions with
remove_securityand re-adds them withadd_optioncrashed whenever an underlying was selected in two consecutive months)Motivation and Context
Removing an option universe and re-adding one for the same underlying in the same time step (e.g. a scheduled event rebalancing option positions) is legitimate API usage and should not crash the algorithm.
Requires Documentation Change
No
How Has This Been Tested?
DataManagerTests.ReplacesSubscriptionOfUniverseRemovedAndReAddedInSameTimeStep: unit test reproducing the collision at theDataManagerlevel; asserts the request is parked while the stale subscription remains, and re-issued once it is removed.OptionUniverseRemovedAndReAddedRegressionAlgorithm(C#): removes and re-adds the AAPL option universe in the same time step; asserts option chain data flows both before and after the swap.OptionUniverseRemovedAndReAddedMemberCleanupRegressionAlgorithm(C#): re-adds the universe with a narrower filter; asserts deselected contracts' subscriptions are removed and removed security changes are emitted for them.Engine.DataFeedstest suite: 927 passed, 0 failed.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>