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: try to reconnect if copilot connection fails (#7204)
Myles Scolnickeadb95386012
diff --git a/frontend/src/core/codemirror/copilot/client.ts b/frontend/src/core/codemirror/copilot/client.tsindex 050c27fb26..62c48a1303 100644--- a/frontend/src/core/codemirror/copilot/client.ts+++ b/frontend/src/core/codemirror/copilot/client.ts@@ -89,9 +89,29 @@ class LazyWebsocketTransport extends Transport {data: JSONRPCRequestData,timeout: number | null | undefined,) {+ // If delegate is undefined, try to reconnect+ if (!this.delegate) {+ Logger.log("Copilot#sendData: Delegate not initialized, reconnecting...");+ try {+ await this.tryConnect();+ } catch (error) {+ Logger.error("Copilot#sendData: Failed to reconnect transport", error);+ throw new Error(+ "Unable to connect to GitHub Copilot. Please check your settings and try again.",+ );+ }+ }++ // After reconnection, delegate should be initialized+ if (!this.delegate) {+ throw new Error(+ "Failed to initialize GitHub Copilot connection. Please try again.",+ );+ }+// Clamp timeout to 5 secondstimeout = Math.min(timeout ?? 5000, 5000);- return this.delegate?.sendData(data, timeout);+ return this.delegate.sendData(data, timeout);}}diff --git a/frontend/src/core/codemirror/copilot/copilot-config.tsx b/frontend/src/core/codemirror/copilot/copilot-config.tsxindex 9191ce0715..c0a8bf1fbb 100644--- a/frontend/src/core/codemirror/copilot/copilot-config.tsx+++ b/frontend/src/core/codemirror/copilot/copilot-config.tsx@@ -24,13 +24,41 @@ export const CopilotConfig = memo(() => {evt.preventDefault();setLoading(true);try {- const { verificationUri, status, userCode } = await initiateSignIn();+ const result = await initiateSignIn();++ // Validate the response has required fields+ if (!result || !result.verificationUri || !result.userCode) {+ Logger.error("Copilot#trySignIn: Invalid response from sign-in", {+ result,+ });+ setStep("connectionError");+ toast({+ title: "GitHub Copilot Connection Error",+ description:+ "Unable to connect to GitHub Copilot. Please check your settings and try again.",+ variant: "danger",+ });+ return;+ }++ const { verificationUri, status, userCode } = result;if (isSignedIn(status)) {copilotChangeSignIn(true);} else {setStep("signingIn");setLocalData({ url: verificationUri, code: userCode });}+ } catch (error) {+ Logger.error("Copilot#trySignIn: Error during sign-in", error);+ setStep("connectionError");+ toast({+ title: "GitHub Copilot Connection Error",+ description:+ error instanceof Error+ ? error.message+ : "Unable to connect to GitHub Copilot. Please check your settings and try again.",+ variant: "danger",+ });} finally {setLoading(false);}