I pushed 0001 after doing some hacking on it --- it was sloppy about datatypes, and about whether the invalid-entry value is 0 or -1, and it was just wrong about keeping the list in backendid order. (You can't conditionally skip looking for where to put the new entry, if you want to maintain the order. I thought about just defining the list as unordered, which would simplify joining the list initially, but that could get pretty cache-unfriendly when there are lots of entries.)
0002 is now going to need a rebase, so please do that.
Thanks for this, and good catch. Looks like I didn't test the first patch by itself very well.