* Fix desktop black screen fallback * Add desktop black screen changeset
Showing the changes to apps (3 of 6 files). Show all
Unified · Split
| @@ -35,6 +35,7 @@ import { · 34 unmodified lines | |||
| 35 | reportAProblem, | 35 | reportAProblem, |
| 36 | } from "./diagnostics"; | 36 | } from "./diagnostics"; |
| 37 | import { sidecarCrashHtml } from "./crash-screen"; | 37 | import { sidecarCrashHtml } from "./crash-screen"; |
| 38 | import { replaceSupervisedDaemonForDesktop } from "./supervised-connection"; | ||
| 38 | import { | 39 | import { |
| 39 | bundledExecutorPath, | 40 | bundledExecutorPath, |
| 40 | installSupervisedService, | 41 | installSupervisedService, |
| @@ -88,6 +89,11 @@ const liveMainWindow = (): BrowserWindow | null => { · 47 unmodified lines | |||
| 88 | return window; | 89 | return window; |
| 89 | }; | 90 | }; |
| 90 | 91 | ||
| 92 | const destroyWindow = (window: BrowserWindow) => { | ||
| 93 | if (mainWindow === window) mainWindow = null; | ||
| 94 | if (!window.isDestroyed()) window.destroy(); | ||
| 95 | }; | ||
| 96 | |||
| 91 | const focusMainWindow = () => { | 97 | const focusMainWindow = () => { |
| 92 | const window = liveMainWindow(); | 98 | const window = liveMainWindow(); |
| 93 | if (!window) { | 99 | if (!window) { |
| @@ -208,17 +214,21 @@ const ensureSupervisedConnection = async (): Promise<SidecarConnection | null> = · 114 unmodified lines | |||
| 208 | if (attached) { | 214 | if (attached) { |
| 209 | if (!shouldReplaceDaemonForDesktop(attached)) return attached; | 215 | if (!shouldReplaceDaemonForDesktop(attached)) return attached; |
| 210 | const settings = getServerSettings(); | 216 | const settings = getServerSettings(); |
| 211 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: desktop launch should attach to the running daemon if automatic upgrade fails | 217 | return replaceSupervisedDaemonForDesktop(attached, { |
| 212 | try { | 218 | install: () => |
| 213 | await installSupervisedService({ | 219 | installSupervisedService({ |
| 214 | port: settings.port, | 220 | port: settings.port, |
| 215 | dataDir: DESKTOP_DATA_DIR, | 221 | dataDir: DESKTOP_DATA_DIR, |
| 216 | }); | 222 | }), |
| 217 | return (await waitForSupervisedAttach(30_000, { port: settings.port })) ?? attached; | 223 | waitForAttach: () => waitForSupervisedAttach(30_000, { port: settings.port }), |
| 218 | } catch (error) { | 224 | attach: attachToSupervisedDaemon, |
| 219 | log.warn("Failed to replace older supervised daemon; attaching to the running daemon", error); | 225 | onInstallFailure: (error) => { |
| 220 | return attached; | 226 | log.warn( |
| 221 | } | 227 | "Failed to replace older supervised daemon; re-checking before falling back", |
| 228 | error, | ||
| 229 | ); | ||
| 230 | }, | ||
| 231 | }); | ||
| 222 | } | 232 | } |
| 223 | 233 | ||
| 224 | const status = await supervisedServiceStatus(); | 234 | const status = await supervisedServiceStatus(); |
| @@ -452,7 +462,18 @@ const createWindow = async (conn: SidecarConnection) => { · 227 unmodified lines | |||
| 452 | return { action: "deny" }; | 462 | return { action: "deny" }; |
| 453 | }); | 463 | }); |
| 454 | 464 | ||
| 455 | await window.loadURL(webUrlForConnection(conn)); | 465 | // A supervised daemon can pass the health probe and still disappear before |
| 466 | // navigation begins. Treat that as a failed connection instead of leaving the | ||
| 467 | // user with a visible BrowserWindow that only shows the black background. | ||
| 468 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: Electron navigation rejects when the sidecar vanishes during startup | ||
| 469 | try { | ||
| 470 | await window.loadURL(webUrlForConnection(conn)); | ||
| 471 | } catch (error) { | ||
| 472 | log.error("Failed to load Executor web UI", error); | ||
| 473 | destroyWindow(window); | ||
| 474 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: caller decides whether to fall back or surface startup failure | ||
| 475 | throw error; | ||
| 476 | } | ||
| 456 | }; | 477 | }; |
| 457 | 478 | ||
| 458 | const showPortInUseDialog = async (port: number) => { | 479 | const showPortInUseDialog = async (port: number) => { |
| @@ -852,10 +873,18 @@ const boot = async () => { · 393 unmodified lines | |||
| 852 | const supervised = await ensureSupervisedConnection(); | 873 | const supervised = await ensureSupervisedConnection(); |
| 853 | if (supervised) { | 874 | if (supervised) { |
| 854 | connection = supervised; | 875 | connection = supervised; |
| 855 | await createWindow(supervised); // installs the bearer-auth header itself | 876 | // createWindow installs the bearer-auth header itself. |
| 856 | armSupervisedMonitor(); | 877 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: supervised attach can race with daemon shutdown; fall back to managed spawn |
| 857 | void runUpdateCheck({ alertOnFail: false }); | 878 | try { |
| 858 | return; | 879 | await createWindow(supervised); |
| 880 | armSupervisedMonitor(); | ||
| 881 | void runUpdateCheck({ alertOnFail: false }); | ||
| 882 | return; | ||
| 883 | } catch (error) { | ||
| 884 | log.warn("Failed to load supervised daemon; falling back to managed sidecar", error); | ||
| 885 | stopSupervisedMonitor(); | ||
| 886 | connection = null; | ||
| 887 | } | ||
| 859 | } | 888 | } |
| 860 | } | 889 | } |
| 861 | connection = await startWithCurrentSettings(); | 890 | connection = await startWithCurrentSettings(); |
| @@ -878,7 +907,44 @@ const boot = async () => { · 16 unmodified lines | |||
| 878 | app.quit(); | 907 | app.quit(); |
| 879 | return; | 908 | return; |
| 880 | } | 909 | } |
| 881 | await createWindow(connection); | 910 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: renderer navigation failure must show the startup recovery dialog, not a black window |
| 911 | try { | ||
| 912 | await createWindow(connection); | ||
| 913 | } catch (error) { | ||
| 914 | log.error("Failed to load managed sidecar web UI", error); | ||
| 915 | const failedConnection = connection; | ||
| 916 | connection = null; | ||
| 917 | await stopConnection(failedConnection); | ||
| 918 | |||
| 919 | const retryAfterReset = await handleFatalSidecarFailure(error); | ||
| 920 | if (!retryAfterReset) { | ||
| 921 | app.quit(); | ||
| 922 | return; | ||
| 923 | } | ||
| 924 | |||
| 925 | lastSidecarStartError = null; | ||
| 926 | connection = await startWithCurrentSettings(); | ||
| 927 | if (!connection && lastSidecarStartError != null) { | ||
| 928 | await handleFatalSidecarFailure(lastSidecarStartError); | ||
| 929 | } | ||
| 930 | if (!connection) { | ||
| 931 | app.quit(); | ||
| 932 | return; | ||
| 933 | } | ||
| 934 | |||
| 935 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: one post-reset retry before giving the user the final startup failure | ||
| 936 | try { | ||
| 937 | await createWindow(connection); | ||
| 938 | } catch (retryError) { | ||
| 939 | log.error("Failed to load managed sidecar web UI after reset", retryError); | ||
| 940 | const failedRetryConnection = connection; | ||
| 941 | connection = null; | ||
| 942 | await stopConnection(failedRetryConnection); | ||
| 943 | await handleFatalSidecarFailure(retryError); | ||
| 944 | app.quit(); | ||
| 945 | return; | ||
| 946 | } | ||
| 947 | } | ||
| 882 | // Check at boot. If an update is available, autoDownload pulls it and | 948 | // Check at boot. If an update is available, autoDownload pulls it and |
| 883 | // the 'update-downloaded' handler fires the install dialog. Silent on | 949 | // the 'update-downloaded' handler fires the install dialog. Silent on |
| 884 | // no-update / failure so we don't bother users on every launch. | 950 | // no-update / failure so we don't bother users on every launch. |
| @@ -0,0 +1,79 @@ | |||
| 1 | import { describe, expect, it } from "@effect/vitest"; | ||
| 2 | import { Effect } from "effect"; | ||
| 3 | import type { SidecarConnection } from "./sidecar"; | ||
| 4 | import { replaceSupervisedDaemonForDesktop } from "./supervised-connection"; | ||
| 5 | |||
| 6 | const connection = (baseUrl: string): SidecarConnection => ({ | ||
| 7 | baseUrl, | ||
| 8 | hostname: "localhost", | ||
| 9 | port: 4789, | ||
| 10 | username: "executor", | ||
| 11 | authToken: "token", | ||
| 12 | child: null, | ||
| 13 | supervisedDaemon: true, | ||
| 14 | ownerVersion: "1.5.12", | ||
| 15 | ownerClient: "cli", | ||
| 16 | ownerExecutablePath: "/tmp/old-executor", | ||
| 17 | }); | ||
| 18 | |||
| 19 | const rejectedInstall = (error: unknown): Promise<void> => Effect.runPromise(Effect.fail(error)); | ||
| 20 | |||
| 21 | describe("replaceSupervisedDaemonForDesktop", () => { | ||
| 22 | it("uses the replacement daemon after install succeeds", async () => { | ||
| 23 | const stale = connection("http://localhost:4789"); | ||
| 24 | const fresh = connection("http://localhost:55334"); | ||
| 25 | let installCalls = 0; | ||
| 26 | let waitCalls = 0; | ||
| 27 | let attachCalls = 0; | ||
| 28 | |||
| 29 | const result = await replaceSupervisedDaemonForDesktop(stale, { | ||
| 30 | install: async () => { | ||
| 31 | installCalls += 1; | ||
| 32 | }, | ||
| 33 | waitForAttach: async () => { | ||
| 34 | waitCalls += 1; | ||
| 35 | return fresh; | ||
| 36 | }, | ||
| 37 | attach: async () => { | ||
| 38 | attachCalls += 1; | ||
| 39 | return stale; | ||
| 40 | }, | ||
| 41 | }); | ||
| 42 | |||
| 43 | expect(result).toBe(fresh); | ||
| 44 | expect(installCalls).toBe(1); | ||
| 45 | expect(waitCalls).toBe(1); | ||
| 46 | expect(attachCalls).toBe(0); | ||
| 47 | }); | ||
| 48 | |||
| 49 | it("re-probes after install fails instead of returning the stale daemon", async () => { | ||
| 50 | const stale = connection("http://localhost:4789"); | ||
| 51 | const installFailure = { _tag: "InstallFailure" }; | ||
| 52 | let loggedError: unknown; | ||
| 53 | let loggedConnection: SidecarConnection | null = null; | ||
| 54 | let waitCalls = 0; | ||
| 55 | let attachCalls = 0; | ||
| 56 | |||
| 57 | const result = await replaceSupervisedDaemonForDesktop(stale, { | ||
| 58 | install: () => rejectedInstall(installFailure), | ||
| 59 | waitForAttach: async () => { | ||
| 60 | waitCalls += 1; | ||
| 61 | return stale; | ||
| 62 | }, | ||
| 63 | attach: async () => { | ||
| 64 | attachCalls += 1; | ||
| 65 | return null; | ||
| 66 | }, | ||
| 67 | onInstallFailure: (error, connection) => { | ||
| 68 | loggedError = error; | ||
| 69 | loggedConnection = connection; | ||
| 70 | }, | ||
| 71 | }); | ||
| 72 | |||
| 73 | expect(result).toBeNull(); | ||
| 74 | expect(waitCalls).toBe(0); | ||
| 75 | expect(attachCalls).toBe(1); | ||
| 76 | expect(loggedError).toBe(installFailure); | ||
| 77 | expect(loggedConnection).toBe(stale); | ||
| 78 | }); | ||
| 79 | }); | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | /* oxlint-disable executor/no-try-catch-or-throw -- boundary: Electron startup must convert service-install failures into a fresh daemon probe */ | ||
| 2 | import type { SidecarConnection } from "./sidecar"; | ||
| 3 | |||
| 4 | export interface ReplaceSupervisedDaemonInput { | ||
| 5 | readonly install: () => Promise<void>; | ||
| 6 | readonly waitForAttach: () => Promise<SidecarConnection | null>; | ||
| 7 | readonly attach: () => Promise<SidecarConnection | null>; | ||
| 8 | readonly onInstallFailure?: (error: unknown, staleConnection: SidecarConnection) => void; | ||
| 9 | } | ||
| 10 | |||
| 11 | export const replaceSupervisedDaemonForDesktop = async ( | ||
| 12 | staleConnection: SidecarConnection, | ||
| 13 | input: ReplaceSupervisedDaemonInput, | ||
| 14 | ): Promise<SidecarConnection | null> => { | ||
| 15 | try { | ||
| 16 | await input.install(); | ||
| 17 | return (await input.waitForAttach()) ?? (await input.attach()); | ||
| 18 | } catch (error) { | ||
| 19 | input.onInstallFailure?.(error, staleConnection); | ||
| 20 | return await input.attach(); | ||
| 21 | } | ||
| 22 | }; | ||