Fix bug where transitions would be added to non-existent states

Fix bug where transitions would be added to non-existent states.
This would occur because cleanupFailedPlan would add a transition
to a new state, but the new state would not actually be added to
the state machine. Agent will now occasionally finish on a three
state machine, and will occasionally get it correct minus an
extraneous unreachable state.