Skip to content

Commit 0beb6e6

Browse files
cliffhallclaude
andcommitted
web: address #1670 review — observable deep-link failures + correct stale-config connect
- The ensure-phase addServer catch now records non-409 failures (read-only catalog, backend 5xx) on data-error-message instead of swallowing every error and leaving the deep link permanently stuck at the guard with no signal (review finding #1). - Split the update and connect phases across renders (new deepLinkUpdateRef): connect only once servers reflects the updated config, so onToggleConnection (which reads serversRef, synced by an earlier passive effect) builds the client from the fresh transport rather than the pre-update config (finding #2 — the exact case deepLinkConfigEquals was added for). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01BrihGWcrM9JGRyu41nzZYw
1 parent 0e93b13 commit 0beb6e6

1 file changed

Lines changed: 45 additions & 30 deletions

File tree

‎clients/web/src/App.tsx‎

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ function App() {
13811381
return [parsed, deepLinkParseStatus(search, parsed)];
13821382
}, []);
13831383
const deepLinkEnsureRef = useRef(false);
1384+
const deepLinkUpdateRef = useRef(false);
13841385
const deepLinkConnectRef = useRef(false);
13851386

13861387
const showReAuthBanner = useCallback(
@@ -2518,15 +2519,20 @@ function App() {
25182519
}, [inspectorClient, finalizeExplicitDisconnect]);
25192520

25202521
// Deep-link auto-connect (the URL-driven case of #1183). `useServers`
2521-
// hydrates asynchronously (initial `servers` is `[]`), so this effect runs
2522-
// in two phases: first render attempts a one-shot `addServer` (a 409 means
2523-
// the row already exists on disk and hydration will surface it); a later
2524-
// render where `servers` actually contains the deep-link row then updates the
2525-
// URL if it has changed and connects. Connecting in the same closure as
2526-
// `addServer` would resolve against a stale (empty) `servers` and silently
2527-
// no-op. The OAuth callback path takes precedence; a deep link on
2528-
// `/oauth/callback` would be a misconfiguration, and the callback handler
2529-
// clears the URL.
2522+
// hydrates asynchronously (initial `servers` is `[]`), so this effect runs in
2523+
// discrete phases keyed on what `servers` currently reflects, one per render:
2524+
// 1. ensure — no row yet: one-shot `addServer`.
2525+
// 2. update — row present but its persisted config differs from the deep
2526+
// link (a stale transport/url from an earlier load under the stable
2527+
// `deep-link` id): `updateServer`, then return so the effect re-runs.
2528+
// 3. connect — row present AND its config already matches: connect.
2529+
// Splitting update and connect across renders (rather than awaiting both in
2530+
// one closure) is what makes the connect correct: `onToggleConnection` reads
2531+
// the target from `serversRef`, which an earlier passive effect syncs from
2532+
// `servers` — so connecting only once `servers` reflects the updated config
2533+
// guarantees the client is built from the fresh transport, not the stale one.
2534+
// The OAuth callback path takes precedence; a deep link on `/oauth/callback`
2535+
// would be a misconfiguration, and the callback handler clears the URL.
25302536
useEffect(() => {
25312537
if (!deepLink) return;
25322538
if (window.location.pathname === OAUTH_CALLBACK_PATH) return;
@@ -2535,33 +2541,42 @@ function App() {
25352541
if (!existing) {
25362542
if (deepLinkEnsureRef.current) return;
25372543
deepLinkEnsureRef.current = true;
2538-
void addServer(deepLink.serverId, deepLink.serverConfig).catch(() => {
2539-
// 409 = already on disk; hydration will surface it on a later render.
2544+
void addServer(deepLink.serverId, deepLink.serverConfig).catch((err) => {
2545+
const message = err instanceof Error ? err.message : String(err);
2546+
// A 409 ("already exists") means the row is on disk and hydration will
2547+
// surface it on a later render, so the connect phase still proceeds —
2548+
// swallow it. Any other failure (read-only catalog, backend 5xx) would
2549+
// otherwise leave the deep link permanently stuck at this guard with no
2550+
// signal, so record it on the machine-readable error surface.
2551+
if (!message.includes("already exists")) recordConnectError(message);
2552+
});
2553+
return;
2554+
}
2555+
2556+
if (!deepLinkConfigEquals(existing.config, deepLink.serverConfig)) {
2557+
if (deepLinkUpdateRef.current) return;
2558+
deepLinkUpdateRef.current = true;
2559+
void updateServer(
2560+
deepLink.serverId,
2561+
deepLink.serverId,
2562+
deepLink.serverConfig,
2563+
).catch((err) => {
2564+
const message = err instanceof Error ? err.message : String(err);
2565+
recordConnectError(message);
25402566
});
25412567
return;
25422568
}
25432569

25442570
if (deepLinkConnectRef.current) return;
25452571
deepLinkConnectRef.current = true;
2546-
void (async () => {
2547-
if (!deepLinkConfigEquals(existing.config, deepLink.serverConfig)) {
2548-
await updateServer(
2549-
deepLink.serverId,
2550-
deepLink.serverId,
2551-
deepLink.serverConfig,
2552-
);
2553-
}
2554-
if (activeServerId !== deepLink.serverId) {
2555-
await onToggleConnection(deepLink.serverId);
2556-
}
2557-
})().catch((err) => {
2558-
// Surface deep-link automation failures (updateServer 5xx, connect throw)
2559-
// on the machine-readable error attribute instead of dropping them. The
2560-
// toast still fires from inside `onToggleConnection` for the common
2561-
// cases; this catch covers the rest.
2562-
const message = err instanceof Error ? err.message : String(err);
2563-
recordConnectError(message);
2564-
});
2572+
if (activeServerId !== deepLink.serverId) {
2573+
void onToggleConnection(deepLink.serverId).catch((err) => {
2574+
// The toast fires from inside `onToggleConnection` for the common
2575+
// cases; this catch covers the rest (surfaced on `data-error-message`).
2576+
const message = err instanceof Error ? err.message : String(err);
2577+
recordConnectError(message);
2578+
});
2579+
}
25652580
}, [
25662581
deepLink,
25672582
servers,

0 commit comments

Comments
 (0)