  ; Record deadlock causes,
  ; Don't try to detect deadlock, just infinitely cycle through preconds & let search take care of it? 
 ; Seems real deadlock detection is best. 
-(defn make-fire-action-hla
-  ([hierarchy effect-var a deadlock-set]
-    (let [reduced-pm (dissoc (:precond-map a) effect-var)]
-     (make-fire-action-hla 
-      hierarchy effect-var a deadlock-set reduced-pm
-      (:full-context hierarchy ) #_
-      (util/safe-get-in hierarchy [:precondition-context-map effect-var]) #_
-      (into #{(action-var effect-var)}
-        (apply concat
-          (for [p (keys reduced-pm)]
-            (cons (free-var p) 
-                  (cons (parent-var p effect-var) 
-                        (get-in hierarchy [:precondition-context-map p])))))))))
- ([hierarchy effect-var a deadlock-set reduced-pm pc]
-  (let [name          [:fire-action effect-var deadlock-set]
-        child-var-map (:child-var-map hierarchy)]
+
+;; TODO: speed up somehow?
+(defn precond-deadlocked? [s precond e-var]
+  (or (and (not (env/get-var s (free-var precond)))
+           (not (env/get-var s (parent-var precond e-var))))
+      (when-let [a (env/get-var s (action-var precond))]
+        (some #(precond-deadlocked? s % precond) (remove #{precond} (keys (:precond-map a)))))))
+
+(defn make-fire-action-hla  [hierarchy effect-var a]
+  (let [name          [:fire-action effect-var]
+        reduced-pm    (dissoc (:precond-map a) effect-var)
+        child-var-map (:child-var-map hierarchy)
+        pc            (:full-context hierarchy ) #_
+                      (util/safe-get-in hierarchy [:precondition-context-map effect-var]) #_
+                      (into #{(action-var effect-var)}
+                            (apply concat
+                                   (for [p (keys reduced-pm)]
+                                     (cons (free-var p) 
+                                           (cons (parent-var p effect-var) 
+                                                 (get-in hierarchy [:precondition-context-map p]))))))]
 ;    (println "FA" name)
-   (reify :as this
+  (reify :as this
     env/Action
       (action-name [] name)
       (primitive?  [] false)

          ;; Active precondition -- assigned, needs its value changed, not deadlock               
          (util/find-first #(and (env/get-var s (parent-var % effect-var))
                                 (not (= (env/get-var s %) (reduced-pm %)))
                                 (not (contains? deadlock-set %)))
                           (keys reduced-pm))
            [[(make-achieve-precondition-hla hierarchy x (reduced-pm x))
              (make-if-deadlock-hla hierarchy x 
                [(make-fire-action-hla hierarchy effect-var a (conj deadlock-set x) reduced-pm pc)]
                [(make-fire-action-hla hierarchy effect-var a #{} reduced-pm pc)])]]

          ;; Inactive precondition -- needs to be assigned.  
          (util/find-first #(env/get-var s (free-var %)) (keys reduced-pm))

          ;; Nothing to do here -- return upwards, or fail if goal-var
          :else
            (when-not (= effect-var sas/goal-var-name) [[]]))))
       (cycle-level-           [s] nil))))



