WIP: task state machine

This is just some experimental refactoring I did.

I noticed `prune` isn't being invoked from methods like `get_work` and I wanted to see if we can make `prune` incremental rather than something that requires full passes through the data set. Ended up having to refactor a lot of stuff related to task state.

Does it make sense? Not sure if it simplified stuff. Is it a step in the right direction? I can spend some more time trying to get this into a better state