         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))

       (map (partial extensions/dereference sync))
       (filter #(= (:state (:content %)) :idle))))

(defmethod extensions/seal-resource? ZooKeeper
  [sync exhaust-node]
  (let [node-data (extensions/read-node sync exhaust-node)

        (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}))
