QuantConnect/Lean · error · RegressionTestException

Unexpected delisting event: {delisting}

Error message

Unexpected delisting event: {delisting}

What it means

This is the DelistingType.Delisted (final) phase guard for _option. It requires every prior lifecycle step complete (_optionSold, _optionAssigned, _stockAssigned, _optionDelistedWarningReceived) and the option not already delisted (!_optionDelisted). The final delisting must come exactly once, after the warning. A failure means the final delisting event arrived without its preceding warning or arrived a second time.

Source

Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:146

            if (!delistings.TryGetValue(_option, out var delisting))
            {
                throw new RegressionTestException($"Unexpected delisting events");
            }

            if (delisting.Type == DelistingType.Warning)
            {
                if (!_optionSold || !_optionAssigned || !_stockAssigned || _optionDelistedWarningReceived)
                {
                    throw new RegressionTestException($"Unexpected delisting warning event: {delisting}");
                }

                _optionDelistedWarningReceived = true;
            }
            else
            {
                if (!_optionSold || !_optionAssigned || !_stockAssigned || !_optionDelistedWarningReceived || _optionDelisted)
                {
                    throw new RegressionTestException($"Unexpected delisting event: {delisting}");
                }

                _optionDelisted = true;
            }
        }

        public override void OnEndOfAlgorithm()
        {
            if (!_optionSold)
            {
                throw new RegressionTestException("Option was not sold");
            }

            if (!_optionAssigned)
            {
                throw new RegressionTestException("Option was not assigned");
            }

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Verify _optionDelistedWarningReceived is true when Delisted fires; if false, the warning was never emitted.
  2. Check Lean's DelistingType handling (Warning vs Delisted) in the Security.Service provider for duplicate emission.
  3. Ensure the final delisting is idempotent or update the test if one-step delisting is the new design.
Defensive patterns

Strategy: validation

Validate before calling

if (!_optionDelistedWarningReceived || _optionDelisted)
{
    throw new RegressionTestException(
        $"Final delisting out of order (warning={_optionDelistedWarningReceived}, delisted={_optionDelisted})");
}

Prevention

When it happens

Trigger: Delisted event arrives without a prior Warning (warning skipped), or Delisted arrives twice. Engine change that drops/merges the warning step, or duplicate delisting emission.

Common situations: Refactoring the delisting provider so Warning and Delisted collapse into one event; mapping change that changes delisting dates; remapping logic that re-emits delisting.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/e7f95c5a7bca3b50. Report an issue: GitHub.