QuantConnect/Lean · error · RegressionTestException
Did not receive expected security changes removal! Got {_rec
Error message
Did not receive expected security changes removal! Got {_receivedSecurityChangesEvent} What it means
OnSecuritiesChanged increments _receivedSecurityChangesEvent only when AAA.1 appears in changes.RemovedSecurities. OnEndOfAlgorithm asserts it equals exactly 1. A value of 0 means the delisted security was never removed from the universe; a value >1 means it was removed more than once, indicating a universe-selection bug.
Source
Thrown at Algorithm.CSharp/DelistingEventsAlgorithm.cs:139
}
public override void OnEndOfAlgorithm()
{
if (!_receivedDelistedEvent)
{
throw new RegressionTestException("Did not receive expected delisted event");
}
if (!_receivedDelistedWarningEvent)
{
throw new RegressionTestException("Did not receive expected delisted warning event");
}
if (_dataCount != 13)
{
throw new RegressionTestException($"Unexpected data count {_dataCount}. Expected 13");
}
if (_receivedSecurityChangesEvent != 1)
{
throw new RegressionTestException($"Did not receive expected security changes removal! Got {_receivedSecurityChangesEvent}");
}
}
/// <summary>
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
/// </summary>
public bool CanRunLocally { get; } = true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
/// <summary>
/// Data Points count of all timeslices of algorithm
/// </summary>
public long DataPoints => 87;
View on GitHub (pinned to d2c3659f87)
Solutions
- Log every change in OnSecuritiesChanged (added + removed symbols) to see whether AAA.1 is present and how many times.
- Verify the delisting event for AAA.1 is in the data and is processed before algorithm end.
- If duplicate removals are a Lean regression, fix the universe removal deduplication logic rather than relaxing the assert.
- Confirm the symbol value comparison uses the same form (Value vs mapped Value) as the data provider.
Defensive patterns
Strategy: validation
Validate before calling
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var removed in changes.RemovedSecurities)
{
if (removed.Symbol.Value == "AAA.1")
{
if (_receivedSecurityChangesEvent >= 1)
Debug($"WARNING: duplicate removal of AAA.1");
_receivedSecurityChangesEvent++;
}
}
} Prevention
- Log all SecurityChanges (added/removed) to detect duplicate or missing removals.
- Compare symbols by SID when mapping is involved.
- Verify delisting events are in the data so removals actually fire.
When it happens
Trigger: AAA.1 is delisted but the universe manager does not emit a removal, or emits duplicate removal SecurityChanges events. Also fires if the symbol comparison removedSecurity.Symbol.Value == "AAA.1" never matches due to a symbol-mapping or ticker change.
Common situations: Lean version change in how delisted securities are removed from the universe, symbol mapping (mapped vs raw symbol value), or a data issue where the delisting event is not processed so the security is never dropped.
Related errors
- Expected {ExpectedSymbols.Count} stocks to be added to the a
- Expected symbols were not added to the algorithm
- Expected events didn't happen
- Unexpected Bar error
- Unexpected data count {_dataCount}. Expected 13
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/363372c5cf220c2b.
Report an issue: GitHub.