Query history items are created once query has finished running, but this can lead to ordering differing from the order in which the user invoked queries, if queries take different amounts of time to run.
Instead create them immediately and asynchronously update their state when queries finish running.