{"record":{"id":"fce0a85aec282792","repo":"QuantConnect/Lean","slug":"scheduled-event-did-not-assert-history-call-as-man","errorCode":null,"errorMessage":"Scheduled Event did not assert history call as many times as expected: {_successCount}/49","messagePattern":"Scheduled Event did not assert history call as many times as expected: (.+?)/49","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs","lineNumber":81,"sourceCode":"\n            Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall);\n        }\n\n        private void MakeHistoryCall()\n        {\n            var history = History(10, Resolution.Minute);\n            if (history.Count() < 10)\n            {\n                throw new RegressionTestException($\"Empty history at {Time}\");\n            }\n            _successCount++;\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (_successCount < ExpectedHistoryCallCount)\n            {\n                throw new RegressionTestException($\"Scheduled Event did not assert history call as many times as expected: {_successCount}/49\");\n            }\n        }\n\n        /// <summary>\n        /// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event\n        /// </summary>\n        /// <param name=\"slice\">The current slice of data keyed by symbol string</param>\n        public override void OnData(Slice slice)\n        {\n            if (!Portfolio.Invested)\n            {\n                foreach (var chain in slice.FutureChains)\n                {\n                    foreach (var contract in chain.Value)\n                    {\n                        Log($\"{contract.Symbol.Value},\" +\n                            $\"Bid={contract.BidPrice.ToStringInvariant()} \" +\n                            $\"Ask={contract.AskPrice.ToStringInvariant()} \" +","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs#L63-L99","documentation":"OnEndOfAlgorithm asserts the hourly scheduled history probe succeeded at least ExpectedHistoryCallCount (49) times. _successCount < expected means the scheduled MakeHistoryCall either did not fire often enough or fired but failed the per-call bar-count check too many times, so history was unreliable across the run.","triggerScenarios":"OnEndOfAlgorithm runs with _successCount < ExpectedHistoryCallCount (49) — the every-hour scheduled event did not accumulate enough successful (>=10-bar) history calls over the backtest span.","commonSituations":"Backtest date span shortened so fewer than 49 hourly probes fit; many probes failed the >=10 bar check (data gaps/warmup); the scheduled event TimeRules.Every(TimeSpan.FromHours(1)) fired less often than expected; market hours reduced the count.","solutions":["Confirm the backtest date span yields >= 49 hourly scheduled triggers.","Ensure each MakeHistoryCall returns >= 10 bars (fix error 15 root causes: warmup, resolution, gaps).","Verify TimeRules.Every(TimeSpan.FromHours(1)) aligns with open market hours across the span.","Adjust ExpectedHistoryCallCount if the date span legitimately changed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"public override void OnEndOfAlgorithm()\n{\n    if (_successCount < ExpectedHistoryCallCount)\n    {\n        Log($\"History probes succeeded {_successCount}/{ExpectedHistoryCallCount}. \" +\n            \"Check date span, warmup, and per-call bar counts.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the date span yields >= ExpectedHistoryCallCount hourly triggers.","Fix per-call short-history causes (warmup, resolution, gaps).","Align TimeRules.Every with open market hours."],"tags":["futures","history","scheduled-event","regression-test","invariant"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}