{"record":{"id":"6f2b18de5d9fa4d1","repo":"QuantConnect/Lean","slug":"order-was-not-canceled","errorCode":null,"errorMessage":"Order was not canceled","messagePattern":"Order was not canceled","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs","lineNumber":182,"sourceCode":"\n            if (!_stockAssigned)\n            {\n                throw new RegressionTestException(\"Stock was not assigned\");\n            }\n\n            if (!_optionDelistedWarningReceived)\n            {\n                throw new RegressionTestException(\"Option delisting warning was not received\");\n            }\n\n            if (!_optionDelisted)\n            {\n                throw new RegressionTestException(\"Option was not delisted\");\n            }\n\n            if (!_orderCanceled)\n            {\n                throw new RegressionTestException(\"Order was not canceled\");\n            }\n\n            var openOrders = Transactions.GetOpenOrders();\n            if (openOrders.Count != 0)\n            {\n                throw new RegressionTestException(\"There should be no open orders\");\n            }\n\n            if (!Portfolio.Invested)\n            {\n                throw new RegressionTestException(\"Portfolio should be invested\");\n            }\n\n            // We should have the stock since the option was assigned\n            if (Portfolio.Positions.Groups.Single().Single().Symbol != _stock)\n            {\n                throw new RegressionTestException(\"Portfolio should have the stock\");\n            }","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs#L164-L200","documentation":"Asserts _orderCanceled: during the algorithm, an order was canceled (set in the OnOrderEvent cancel branch seen in the SOURCE). The test expects a specific order to be canceled after the option is assigned/delisted. Failure means the cancellation path did not execute.","triggerScenarios":"The order that should be canceled (e.g. a remaining open option order after delisting) was never submitted, or its cancel event did not arrive as OrderStatus.Canceled.","commonSituations":"Lean's automatic cancellation of open orders on delisting changed; the order fill model filled the order instead of canceling it; a change to order cancellation event dispatch.","solutions":["Inspect the open-order log to see if the target order existed and whether it was filled vs canceled.","Trace the delisting-triggered order cancellation logic in the TransactionHandler/AlgorithmManager.","Verify the OnOrderEvent cancel branch (OrderEvent.Status == Canceled) sets _orderCanceled."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Inspect whether the target order exists and its status\nvar open = Transactions.GetOpenOrders(_option);\nvar all = Transactions.GetOrders(_option);\nvar canceled = all.Where(o => o.Status == OrderStatus.Canceled).ToList();\nif (canceled.Count == 0) Log($\"No canceled order for {_option}. Open={open.Count}, Total={all.Count}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Log order status transitions (submitted/filled/canceled) for the option throughout the run.","Confirm the engine cancels open option orders on delisting.","Verify OnOrderEvent maps OrderStatus.Canceled to the flag."],"tags":["quantconnect","lean","regression-test","orders","cancellation","postcondition"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}