agent: update UnitStatePublisher locking + timing

rebased on #839