QuantConnect/Lean · error · RegressionTestException

Unexpected delisting warning event: {delisting}

Error message

Unexpected delisting warning event: {delisting}

What it means

Once a delisting for _option is confirmed, this check applies to the DelistingType.Warning phase. It requires a strict ordering: the option must already have been sold (_optionSold), assigned (_optionAssigned), the underlying stock assigned (_stockAssigned), and no warning received yet (!_optionDelistedWarningReceived). If the warning arrives before all those preconditions hold, the engine delivered the delisting warning out of expected sequence.

Source

Thrown at Algorithm.CSharp/DuplicateOptionAssignmentRegressionAlgorithm.cs:137

                    throw new RegressionTestException($"Unexpected cancel event: {orderEvent}");
                }

                _orderCanceled = true;
            }
        }

        public override void OnDelistings(Delistings delistings)
        {
            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)

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Capture the values of _optionSold/_optionAssigned/_stockAssigned/_optionDelistedWarningReceived at throw time to see which precondition is unmet.
  2. Inspect the OptionAssignment/Exercise pipeline logs to confirm the assignment event actually fired before the delisting warning.
  3. Correct the engine ordering so assignment precedes the delisting warning, or adjust the expected sequence if the new order is intentional.

Example fix

// before
if (!_optionSold || !_optionAssigned || !_stockAssigned || _optionDelistedWarningReceived)
{
    throw new RegressionTestException($"Unexpected delisting warning event: {delisting}");
}

// after (include which flag is wrong)
var unmet = new[] { ("optionSold", _optionSold), ("optionAssigned", _optionAssigned), ("stockAssigned", _stockAssigned), ("warningAlready", _optionDelistedWarningReceived) }
    .Where(x => !x.Item2).Select(x => x.Item1);
throw new RegressionTestException($"Unexpected delisting warning event: {delisting}. Unmet: {string.Join(", ", unmet)}");
Defensive patterns

Strategy: validation

Validate before calling

static bool PreconditionsMet(params (string name, bool ok)[] checks)
    => checks.All(c => c.ok);

var ok = PreconditionsMet(
    ("optionSold", _optionSold),
    ("optionAssigned", _optionAssigned),
    ("stockAssigned", _stockAssigned),
    ("warningNotReceived", !_optionDelistedWarningReceived));
if (!ok) throw new RegressionTestException("Delisting warning received before preconditions met");

Prevention

When it happens

Trigger: DelistingType.Warning arrives before the assignment events fired, or a warning fires twice (second one trips _optionDelistedWarningReceived). Caused by reordering of the assignment/delisting pipeline or by option assignment being skipped.

Common situations: Changing exercise/assignment processing order versus delisting detection; data where the option's last trading date moves earlier than the assignment date; a regression in the OptionAssignment service.

Related errors


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