diff --git a/apps/app/src/react-app/shell/session-route.tsx b/apps/app/src/react-app/shell/session-route.tsx index 93228c95..b660479c 100644 --- a/apps/app/src/react-app/shell/session-route.tsx +++ b/apps/app/src/react-app/shell/session-route.tsx @@ -118,14 +118,14 @@ async function resolveRouteOpenworkConnection() { try { const info = await openworkServerInfo(); hostInfo = info; - if (!normalizedBaseUrl) { - normalizedBaseUrl = - normalizeOpenworkServerUrl(info.connectUrl ?? info.baseUrl ?? info.lanUrl ?? info.mdnsUrl ?? "") ?? - normalizedBaseUrl; - } - if (!resolvedToken) { - resolvedToken = info.ownerToken?.trim() || info.clientToken?.trim() || resolvedToken; - } + // Desktop-hosted servers use a fresh loopback port and freshly minted + // owner token per boot. Prefer the live runtime info over localStorage; + // the stored URL/token can point at the previous process and produce + // ERR_CONNECTION_REFUSED or 401 before the boot event refreshes settings. + normalizedBaseUrl = + normalizeOpenworkServerUrl(info.connectUrl ?? info.baseUrl ?? info.lanUrl ?? info.mdnsUrl ?? "") ?? + normalizedBaseUrl; + resolvedToken = info.ownerToken?.trim() || info.clientToken?.trim() || resolvedToken; } catch { // ignore and fall back to stored settings only } diff --git a/apps/app/src/react-app/shell/settings-route.tsx b/apps/app/src/react-app/shell/settings-route.tsx index 1637f6d7..115fa5b9 100644 --- a/apps/app/src/react-app/shell/settings-route.tsx +++ b/apps/app/src/react-app/shell/settings-route.tsx @@ -178,9 +178,12 @@ async function resolveRouteOpenworkConnection() { let normalizedBaseUrl = normalizeOpenworkServerUrl(settings.urlOverride ?? "") ?? ""; let resolvedToken = settings.token?.trim() ?? ""; - if ((!normalizedBaseUrl || !resolvedToken) && isDesktopRuntime()) { + if (isDesktopRuntime()) { try { const info = await openworkServerInfo(); + // Desktop-hosted servers use a fresh loopback port and freshly minted + // owner token per boot. Prefer the live runtime info over localStorage; + // stored settings may belong to a previous server process. normalizedBaseUrl = normalizeOpenworkServerUrl(info.connectUrl ?? info.baseUrl ?? info.lanUrl ?? info.mdnsUrl ?? "") ?? normalizedBaseUrl;