A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: Display failed connection information + more graceful backoff. (#5584)
Dylan Madisettib89aebf1fb26
diff --git a/frontend/src/components/editor/alerts/connecting-alert.tsx b/frontend/src/components/editor/alerts/connecting-alert.tsxindex 7c0dc906a8..1aa7f71ff1 100644--- a/frontend/src/components/editor/alerts/connecting-alert.tsx+++ b/frontend/src/components/editor/alerts/connecting-alert.tsx@@ -4,7 +4,7 @@ import { useAtomValue } from "jotai";import { LoadingEllipsis } from "@/components/icons/loading-ellipsis";import { Spinner } from "@/components/icons/spinner";import { DelayMount } from "@/components/utils/delay-mount";-import { isConnectingAtom } from "@/core/network/connection";+import { isClosedAtom, isConnectingAtom } from "@/core/network/connection";import { Tooltip } from "../../ui/tooltip";import { FloatingAlert } from "./floating-alert";@@ -13,9 +13,10 @@ const LONG_DELAY_MS = 5000; // 5 secondsexport const ConnectingAlert: React.FC = () => {const isConnecting = useAtomValue(isConnectingAtom);+ const isClosed = useAtomValue(isClosedAtom);return (- isConnecting && (+ (isConnecting && (<><DelayMount milliseconds={SHORT_DELAY_MS}><div className="absolute top-4 m-0 flex items-center min-h-[28px] left-1/2 transform -translate-x-1/2 z-[200] ">@@ -33,6 +34,13 @@ export const ConnectingAlert: React.FC = () => {</div></FloatingAlert></>- )+ )) ||+ (isClosed && (+ <FloatingAlert show={isClosed} kind="danger">+ <div className="flex items-center gap-2">+ <p>Failed to connect.</p>+ </div>+ </FloatingAlert>+ )));};diff --git a/frontend/src/core/network/connection.ts b/frontend/src/core/network/connection.tsindex 67f58b5b24..82bc648186 100644--- a/frontend/src/core/network/connection.ts+++ b/frontend/src/core/network/connection.ts@@ -26,3 +26,8 @@ export const isConnectedAtom = atom((get) => {const connection = get(connectionAtom);return connection.state === WebSocketState.OPEN;});++export const isClosedAtom = atom((get) => {+ const connection = get(connectionAtom);+ return connection.state === WebSocketState.CLOSED;+});diff --git a/frontend/src/core/runtime/__tests__/runtime.test.ts b/frontend/src/core/runtime/__tests__/runtime.test.tsindex 897ff3541a..7ea7a4a15a 100644--- a/frontend/src/core/runtime/__tests__/runtime.test.ts+++ b/frontend/src/core/runtime/__tests__/runtime.test.ts@@ -229,7 +229,7 @@ describe("RuntimeManager", () => {runtime.init({ disableRetryDelay: true });await expect(runtime.waitForHealthy()).rejects.toThrow(- "Failed to connect after 6 retries",+ "Failed to connect after 25 retries",);});});diff --git a/frontend/src/core/runtime/runtime.ts b/frontend/src/core/runtime/runtime.tsindex 4e9063e54a..809b7a0fae 100644--- a/frontend/src/core/runtime/runtime.ts+++ b/frontend/src/core/runtime/runtime.ts@@ -177,8 +177,11 @@ export class RuntimeManager {async init(options?: { disableRetryDelay?: boolean }) {let retries = 0;- const maxRetries = 6;- const baseDelay = 1000;+ // This matches backoff logic elsewhere.+ const maxRetries = 25;+ const baseDelay = 100; // 0.1 second+ const growthFactor = 1.2;+ const maxDelay = 2000;while (!(await this.isHealthy())) {if (retries >= maxRetries) {@@ -189,7 +192,7 @@ export class RuntimeManager {return;}if (!options?.disableRetryDelay) {- const delay = baseDelay * 2 ** retries;+ const delay = Math.min(baseDelay * growthFactor ** retries, maxDelay);await new Promise((resolve) => setTimeout(resolve, delay));}retries++;diff --git a/frontend/src/core/websocket/useWebSocket.tsx b/frontend/src/core/websocket/useWebSocket.tsxindex 759c844826..2f3fa1b802 100644--- a/frontend/src/core/websocket/useWebSocket.tsx+++ b/frontend/src/core/websocket/useWebSocket.tsx@@ -58,9 +58,14 @@ export function useWebSocket(options: UseWebSocketOptions) {if (ws.readyState === WebSocket.CLOSED) {// Ignore waitToConnect for static and wasm notebooksif (waitToConnect && !isStaticNotebook() && !isWasm()) {- waitToConnect().then(() => {- ws.reconnect();- });+ waitToConnect()+ .then(() => {+ ws.reconnect();+ })+ .catch((error) => {+ Logger.error("Healthy connection never made", error);+ ws.close();+ });} else {ws.reconnect();}