QuantConnect/Lean · error · RegressionTestException
Order failure: {history[i].EndTime} > {history[i + 1].EndTim
Error message
Order failure: {history[i].EndTime} > {history[i + 1].EndTime} at index {i}. What it means
After fetching history, the algorithm iterates consecutive pairs and asserts history[i].EndTime <= history[i+1].EndTime (ascending). A failure means the custom-data Sort=true flag did not re-order descending source data into ascending order in the history result.
Source
Thrown at Algorithm.CSharp/DescendingCustomDataObjectStoreRegressionAlgorithm.cs:111
{
if (_receivedData.Count == 0)
{
throw new RegressionTestException("Custom data was not fetched");
}
var history = History<SortCustomData>(_customSymbol, StartDate, EndDate, Resolution.Hour).ToList();
if (history.Count != _receivedData.Count)
{
throw new RegressionTestException("History request returned different data than expected");
}
// Iterate through the history collection, checking if the EndTime is in ascending order.
for (int i = 0; i < history.Count - 1; i++)
{
if (history[i].EndTime > history[i + 1].EndTime)
{
throw new RegressionTestException($"Order failure: {history[i].EndTime} > {history[i + 1].EndTime} at index {i}.");
}
}
}
/// <summary>
/// Final status of the algorithm
/// </summary>
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
/// <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 => true;
/// <summary>
/// This is used by the regression test system to indicate which languages this algorithm is written in.
/// </summary>
public List<Language> Languages => new() { Language.CSharp, Language.Python };View on GitHub (pinned to d2c3659f87)
Solutions
- Confirm GetSource sets Sort = true on the SubscriptionDataSource in all paths (subscription and history share it, but verify history invokes GetSource).
- Check whether EndTime is overridden in SortCustomData; BaseData.EndTime defaults to Time, which may need overriding for the ordering to be meaningful.
- If the Sort flag is not respected by history, fix the Lean history data-reading path to sort.
- Log the EndTime sequence to confirm where the inversion occurs.
Defensive patterns
Strategy: validation
Validate before calling
for (int i = 0; i < history.Count - 1; i++)
{
if (history[i].EndTime > history[i + 1].EndTime)
{
Debug($"Inversion at {i}: {history[i].EndTime} > {history[i+1].EndTime}");
// optionally re-sort as a safety net
}
} Prevention
- Confirm Sort = true is set on the SubscriptionDataSource in GetSource.
- Override EndTime in custom data if the default (Time) is not the correct bar boundary.
- Log the EndTime sequence to catch where sorting fails.
When it happens
Trigger: SortCustomData.GetSource sets Sort = true, but the history path does not honor it, so points arrive in the original descending order. Also fires if EndTime is computed incorrectly (e.g., defaults to Time instead of Time + period).
Common situations: A Lean regression where the history pipeline skips the Sort step that the subscription pipeline applies, or a custom data type that does not set EndTime correctly for bar-style data.
Related errors
- History request returned different data than expected
- Unexpected universe data count {historicalSelectionData.Coun
- Unexpected history count: {history.Count}
- Unexpected history data start time
- Unexpected history data end time
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/1cb12cce4b7f81c2.
Report an issue: GitHub.