This also fixes a bug where task IDs were being deallocated from the
wrong IDAllocator. I don't know if it was actually possible to cause any
real trouble with that mistake, nor do I know how to write a test for
it, but this makes the bug go away.
(cherry picked from commit 08d60d7521915b4f73fd3bb40a1aa159f4f31eb1)