         state (assoc peer-state :state :dead)]
     (:node (extensions/create-at sync :peer-state (:id peer-state) state))))
 
+
+;;; Ensure "tasks" always has the same order.
+;;; Ensure that node creation is idempotent.
 (defmethod extensions/plan-job ZooKeeper
   [sync job-id tasks catalog workflow]
   (let [catalog-node (:node (extensions/create-at sync :catalog job-id catalog))

    (extensions/create sync :job job-id)  
    job-id))

(defmethod extensions/mark-offered ZooKeeper
  [sync task-node peer-id nodes]
  (let [peer-state-path (extensions/resolve-node sync :peer-state peer-id)

        (when-not (= (:state peer-state) :dead)
          (extensions/create-at sync :peer-state (:id node-data) state))

        ;; Peer may have died just after completion, n may again be 0
        (if (and (<= n 1) (not complete?))
          (do (complete-task sync (:task-node peer-state))
              (extensions/write-node sync cooldown-down {:completed? true}))
