From 84a7471ea2d6801ca65369942025554dfaa9a4fd Mon Sep 17 00:00:00 2001 From: Alonso Torres Date: Fri, 20 Nov 2026 14:13:55 +0100 Subject: [PATCH] :bug: Keep the MCP connection when an account first leaves the workspace (#13192) The MCP controller restarts its runtime when the profile id changes, and it compared ids by object identity. Leaving the workspace clears the transit uuid cache, and on the first visit it also saves the workspace-visited prop, which reloads the profile. The reloaded id came back as a new uuid instance, so MCP init ran again: it closed the plugin, dropped the WebSocket and left the new plugin disconnected. Compare profile ids by value, and add a regression test that sends the same id as two distinct uuid instances. Closes #13128 AI-assisted-by: claude-opus-5-5 --- frontend/src/app/main/data/workspace/mcp.cljs | 3 ++- .../data/workspace_mcp_test.cljs | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/main/data/workspace/mcp.cljs b/frontend/src/app/main/data/workspace/mcp.cljs index 07f766ab61..8ca0af2a60 100644 --- a/frontend/src/app/main/data/workspace/mcp.cljs +++ b/frontend/src/app/main/data/workspace/mcp.cljs @@ -372,7 +372,8 @@ (ptk/type? ::auth/logged-out %))) (rx/map #(when (ptk/type? ::du/set-profile %) (:id (deref %)))) - (rx/pipe (rxo/distinct-contiguous)) + ;; by value: a reloaded profile can carry its id in a new uuid instance + (rx/pipe (rxo/distinct-contiguous =)) (rx/switch-map (fn [profile-id] (if profile-id diff --git a/frontend/test/frontend_tests/data/workspace_mcp_test.cljs b/frontend/test/frontend_tests/data/workspace_mcp_test.cljs index 3906fb7f0c..51e54a34eb 100644 --- a/frontend/test/frontend_tests/data/workspace_mcp_test.cljs +++ b/frontend/test/frontend_tests/data/workspace_mcp_test.cljs @@ -46,6 +46,29 @@ (rx/dispose! subscription) (rx/end! stream)))))))) +(t/deftest ^:async test-initialize-ignores-reloaded-profile + (let [stream (rx/subject) + events (atom []) + id (uuid/next) + ;; equal id in a distinct instance, as a decode after the uuid cache is cleared + reloaded (uuid/uuid (str id))] + (t/is (not (identical? id reloaded))) + (await + (mock/with-mocks* + {cf/flags #{:mcp} + preg/wait-for-runtime (fn [] (js/Promise.resolve true))} + (let [subscription (rx/subs! #(swap! events conj (ptk/type %)) + (ptk/watch (mcp/initialize) {} stream))] + (try + (rx/push! stream (du/set-profile {:id id})) + (await (a/wait-for #(= 1 (count @events)))) + (rx/push! stream (du/set-profile {:id reloaded})) + (await (a/settle)) + (t/is (= [:app.main.data.workspace.mcp/init] @events)) + (finally + (rx/dispose! subscription) + (rx/end! stream)))))))) + (t/deftest test-update-mcp-status (t/testing "enables MCP in profile props and mcp state" (let [state {:profile {:props {:mcp-enabled false}} :mcp {}}