From 0362fde9e25be88dc3c8660b99271520d87c6ac3 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 27 Jun 2026 14:58:12 +0000 Subject: [PATCH] Fix Connect approval toggle stuck on load failure, mint replay loss, and concurrent action race - Revert decodeSecurityMode to fall back to 'account' for invalid persisted values instead of failing with ConnectSecurityModeLoadError. This prevents the UI toggle from being permanently disabled when the secret store contains corrupt data, and also prevents mint replay guard consumption from being wasted when getSecurityMode fails after guards are consumed. - Add synchronous useRef guard in handleConnectClientAction to prevent concurrent approve/reject/revoke calls that can slip through the asynchronous React state check before re-render disables buttons. --- apps/server/src/auth/ConnectClientStore.ts | 19 +++++-------------- .../settings/ConnectionsSettings.tsx | 9 ++++++--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/apps/server/src/auth/ConnectClientStore.ts b/apps/server/src/auth/ConnectClientStore.ts index 9c9debe823..952fbebb7a 100644 --- a/apps/server/src/auth/ConnectClientStore.ts +++ b/apps/server/src/auth/ConnectClientStore.ts @@ -222,18 +222,9 @@ function fromPresentationMetadata( }; } -function decodeSecurityMode( - bytes: Uint8Array, -): Effect.Effect { +function decodeSecurityMode(bytes: Uint8Array): AuthConnectSecurityMode { const value = textDecoder.decode(bytes).trim(); - if (value === "account" || value === "client-approval") { - return Effect.succeed(value); - } - return Effect.fail( - new ConnectSecurityModeLoadError({ - cause: new Error(`Invalid Connect security mode: ${value}`), - }), - ); + return value === "account" || value === "client-approval" ? value : "account"; } function encodeSecurityMode(mode: AuthConnectSecurityMode): Uint8Array { @@ -265,10 +256,10 @@ export const make = Effect.gen(function* () { const getSecurityMode: ConnectClientStore["Service"]["getSecurityMode"] = () => secrets.get(CONNECT_SECURITY_MODE_SECRET).pipe( - Effect.mapError((cause) => new ConnectSecurityModeLoadError({ cause })), - Effect.flatMap((mode) => - Option.isSome(mode) ? decodeSecurityMode(mode.value) : Effect.succeed("account" as const), + Effect.map((mode) => + Option.isSome(mode) ? decodeSecurityMode(mode.value) : ("account" as const), ), + Effect.mapError((cause) => new ConnectSecurityModeLoadError({ cause })), Effect.withSpan("ConnectClientStore.getSecurityMode"), ); diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index c8983361b7..5b2c8c8307 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -8,7 +8,7 @@ import { TriangleAlertIcon, } from "lucide-react"; import { useAuth } from "@clerk/react"; -import { type ReactNode, memo, useCallback, useEffect, useMemo, useState } from "react"; +import { type ReactNode, memo, useCallback, useEffect, useMemo, useRef, useState } from "react"; import { AuthAccessReadScope, AuthAccessWriteScope, @@ -2224,6 +2224,7 @@ export function ConnectionsSettings() { const [pendingConnectClientActionKey, setPendingConnectClientActionKey] = useState( null, ); + const pendingConnectClientActionRef = useRef(false); const [addBackendDialogOpen, setAddBackendDialogOpen] = useState(false); const [savedBackendMode, setSavedBackendMode] = useState<"remote" | "ssh">("remote"); const [savedBackendHost, setSavedBackendHost] = useState(""); @@ -2549,7 +2550,8 @@ export function ConnectionsSettings() { const handleConnectClientAction = useCallback( async (action: "approve" | "reject" | "revoke", clientProofKeyThumbprint: string) => { - if (pendingConnectClientActionKey !== null) return; + if (pendingConnectClientActionRef.current) return; + pendingConnectClientActionRef.current = true; const actionKey = `${action}:${clientProofKeyThumbprint}`; setPendingConnectClientActionKey(actionKey); setDesktopAccessManagementMutationError(null); @@ -2573,10 +2575,11 @@ export function ConnectionsSettings() { }), ); } finally { + pendingConnectClientActionRef.current = false; setPendingConnectClientActionKey(null); } }, - [pendingConnectClientActionKey], + [], ); const handleAddSavedBackend = useCallback(async () => {