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
- Verify _optionDelistedWarningReceived is true when Delisted fires; if false, the warning was never emitted.
- Check Lean's DelistingType handling (Warning vs Delisted) in the Security.Service provider for duplicate emission.
- 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
- Treat delisting as a two-phase state machine and assert transitions explicitly.
- Make the final-delisting step idempotent in the engine so it cannot fire twice.
- Include prior-phase flags in the final-delisting assertion message.
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
- Unexpected delisting warning event: {delisting}
- Unexpected delisting events
- Option delisting warning was not received
- Option was not delisted
- Unexpected cancel pending event: {orderEvent}
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/e7f95c5a7bca3b50.
Report an issue: GitHub.