You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by ja...@apache.org on 2026/08/22 13:57:25 UTC

(maka) branch main updated: fix(desktop): recover from main Renderer loss (#3495)

This is an automated email from the ASF dual-hosted git repository.

jackwener pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/maka.git


The following commit(s) were added to refs/heads/main by this push:
     new 9a661a183 fix(desktop): recover from main Renderer loss (#3495)
9a661a183 is described below

commit 9a661a183756cee2a5e779d84bdaf6cb8b8a45d9
Author: Wang <m4...@gmail.com>
AuthorDate: Sat Aug 22 21:57:19 2026 +0800

    fix(desktop): recover from main Renderer loss (#3495)
    
    * fix(desktop): recover from main renderer loss
    
    Observe unexpected termination of the main BrowserWindow renderer while the Electron main process is still alive. Reuse the native diagnostic dialog and existing report formatter so users can copy bounded Desktop evidence before choosing to relaunch or exit, without querying an unrelated Runtime Host.
    
    Generated-by: Codex
    
    * fix(desktop): preserve renderer recovery during initial load
    
    Route every window creation through the quit coordinator so rejected initial loads are reported instead of escaping as unhandled rejections. Test the real render-process-gone observation boundary while preserving the existing native recovery decision flow.
    
    Generated-by: Codex
    
    * refactor(desktop): centralize renderer recovery diagnostics
    
    Route Renderer-loss copying through the existing Desktop diagnostic authority so collection, Host attribution, redaction, and clipboard behavior keep one owner. Align the shutdown regression test with the production register-then-abort lifecycle.
    
    Generated-by: Codex
---
 .../main/__tests__/app-quit-coordinator.test.ts    | 34 +++++++--
 .../__tests__/main-renderer-process-gone.test.ts   | 42 +++++++++++
 .../__tests__/native-diagnostic-dialog.test.ts     | 87 ++++++++++++++++++----
 apps/desktop/src/main/app-quit-coordinator.ts      | 15 ++--
 apps/desktop/src/main/main-process-diagnostics.ts  | 39 +++++++++-
 .../desktop/src/main/main-renderer-process-gone.ts | 19 +++++
 apps/desktop/src/main/main-window.ts               | 17 +++++
 apps/desktop/src/main/native-diagnostic-dialog.ts  | 70 +++++++++++++----
 apps/desktop/src/main/runtime-host-boot.ts         | 28 ++++++-
 9 files changed, 305 insertions(+), 46 deletions(-)

diff --git a/apps/desktop/src/main/__tests__/app-quit-coordinator.test.ts b/apps/desktop/src/main/__tests__/app-quit-coordinator.test.ts
index 838a8a9b2..a5b249259 100644
--- a/apps/desktop/src/main/__tests__/app-quit-coordinator.test.ts
+++ b/apps/desktop/src/main/__tests__/app-quit-coordinator.test.ts
@@ -29,6 +29,7 @@ describe('app quit coordinator', () => {
       cleanup: async () => {},
       focusOrCreateWindow: () => {},
       onCleanupError: () => {},
+      onWindowCreationError: () => {},
       resumeQuit: () => {
         resumeQuitCount += 1;
       },
@@ -69,6 +70,7 @@ describe('app quit coordinator', () => {
         focusOrCreateCount += 1;
       },
       onCleanupError: () => {},
+      onWindowCreationError: () => {},
       resumeQuit: () => {
         resumeQuitCount += 1;
       },
@@ -104,22 +106,44 @@ describe('app quit coordinator', () => {
 
   it('does not reopen the main window after quit cleanup starts', () => {
     let focusOrCreateCount = 0;
+    let windowCreationSignal: AbortSignal | undefined;
     const coordinator = createAppQuitCoordinator({
       cleanup: () => new Promise<void>(() => {}),
-      focusOrCreateWindow: () => {
+      focusOrCreateWindow: (signal) => {
         focusOrCreateCount += 1;
+        windowCreationSignal = signal;
       },
       onCleanupError: () => {},
+      onWindowCreationError: () => {},
       resumeQuit: () => {},
     });
-    const windowCreationSignal = coordinator.getWindowCreationSignal();
 
+    coordinator.focusOrCreateWindow();
     coordinator.handleBeforeQuit({ preventDefault: () => {} });
     coordinator.focusOrCreateWindow();
 
-    assert.equal(focusOrCreateCount, 0);
+    assert.equal(focusOrCreateCount, 1);
     assert.equal(windowCreationSignal?.aborted, true);
-    assert.equal(coordinator.getWindowCreationSignal(), undefined);
+  });
+
+  it('reports window creation failure without leaking an unhandled rejection', async () => {
+    const failure = new Error('window load failed');
+    const reportedErrors: unknown[] = [];
+    const coordinator = createAppQuitCoordinator({
+      cleanup: async () => {},
+      focusOrCreateWindow: async () => {
+        throw failure;
+      },
+      onCleanupError: () => {},
+      onWindowCreationError: (error) => reportedErrors.push(error),
+      resumeQuit: () => {},
+    });
+
+    coordinator.focusOrCreateWindow();
+    await Promise.resolve();
+    await Promise.resolve();
+
+    assert.deepEqual(reportedErrors, [failure]);
   });
 
   it('reports cleanup failure without leaking an unhandled rejection', async () => {
@@ -137,6 +161,7 @@ describe('app quit coordinator', () => {
       onCleanupError: (error: unknown) => {
         reportedErrors.push(error);
       },
+      onWindowCreationError: () => {},
       resumeQuit: () => {
         resumeQuitCount += 1;
       },
@@ -158,6 +183,5 @@ describe('app quit coordinator', () => {
     assert.equal(focusOrCreateCount, 0);
     assert.equal(resumeQuitCount, 1);
     assert.equal(secondQuitPrevented, false);
-    assert.equal(coordinator.getWindowCreationSignal(), undefined);
   });
 });
diff --git a/apps/desktop/src/main/__tests__/main-renderer-process-gone.test.ts b/apps/desktop/src/main/__tests__/main-renderer-process-gone.test.ts
new file mode 100644
index 000000000..b07e6d8b0
--- /dev/null
+++ b/apps/desktop/src/main/__tests__/main-renderer-process-gone.test.ts
@@ -0,0 +1,42 @@
+import assert from 'node:assert/strict';
+import { EventEmitter } from 'node:events';
+import { test } from 'node:test';
+import type { RenderProcessGoneDetails } from 'electron';
+import { observeMainRendererProcessGone } from '../main-renderer-process-gone.js';
+
+test('observes one unexpected main Renderer exit while the app is running', () => {
+  const source = new EventEmitter();
+  const observed: RenderProcessGoneDetails[] = [];
+  observeMainRendererProcessGone({
+    source,
+    shutdownSignal: new AbortController().signal,
+    onUnexpectedExit: (details) => observed.push(details),
+  });
+
+  source.emit('render-process-gone', {}, { reason: 'oom', exitCode: 137 });
+  source.emit('render-process-gone', {}, { reason: 'crashed', exitCode: 11 });
+
+  assert.deepEqual(observed, [{ reason: 'oom', exitCode: 137 }]);
+});
+
+test('ignores clean exits and app shutdown', () => {
+  for (const scenario of [
+    { aborted: false, details: { reason: 'clean-exit', exitCode: 0 } as const },
+    { aborted: true, details: { reason: 'killed', exitCode: 9 } as const },
+  ]) {
+    const source = new EventEmitter();
+    const abort = new AbortController();
+    let observed = false;
+    observeMainRendererProcessGone({
+      source,
+      shutdownSignal: abort.signal,
+      onUnexpectedExit: () => {
+        observed = true;
+      },
+    });
+    if (scenario.aborted) abort.abort();
+
+    source.emit('render-process-gone', {}, scenario.details);
+    assert.equal(observed, false);
+  }
+});
diff --git a/apps/desktop/src/main/__tests__/native-diagnostic-dialog.test.ts b/apps/desktop/src/main/__tests__/native-diagnostic-dialog.test.ts
index 275c46d73..f2db20c36 100644
--- a/apps/desktop/src/main/__tests__/native-diagnostic-dialog.test.ts
+++ b/apps/desktop/src/main/__tests__/native-diagnostic-dialog.test.ts
@@ -20,7 +20,31 @@
 import assert from 'node:assert/strict';
 import { test } from 'node:test';
 import type { MessageBoxOptions, MessageBoxReturnValue } from 'electron';
-import { showFatalStartupError, showMessageBoxWithDiagnostics } from '../native-diagnostic-dialog.js';
+import {
+  copyDesktopDiagnosticReport,
+  createDesktopMainRendererDiagnosticInput,
+} from '../main-process-diagnostics.js';
+import {
+  showFatalStartupError,
+  showMainRendererProcessGoneDialog,
+  showMessageBoxWithDiagnostics,
+} from '../native-diagnostic-dialog.js';
+
+const diagnosticEnvironment = () => ({
+  appVersion: '0.1.8',
+  buildMode: 'packaged' as const,
+  buildCommit: null,
+  electronVersion: '38.0.0',
+  nodeVersion: '22.0.0',
+  chromeVersion: '140.0.0',
+  platform: 'linux' as const,
+  arch: 'x64',
+  osRelease: '6.6.0',
+  locale: 'en-US',
+  workspacePath: '/home/tester/.local/share/maka/workspaces/default',
+  homePath: '/home/tester',
+  processUptimeSeconds: 3,
+});
 
 test('copies diagnostics as an auxiliary native-dialog action', async () => {
   const shown: MessageBoxOptions[] = [];
@@ -62,21 +86,7 @@ test('fatal startup errors remain copyable without a renderer or BrowserWindow',
 
   await showFatalStartupError(new Error('Authorization: Bearer very-secret-token'), {
     locale: 'en',
-    environment: () => ({
-      appVersion: '0.1.8',
-      buildMode: 'packaged',
-      buildCommit: null,
-      electronVersion: '38.0.0',
-      nodeVersion: '22.0.0',
-      chromeVersion: '140.0.0',
-      platform: 'linux',
-      arch: 'x64',
-      osRelease: '6.6.0',
-      locale: 'en-US',
-      workspacePath: '/home/tester/.local/share/maka/workspaces/default',
-      homePath: '/home/tester',
-      processUptimeSeconds: 3,
-    }),
+    environment: diagnosticEnvironment,
     mainLogs: () => ['startup failed with Authorization: Bearer very-secret-token'],
     writeClipboard: (value) => {
       clipboard = value;
@@ -94,3 +104,48 @@ test('fatal startup errors remain copyable without a renderer or BrowserWindow',
   assert.match(clipboard, /Recent main-process logs \(1\)/);
   assert.doesNotMatch(clipboard, /very-secret-token/);
 });
+
+test('main Renderer loss keeps Copy Diagnostics auxiliary to recovery', async () => {
+  const shown: MessageBoxOptions[] = [];
+  const responses = [2, 0];
+  let clipboard = '';
+  const diagnosticInput = createDesktopMainRendererDiagnosticInput({
+    title: 'Maka main Renderer process exited unexpectedly',
+    description: 'Reason: oom',
+    details: 'Exit code: 137',
+  });
+
+  const decision = await showMainRendererProcessGoneDialog({
+    locale: 'en',
+    copyDiagnostics: () =>
+      copyDesktopDiagnosticReport(
+        {
+          environment: diagnosticEnvironment,
+          mainLogs: () => ['renderer stopped with api_key=very-secret-token'],
+          resolveActiveRuntimeHost: () => {
+            throw new Error('Renderer-loss diagnostics must remain Desktop-only');
+          },
+          resolveRuntimeHost: () => {
+            throw new Error('Renderer-loss diagnostics must not resolve a task Host');
+          },
+          writeClipboard: (value) => {
+            clipboard = value;
+          },
+        },
+        diagnosticInput,
+      ),
+    showMessageBox: async (options): Promise<MessageBoxReturnValue> => {
+      shown.push(options);
+      return { response: responses.shift() ?? 1, checkboxChecked: false };
+    },
+  });
+
+  assert.equal(decision, 'relaunch');
+  assert.deepEqual(shown[0]?.buttons, ['Relaunch', 'Exit', 'Copy Diagnostics']);
+  assert.deepEqual(shown[1]?.buttons, ['Relaunch', 'Exit', 'Copy Again']);
+  assert.match(clipboard, /Surface: renderer_process_gone/);
+  assert.match(clipboard, /Reason: oom/);
+  assert.match(clipboard, /Exit code: 137/);
+  assert.match(clipboard, /Recent main-process logs \(1\)/);
+  assert.doesNotMatch(clipboard, /very-secret-token/);
+});
diff --git a/apps/desktop/src/main/app-quit-coordinator.ts b/apps/desktop/src/main/app-quit-coordinator.ts
index 734fcd778..6aef75305 100644
--- a/apps/desktop/src/main/app-quit-coordinator.ts
+++ b/apps/desktop/src/main/app-quit-coordinator.ts
@@ -23,14 +23,14 @@ export interface AppQuitEvent {
 
 export interface AppQuitCoordinator {
   focusOrCreateWindow(): void;
-  getWindowCreationSignal(): AbortSignal | undefined;
   handleBeforeQuit(event: AppQuitEvent): void;
 }
 
 export interface AppQuitCoordinatorDeps {
   cleanup(): Promise<void>;
-  focusOrCreateWindow(signal: AbortSignal): void;
+  focusOrCreateWindow(signal: AbortSignal): void | Promise<void>;
   onCleanupError(error: unknown): void;
+  onWindowCreationError(error: unknown): void;
   resumeQuit(): void;
 }
 
@@ -43,10 +43,13 @@ export function createAppQuitCoordinator(deps: AppQuitCoordinatorDeps): AppQuitC
   return {
     focusOrCreateWindow(): void {
       if (phase !== 'running') return;
-      deps.focusOrCreateWindow(windowCreationAbort.signal);
-    },
-    getWindowCreationSignal(): AbortSignal | undefined {
-      return phase === 'running' ? windowCreationAbort.signal : undefined;
+      try {
+        void Promise.resolve(deps.focusOrCreateWindow(windowCreationAbort.signal)).catch(
+          deps.onWindowCreationError,
+        );
+      } catch (error) {
+        deps.onWindowCreationError(error);
+      }
     },
     handleBeforeQuit(event): void {
       if (phase === 'ready-to-exit') return;
diff --git a/apps/desktop/src/main/main-process-diagnostics.ts b/apps/desktop/src/main/main-process-diagnostics.ts
index 200af1cf9..618da6e02 100644
--- a/apps/desktop/src/main/main-process-diagnostics.ts
+++ b/apps/desktop/src/main/main-process-diagnostics.ts
@@ -75,9 +75,18 @@ export interface DesktopStartupDiagnosticInput {
   readonly hostTarget: 'none';
 }
 
+export interface DesktopMainRendererDiagnosticInput {
+  readonly surface: 'renderer_process_gone';
+  readonly title: string;
+  readonly description?: string;
+  readonly details?: string;
+  readonly hostTarget: 'none';
+}
+
 export type DesktopDiagnosticReportInput =
   | DesktopDiagnosticWireInput
-  | DesktopStartupDiagnosticInput;
+  | DesktopStartupDiagnosticInput
+  | DesktopMainRendererDiagnosticInput;
 
 export type RuntimeHostDiagnosticRead =
   | { readonly ok: true; readonly value: HostDiagnosticsResult }
@@ -139,6 +148,27 @@ export function createDesktopStartupDiagnosticInput(input: {
 }): DesktopStartupDiagnosticInput {
   return {
     surface: 'startup',
+    ...createDesktopNativeDiagnosticFields(input),
+  };
+}
+
+export function createDesktopMainRendererDiagnosticInput(input: {
+  readonly title: string;
+  readonly description?: string;
+  readonly details?: string;
+}): DesktopMainRendererDiagnosticInput {
+  return {
+    surface: 'renderer_process_gone',
+    ...createDesktopNativeDiagnosticFields(input),
+  };
+}
+
+function createDesktopNativeDiagnosticFields(input: {
+  readonly title: string;
+  readonly description?: string;
+  readonly details?: string;
+}): Omit<DesktopStartupDiagnosticInput, 'surface'> {
+  return {
     hostTarget: 'none',
     title: requireDiagnosticString(input.title, 'title', INPUT_LIMITS.title),
     ...(input.description
@@ -327,7 +357,12 @@ export function formatDesktopDiagnosticReport(
   capturedAt = new Date(),
 ): string {
   const lines = ['Maka Desktop diagnostic report', `Captured at: ${capturedAt.toISOString()}`];
-  const rendererContext = input.surface === 'startup' ? undefined : input;
+  const rendererContext =
+    input.surface === 'manual' ||
+    input.surface === 'toast' ||
+    input.surface === 'renderer_crash'
+      ? input
+      : undefined;
   if (input.surface === 'manual') {
     lines.push('', 'Capture', 'Surface: manual');
   } else {
diff --git a/apps/desktop/src/main/main-renderer-process-gone.ts b/apps/desktop/src/main/main-renderer-process-gone.ts
new file mode 100644
index 000000000..9e741df8f
--- /dev/null
+++ b/apps/desktop/src/main/main-renderer-process-gone.ts
@@ -0,0 +1,19 @@
+import type { RenderProcessGoneDetails } from 'electron';
+
+interface RenderProcessGoneSource {
+  once(
+    event: 'render-process-gone',
+    listener: (event: unknown, details: RenderProcessGoneDetails) => void,
+  ): void;
+}
+
+export function observeMainRendererProcessGone(deps: {
+  readonly source: RenderProcessGoneSource;
+  readonly shutdownSignal: AbortSignal;
+  readonly onUnexpectedExit: (details: RenderProcessGoneDetails) => void;
+}): void {
+  deps.source.once('render-process-gone', (_event, details) => {
+    if (deps.shutdownSignal.aborted || details.reason === 'clean-exit') return;
+    deps.onUnexpectedExit(details);
+  });
+}
diff --git a/apps/desktop/src/main/main-window.ts b/apps/desktop/src/main/main-window.ts
index 956738c84..5cb81171c 100644
--- a/apps/desktop/src/main/main-window.ts
+++ b/apps/desktop/src/main/main-window.ts
@@ -29,6 +29,7 @@ import { BrowserViewController } from './browser/controller.js';
 import { BrowserViewManager } from './browser/view-manager.js';
 import type { E2eFixture } from './e2e-fixture.js';
 import { installMainWindowPermissionPolicy } from './main-window-permission-policy.js';
+import { observeMainRendererProcessGone } from './main-renderer-process-gone.js';
 import { isThemePreference, toNativeThemeSource } from './theme-source.js';
 import { createWindowRevealGate } from './window-reveal.js';
 import {
@@ -85,6 +86,7 @@ interface MainWindowControllerDeps {
   // and the fake backend, so main-window.ts owns no env policy of its own.
   startHidden: boolean;
   onClose?: () => void;
+  onRendererProcessGone: (details: Electron.RenderProcessGoneDetails) => void | Promise<void>;
 }
 
 let mainWindow: BrowserWindow | null = null;
@@ -367,6 +369,21 @@ export function createMainWindowController(deps: MainWindowControllerDeps): Main
         allowRunningInsecureContent: false,
       },
     });
+    observeMainRendererProcessGone({
+      source: mainWindow.webContents,
+      shutdownSignal: signal,
+      onUnexpectedExit: (details) => {
+        console.error(
+          `[renderer] main Renderer process exited unexpectedly: reason=${details.reason} exitCode=${details.exitCode}`,
+        );
+        void Promise.resolve()
+          .then(() => deps.onRendererProcessGone(details))
+          .catch((error) => {
+            console.error('[renderer] failed to handle main Renderer process exit:', error);
+            app.quit();
+          });
+      },
+    });
     installMainWindowPermissionPolicy(mainWindow.webContents, rendererEntryUrl);
 
     // Two-layer external-link hygiene: assistant markdown often emits `<a href>`
diff --git a/apps/desktop/src/main/native-diagnostic-dialog.ts b/apps/desktop/src/main/native-diagnostic-dialog.ts
index 194e0c7e1..d7d2fb467 100644
--- a/apps/desktop/src/main/native-diagnostic-dialog.ts
+++ b/apps/desktop/src/main/native-diagnostic-dialog.ts
@@ -18,7 +18,10 @@
  */
 
 import type { UiLocale } from '@maka/core/ui-locale';
-import type { MessageBoxOptions, MessageBoxReturnValue } from 'electron';
+import type {
+  MessageBoxOptions,
+  MessageBoxReturnValue,
+} from 'electron';
 import {
   createDesktopStartupDiagnosticInput,
   formatDesktopDiagnosticReport,
@@ -26,13 +29,23 @@ import {
 } from './main-process-diagnostics.js';
 import { whileAwaitingPerson } from './startup-step.js';
 
+interface DiagnosticDialogDeps {
+  readonly locale: UiLocale;
+  readonly copyDiagnostics: () => void | Promise<void>;
+  readonly showMessageBox: (options: MessageBoxOptions) => Promise<MessageBoxReturnValue>;
+}
+
+interface FatalStartupDiagnosticDialogDeps {
+  readonly locale: UiLocale;
+  readonly environment: () => DesktopDiagnosticEnvironment;
+  readonly mainLogs: () => readonly string[];
+  readonly writeClipboard: (value: string) => void;
+  readonly showMessageBox: (options: MessageBoxOptions) => Promise<MessageBoxReturnValue>;
+}
+
 export async function showMessageBoxWithDiagnostics(
   options: MessageBoxOptions,
-  deps: {
-    readonly locale: UiLocale;
-    readonly copyDiagnostics: () => void | Promise<void>;
-    readonly showMessageBox: (options: MessageBoxOptions) => Promise<MessageBoxReturnValue>;
-  },
+  deps: DiagnosticDialogDeps,
 ): Promise<MessageBoxReturnValue> {
   let status: string | undefined;
   for (;;) {
@@ -45,13 +58,7 @@ export async function showMessageBoxWithDiagnostics(
 
 export async function showFatalStartupError(
   error: unknown,
-  deps: {
-    readonly locale: UiLocale;
-    readonly environment: () => DesktopDiagnosticEnvironment;
-    readonly mainLogs: () => readonly string[];
-    readonly writeClipboard: (value: string) => void;
-    readonly showMessageBox: (options: MessageBoxOptions) => Promise<MessageBoxReturnValue>;
-  },
+  deps: FatalStartupDiagnosticDialogDeps,
 ): Promise<void> {
   const copy = FATAL_STARTUP_COPY[deps.locale];
   const message = error instanceof Error ? error.message : String(error);
@@ -87,6 +94,26 @@ export async function showFatalStartupError(
   );
 }
 
+export async function showMainRendererProcessGoneDialog(
+  deps: DiagnosticDialogDeps,
+): Promise<'relaunch' | 'exit'> {
+  const copy = MAIN_RENDERER_GONE_COPY[deps.locale];
+  const result = await showMessageBoxWithDiagnostics(
+    {
+      type: 'error',
+      title: copy.title,
+      message: copy.message,
+      detail: copy.detail,
+      buttons: [copy.relaunch, copy.exit],
+      defaultId: 0,
+      cancelId: 1,
+      noLink: true,
+    },
+    deps,
+  );
+  return result.response === 0 ? 'relaunch' : 'exit';
+}
+
 async function copyDiagnostics(
   copy: () => void | Promise<void>,
   locale: UiLocale,
@@ -151,3 +178,20 @@ const FATAL_STARTUP_COPY = {
     exit: '退出',
   },
 } as const;
+
+const MAIN_RENDERER_GONE_COPY = {
+  en: {
+    title: 'Maka needs to recover',
+    message: "Maka's interface stopped unexpectedly.",
+    detail: 'Relaunch Maka to continue, or exit and reopen it later.',
+    relaunch: 'Relaunch',
+    exit: 'Exit',
+  },
+  zh: {
+    title: 'Maka 需要恢复',
+    message: 'Maka 界面意外停止运行。',
+    detail: '重新启动 Maka 以继续,或退出后稍后再打开。',
+    relaunch: '重新启动',
+    exit: '退出',
+  },
+} as const;
diff --git a/apps/desktop/src/main/runtime-host-boot.ts b/apps/desktop/src/main/runtime-host-boot.ts
index 3122bcf99..8ae077969 100644
--- a/apps/desktop/src/main/runtime-host-boot.ts
+++ b/apps/desktop/src/main/runtime-host-boot.ts
@@ -93,11 +93,15 @@ import { createMainWindowController } from "./main-window.js";
 import {
   captureDesktopDiagnosticEnvironment,
   copyDesktopDiagnosticReport,
+  createDesktopMainRendererDiagnosticInput,
   createDesktopStartupDiagnosticInput,
   mainProcessLogBuffer,
   type DesktopDiagnosticsDeps,
 } from "./main-process-diagnostics.js";
-import { showMessageBoxWithDiagnostics } from "./native-diagnostic-dialog.js";
+import {
+  showMainRendererProcessGoneDialog,
+  showMessageBoxWithDiagnostics,
+} from "./native-diagnostic-dialog.js";
 import {
   resolveDesktopSessionWorkspace,
 } from "./new-session-project.js";
@@ -342,6 +346,21 @@ const mainWindowController = createMainWindowController({
   settingsStore,
   startHidden,
   onClose: () => onMainWindowClose(),
+  onRendererProcessGone: async (details) => {
+    const diagnosticInput = createDesktopMainRendererDiagnosticInput({
+      title: "Maka main Renderer process exited unexpectedly",
+      description: `Reason: ${details.reason}`,
+      details: `Exit code: ${details.exitCode}`,
+    });
+    const decision = await showMainRendererProcessGoneDialog({
+      locale: desktopLocale.current(),
+      copyDiagnostics: () =>
+        copyDesktopDiagnosticReport(desktopDiagnostics, diagnosticInput),
+      showMessageBox: (options) => dialog.showMessageBox(options),
+    });
+    if (decision === "relaunch") app.relaunch();
+    app.quit();
+  },
 });
 const runtimeHostSshTerminal = createDesktopRuntimeHostSshTerminal({
   ipcMain,
@@ -1440,10 +1459,12 @@ function wireLifecycle(): void {
     cleanup: closeRuntimeHostDesktop,
     focusOrCreateWindow: (signal) => {
       if (mainWindowController.hasOpenWindows()) mainWindowController.focus();
-      else void mainWindowController.createWindow(signal);
+      else return mainWindowController.createWindow(signal);
     },
     onCleanupError: (error) =>
       console.error("[runtime-host] shutdown failed:", error),
+    onWindowCreationError: (error) =>
+      console.error("[window] creation failed:", error),
     resumeQuit: () => app.quit(),
   });
   installDesktopShellPresentation({
@@ -1464,8 +1485,7 @@ function wireLifecycle(): void {
     if (process.platform !== "darwin") app.quit();
   });
   app.on("before-quit", quitCoordinator.handleBeforeQuit);
-  const initialWindowSignal = quitCoordinator.getWindowCreationSignal();
-  if (initialWindowSignal) void mainWindowController.createWindow(initialWindowSignal);
+  quitCoordinator.focusOrCreateWindow();
 }
 
 async function closeRuntimeHostDesktop(): Promise<void> {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org