{"record":{"id":"6b72e867af259bf4","repo":"QuantConnect/Lean","slug":"expected-a-single-subscription-to-exist-spx","errorCode":null,"errorMessage":"Expected a single subscription to exist ({spx})","messagePattern":"Expected a single subscription to exist \\((.+?)\\)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicatedIndexOptionSubscriptionRegressionAlgorithm.cs","lineNumber":42,"sourceCode":"namespace QuantConnect.Algorithm.CSharp\n{\n    /// <summary>\n    /// Reproduces https://github.com/QuantConnect/Lean/issues/7451, making sure no additional subscriptions are added for an index\n    /// after manually adding both the underlying and an option contract, with slightly different configurations like the fill forward value.\n    /// </summary>\n    public class DuplicatedIndexOptionSubscriptionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition\n    {\n        public override void Initialize()\n        {\n            SetStartDate(2021, 1, 4);\n            SetEndDate(2021, 1, 4);\n            SetCash(1000000);\n\n            var spx = AddIndex(\"SPX\", Resolution.Minute, fillForward: false).Symbol;\n\n            if (SubscriptionManager.Subscriptions.Single().Symbol != spx)\n            {\n                throw new RegressionTestException($\"Expected a single subscription to exist ({spx})\");\n            }\n\n            var spxOption = QuantConnect.Symbol.CreateOption(\n                spx,\n                Market.USA,\n                OptionStyle.European,\n                OptionRight.Call,\n                3200m,\n                new DateTime(2021, 1, 15));\n\n            AddIndexOptionContract(spxOption, Resolution.Minute);\n\n            if (SubscriptionManager.Subscriptions.Count() < 2)\n            {\n                throw new RegressionTestException(\"Expected subscriptions for the added index option contract\");\n            }\n\n            if (SubscriptionManager.Subscriptions.Count(x => x.Symbol == spx) != 1)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicatedIndexOptionSubscriptionRegressionAlgorithm.cs#L24-L60","documentation":"After AddIndex('SPX', Resolution.Minute, fillForward:false), this asserts SubscriptionManager.Subscriptions has exactly one entry and its Symbol equals spx. .Single() will throw if count != 1. It guards that adding the index creates exactly one subscription, no more. Failure means either zero or multiple subscriptions, or the single subscription's symbol differs from spx.","triggerScenarios":"AddIndex created more than one subscription (duplicate), or the symbol returned does not match. A SubscriptionManager refactor that adds auxiliary subscriptions or changes canonical symbol resolution.","commonSituations":"Default subscriptions being added automatically (e.g. a benchmark or a helper subscription); symbol canonicalization producing a different SID; fillForward/extendedMarket options triggering extra config entries.","solutions":["Dump SubscriptionManager.Subscriptions after AddIndex to count entries and their symbols.","Check AddIndex for any automatic auxiliary-subscription logic that was introduced.","Ensure the SPX canonical symbol matches the returned subscription Symbol (SID equality)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var subs = SubscriptionManager.Subscriptions.Select(s => s.Symbol).ToList();\nif (subs.Count != 1 || subs[0] != spx)\n{\n    foreach (var s in subs) Log($\"Subscription: {s}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid .Single() which throws before your message; assert the count and symbols explicitly.","Check for automatic auxiliary subscriptions (benchmark/helper) introduced by config changes.","Compare SIDs, not tickers, when validating subscription symbols."],"tags":["quantconnect","lean","regression-test","subscriptions","index","invariant"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}