fix: snapshot the charts for the in-run results analysis - #9848
Merged
Martin-Molinero merged 4 commits intoSep 30, 2026
Merged
Martin-Molinero merged 4 commits into
Martin-Molinero merged 4 commits into
Conversation
- clone the charts under the chart lock before building the intermediate backtest result - the margin usage analysis enumerated the live chart while the algorithm thread sampled it - add a handler test that samples the margin chart while the in-run analysis runs
- reset the private first store time by reflection so the first update stores at once
- add the protected virtual InitialResultStoreDelay property, 5 seconds by default - the in-run analysis test overrides it to zero instead of resetting the private field by reflection
The in-run and final results hand StoreResult a copy of the charts taken under the chart lock, so it stores that copy instead of cloning the charts a second time. The final result takes its copy too, since the algorithm thread can still be sampling when it was stopped for exceeding a limit. The single point portfolio margin series are now removed from the stored result, like the live handler does, instead of from the charts the algorithm keeps sampling. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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
The in-run results analysis received the handler's live charts.
PortfolioMarginUsageAnalysisenumerates the "Portfolio Margin" chart while the algorithm thread keeps sampling it at midnight, so the enumeration failed:BacktestingResultHandler.Update()now clones the charts underChartLockbefore building the intermediate result, the way the live handler does for its packets, so the in-run analyses and the stored result read a consistent copy. TheResultsAnalyzer.Rundoc comment that accepted the torn read is updated.Side effect:
StoreResultno longer strips single-point series from the live margin chart during the run, only from the copy. Stored files and sent packets are unchanged.Related PR(s)
#9632 added the in-run analysis.
Related Issue
N/A
Motivation and Context
The handler catches the exception and logs it as an error, so the backtest completes, but the error line lands on stderr and the cloud shows it in the backtest error box. Users saw a fatal-looking error on a completed backtest.
Requires Documentation Change
No
How Has This Been Tested?
BacktestingResultHandlerTests.InRunAnalysisRunsWhileTheAlgorithmSamplesTheCharts: a 100,000-point margin chart, a task re-sampling its last point under the chart lock, and the handler's update loop running the in-run analysis. Fails on master with the stack above, passes with the fix, 3 reruns.BacktestingResultHandlerTests,ResultsAnalyzerInRunTestsandResultsAnalyzerTests: 41 of 41 passed.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>