fix regression from #3968

Not ordering the IDs caused incorret ones returned

The spec is totally at the wrong level but I couldn't make
something up that exposed the bug at a deeper level :(