new assignJobs algorithm. Internally consistent and agent events are only sent when the internal state is correct. Aka the internal state always corresponds to events sent

* also added some debugging in agent code