In that rare case when a set of node heads are not in cache (none of them!), the DataBackingStore.GetNodeHeads method fails to preserve the original order.
If in the method above all loaded heads go to the unloadHeads collection (the nodeHeads collection remains empty), sorting is switched off (probably for performance reasons). In this case the result list will contain ids in the raw db order, instead of the original, sorted order.
Solution
Maybe the solution is to remove the condition and sort the result list always.
In that rare case when a set of node heads are not in cache (none of them!), the DataBackingStore.GetNodeHeads method fails to preserve the original order.
https://github.com/SenseNet/sensenet/blob/aa31792ae03ee53a1213b8cdc68197dbad544471/src/Storage/DataBackingStore.cs#L97
If in the method above all loaded heads go to the unloadHeads collection (the nodeHeads collection remains empty), sorting is switched off (probably for performance reasons). In this case the result list will contain ids in the raw db order, instead of the original, sorted order.
Solution
Maybe the solution is to remove the condition and sort the result list always.