   (util/assert-is (= (state/current-context s1) (state/current-context s2)) "%s" [s1 s2])
   (= s1 s2))
 
-(defn wrapper? [sp] (#{:OC :SA} (first (sp-name sp))))
+;; Note: must always wrap (at least with SA), or we lose context.
+;; TODO: only :Atomic or :Pair inside, when SA off 
+;;(defn wrapper? [sp] (#{:OC :SA} (first (sp-name sp))))
+;; (comment  (if (wrapper? child-sp) child-sp (make-output-collecting-subproblem fs child-sp)))
+
 
 (defn atomic-name-fs [n] (util/match [[:Atomic ~fs] n] fs))
 (defn log-input [fs inp-set] (if *state-abstraction* (fs/get-logger fs inp-set) inp-set))


(defn- make-output-collecting-subproblem [fs inner-sp]
  (make-wrapped-subproblem
   (oc-name (sp-name inner-sp)) (input-set inner-sp) #{:Atomic :Pair} inner-sp
   identity
   (fn child-watch [sp child-sp] #_ (println inner-sp sp child-sp)
     (if (=-state-sets (get-output-set! inner-sp) (get-output-set! child-sp))
       (do (connect-and-watch! sp child-sp nil #(child-watch sp %2))
           (summaries/summary-changed! sp))
       (add-sp-child! sp 
         (if (wrapper? child-sp) child-sp (make-output-collecting-subproblem fs child-sp))
         false)))
   (fn refine-input [s ni]
     (if (= (input-set s) ni)
       s

(defn noeval [s] (throw (RuntimeException. (print-str s "not evaluable!"))))

(defn make-wrapped-subproblem [nm inp-set prefix-set inner-sp output-wrap child-watch ri-fn]
  (util/assert-is (contains? prefix-set (first (sp-name inner-sp))))
  (let [ret (traits/reify-traits
             [summaries/or-summarizable
              (simple-subproblem nm inp-set (sp-ts inner-sp) noeval ri-fn)])]
    (connect-and-watch! ret inner-sp
      (fn [] (set-output-set! ret (output-wrap (get-output-set! inner-sp))))
      (fn [inner-child] (child-watch ret inner-child)))
    ret))


