     (swap! session assoc #'repl-state-ref (atom {})))
 
   (let [state-ref (get @session #'repl-state-ref)
-        {:keys [build-id worker]} @state-ref]
+        session-id (-> session meta :id)
+        {:keys [build-id worker]} (get @state-ref session-id)]
     (if-not build-id
       msg
       (assoc msg ::state-ref state-ref ::worker worker ::build-id build-id))))

        (-> (async/sliding-buffer 100)
            (async/chan))

        state-ref
        (get @session #'repl-state-ref)]

    (reset! state-ref
      {:init-msg msg
       :last-msg msg
       :session session

    (transport/send transport res)))

(defn do-repl-quit [state-ref session]
  (let [session-id (-> session meta :id)
        {:keys [clj-ns watch-chan]} (get @state-ref session-id)]

    (swap! state-ref dissoc session-id)
    (async/close! watch-chan)

    (swap! session assoc
      #'*ns* clj-ns
      #'cider.piggieback/*cljs-compiler-env* nil)))
