Repository navigation
Schedule the brokerage reconnect check from the wall clock - #10271
Closed
quantconnect-kronos[bot] wants to merge 1 commit into
Closed
quantconnect-kronos[bot] wants to merge 1 commit into
quantconnect-kronos[bot] wants to merge 1 commit into
Conversation
DefaultBrokerageMessageHandler decided whether a market was about to open from the algorithm time, then computed the check's delay from the wall time. When the algorithm time lags, during warm up or just before the pre-open cutoff, the delay came out negative and the check never started, so a disconnected live algorithm kept running. Use one wall clock for both, and run a check that is already due instead of skipping it. Closes #10270 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Martin-Molinero
deleted the
kronos/bug-67-outage-disconnect-grace-period
branch
December 1, 2026 15:49
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.
Closes #10270
Description
When a brokerage reports
Disconnect,DefaultBrokerageMessageHandlerwaits before it stops the live algorithm. It waits 15 minutes when an exchange opens within the next 5 minutes. Otherwise it waits until 5 minutes before the next open.To make that choice it read the algorithm time, but it computed the delay from the wall time. A live algorithm's time lags behind the wall time: by the warm-up period during warm-up, and by up to a slice in normal operation.
new CancellationTokenSource(delay)threw and the check was never scheduled.Brokerage.OnMessagehad already recorded the brokerage as disconnected, so it dropped every laterDisconnectas a duplicate. The algorithm kept running while disconnected, with no further shutdown check.The change:
DateTime.UtcNowonce and uses it for the open check, the next market open and the delay.Task.Runno longer receives the token. A token that is already cancelled used to skip the task body, and with itCheckReconnected. AReconnectbefore the task starts is still handled, becauseCheckReconnecteddoes nothing while connected.The handler's public API is unchanged. It serves every brokerage that reports
Disconnect. QuantConnect/Lean.Brokerages.Tradier#68 starts reporting Tradier API outages through it.Not changed: an algorithm whose securities are all custom data still fails in
Min(), as before. That is #10262.Tests
Tests/Engine/DefaultBrokerageMessageHandlerTests.cshas two new tests:DoesNotThrowOnDisconnectDuringWarmUpWhenAlgorithmTimeIsInThePast: the algorithm time is 400 days behind and the algorithm is still warming up.DoesNotThrowOnDisconnectWhenTheAlgorithmTimeLagsBehindThePreOpenCutoff: the algorithm time is 2 s before the pre-open cutoff and the wall time is 2 s after it.Both fail on
masterwithArgumentOutOfRangeException (Parameter 'delay')and pass with this change.dotnet test Tests/QuantConnect.Tests.csproj --filter "FullyQualifiedName~DefaultBrokerageMessageHandlerTests": 4 passed on this branch. Onmaster, the 2 new tests fail.The full suite, run as CI runs it:
dotnet build /p:Configuration=Release QuantConnect.Lean.slnand thendotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "TestCategory!=TravisExclude&TestCategory!=ResearchRegressionTests". Result: 40054 passed, 0 failed, 112 skipped.Tested end to end with the Tradier brokerage, which reported a sustained 503 outage as
Disconnectto this handler (5 s initial delay, default 5 minute pre-open threshold). Results:masterDisconnects were droppedmasterIn every case where the change stopped the algorithm, it did so within 120 s, with the brokerage's outage message as the runtime error.