Simplify failure definition.
Rewrite query state machine with become().

Previously we used a "manual" state machine by explicitly keeping an enum field
with the state. The new implementation uses explicit actor behaviors as states
to significantly simplify the logic of the implementation.