@amd-gaia/agent-ui 0.27.0-rc.10 → 0.27.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/assets/AdvancedSettings-D2hiKcb8.js +1 -0
  2. package/dist/assets/AutomationsSettings-kmr5NhGJ.js +1 -0
  3. package/dist/assets/ConnectorsPane-BKJzwjs_.js +1 -0
  4. package/dist/assets/ConnectorsPane-BxG6qzLb.css +1 -0
  5. package/dist/assets/DocumentLibrary-Cen-e75Q.js +5 -0
  6. package/dist/assets/{DocumentLibrary-fEMoY7lH.css → DocumentLibrary-Ctwq2m2t.css} +1 -1
  7. package/dist/assets/FileBrowser-C1BvzIK3.js +4 -0
  8. package/dist/assets/FileBrowser-D0IsL30H.css +1 -0
  9. package/dist/assets/MemoryDashboard-CTv0qxep.js +1 -0
  10. package/dist/assets/MemoryDashboard-DNhdvlcl.css +1 -0
  11. package/dist/assets/MessagingSettings-Z9ZX0Hcu.js +1 -0
  12. package/dist/assets/{MobileAccessModal-BrZMaERi.css → MobileAccessModal-DSFjH6di.css} +1 -1
  13. package/dist/assets/MobileAccessModal-De86l1zd.js +2 -0
  14. package/dist/assets/ScheduleManager-BLUwCMl0.js +1 -0
  15. package/dist/assets/{ScheduleManager-BZzEH2-W.css → ScheduleManager-CzW_0sNI.css} +1 -1
  16. package/dist/assets/folderIndexResult-kIPjvkMW.js +1 -0
  17. package/dist/assets/index-BFIVkgAZ.js +226 -0
  18. package/dist/assets/index-DB1-bDNU.css +1 -0
  19. package/dist/assets/useFocusTrap-CzBMA4Ux.js +6 -0
  20. package/dist/index.html +3 -3
  21. package/dist/sw.js +1 -1
  22. package/main-safety-net.cjs +26 -2
  23. package/main.cjs +188 -58
  24. package/package.json +2 -2
  25. package/services/backend-crash-dialog.cjs +19 -5
  26. package/services/backend-health-monitor.cjs +86 -0
  27. package/services/backend-installer.cjs +1 -0
  28. package/services/backend-supervisor.cjs +35 -9
  29. package/services/browser-pane/dev-servers.cjs +44 -1
  30. package/services/browser-pane/listen-addresses.cjs +140 -0
  31. package/services/context-menu.cjs +79 -0
  32. package/services/link-policy.cjs +78 -7
  33. package/services/port-manager.cjs +2 -3
  34. package/services/process-tree.cjs +84 -14
  35. package/dist/assets/AdvancedSettings-BLR8jrQ6.js +0 -1
  36. package/dist/assets/AutomationsSettings-Cl-NlbrD.js +0 -1
  37. package/dist/assets/ConnectorsPane-BGI8nBUb.css +0 -1
  38. package/dist/assets/ConnectorsPane-Dcuevs9v.js +0 -1
  39. package/dist/assets/DocumentLibrary-BHNYPjV3.js +0 -5
  40. package/dist/assets/FileBrowser-1goNp4CP.css +0 -1
  41. package/dist/assets/FileBrowser-Dosu_Lh8.js +0 -4
  42. package/dist/assets/MemoryDashboard-1g_y8lqR.js +0 -1
  43. package/dist/assets/MemoryDashboard-RpfLag-v.css +0 -1
  44. package/dist/assets/MessagingSettings-DkTMjERx.js +0 -1
  45. package/dist/assets/MobileAccessModal-Cj_Qjsbv.js +0 -2
  46. package/dist/assets/ScheduleManager-B8xUdWID.js +0 -1
  47. package/dist/assets/index-bP0Mo7oA.css +0 -1
  48. package/dist/assets/index-eiWfnMcl.js +0 -225
  49. package/dist/assets/useFocusTrap-hXXaHKVF.js +0 -6
package/dist/index.html CHANGED
@@ -26,10 +26,10 @@
26
26
  // main.tsx applies the theme again and reports why it could not read the saved one.
27
27
  }
28
28
  </script>
29
- <script type="module" crossorigin src="./assets/index-eiWfnMcl.js"></script>
29
+ <script type="module" crossorigin src="./assets/index-BFIVkgAZ.js"></script>
30
30
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-XKyaHtl9.js">
31
- <link rel="modulepreload" crossorigin href="./assets/useFocusTrap-hXXaHKVF.js">
32
- <link rel="stylesheet" crossorigin href="./assets/index-bP0Mo7oA.css">
31
+ <link rel="modulepreload" crossorigin href="./assets/useFocusTrap-CzBMA4Ux.js">
32
+ <link rel="stylesheet" crossorigin href="./assets/index-DB1-bDNU.css">
33
33
  </head>
34
34
  <body>
35
35
  <div id="root"></div>
package/dist/sw.js CHANGED
@@ -9,7 +9,7 @@
9
9
  // never sees a stale UI or stale data.
10
10
 
11
11
  const CACHE_PREFIX = 'gaia-assets-';
12
- const CACHE_NAME = CACHE_PREFIX + '0.27.0rc10-bb079cbcce58215c';
12
+ const CACHE_NAME = CACHE_PREFIX + '0.27.0rc13-906cbe39bcfa5271';
13
13
  const ASSETS_PATH = new URL('assets/', self.registration.scope).pathname;
14
14
 
15
15
  self.addEventListener('install', () => {
@@ -87,6 +87,9 @@ function appendLog(logPath, msg) {
87
87
  }
88
88
  }
89
89
 
90
+ // Chats live in the backend's database, written as each message is sent.
91
+ const FATAL_MESSAGE = "GAIA ran into a problem and needs to restart. Your chats are saved.";
92
+
90
93
  /** How long a fatal error's quit may take before the process is ended outright (ms). */
91
94
  const FATAL_EXIT_GRACE_MS = 25000;
92
95
 
@@ -107,6 +110,9 @@ const FATAL_EXIT_GRACE_MS = 25000;
107
110
  * when a window's page dies while GAIA runs on, e.g. to offer a reload.
108
111
  * Without it, or if it throws synchronously, the crash is fatal; an async
109
112
  * handler must handle its own failures.
113
+ * @param {Function} [opts.isPanePage] - Called with a webContents whose page
114
+ * died; true means it is a browser-pane tab, which shows its own notice, so
115
+ * the crash is logged only: no dialog, no quit, no crash count.
110
116
  */
111
117
  function installSafetyNet({
112
118
  logPath,
@@ -117,6 +123,7 @@ function installSafetyNet({
117
123
  exitGraceMs = FATAL_EXIT_GRACE_MS,
118
124
  holdCrashCount = () => false,
119
125
  onRendererGone,
126
+ isPanePage,
120
127
  }) {
121
128
  const homedir = homedirFn || (() => os.homedir());
122
129
 
@@ -179,11 +186,12 @@ function installSafetyNet({
179
186
  dialogModule.showMessageBoxSync({
180
187
  type: "error",
181
188
  title: "GAIA crashed",
182
- message: stack,
189
+ message: FATAL_MESSAGE,
190
+ detail: stack,
183
191
  buttons: ["OK"],
184
192
  });
185
193
  } else {
186
- dialogModule.showErrorBox("GAIA failed to start", stack);
194
+ dialogModule.showErrorBox("GAIA failed to start", `${FATAL_MESSAGE}\n\n${stack}`);
187
195
  }
188
196
  } catch { } // intentional: fatal path, no upstream
189
197
 
@@ -214,6 +222,21 @@ function installSafetyNet({
214
222
  appendLog(logPath, `[${new Date().toISOString()}] RENDER_PROCESS_EXITED reason=${reason}`);
215
223
  return;
216
224
  }
225
+ if (typeof isPanePage === "function") {
226
+ let panePage = false;
227
+ try {
228
+ panePage = isPanePage(webContents) === true;
229
+ } catch (err) {
230
+ appendLog(logPath, `[${new Date().toISOString()}] RENDER_PROCESS_GONE pane check failed: ${err.stack || err}`);
231
+ }
232
+ if (panePage) {
233
+ appendLog(
234
+ logPath,
235
+ `[${new Date().toISOString()}] PANE_PAGE_GONE reason=${reason} exitCode=${details && details.exitCode}`
236
+ );
237
+ return;
238
+ }
239
+ }
217
240
  if (typeof onRendererGone === "function") {
218
241
  // Only the page died: the backend and agents still run, so the window can come back.
219
242
  appendLog(
@@ -348,6 +371,7 @@ module.exports = {
348
371
  installSafetyNet,
349
372
  installLogTee,
350
373
  FATAL_EXIT_GRACE_MS,
374
+ FATAL_MESSAGE,
351
375
  readCount,
352
376
  runSafeModePrompt,
353
377
  SAFE_MODE_THRESHOLD,
package/main.cjs CHANGED
@@ -17,6 +17,7 @@ const {
17
17
  app,
18
18
  autoUpdater: electronAutoUpdater,
19
19
  BrowserWindow,
20
+ clipboard,
20
21
  Menu,
21
22
  dialog,
22
23
  ipcMain,
@@ -71,6 +72,8 @@ try {
71
72
  onRendererGone: (contents, details) => {
72
73
  void handleRendererGone(contents, details);
73
74
  },
75
+ // A pane tab's crash is the pane's to report ("Reload to try again"), not GAIA's.
76
+ isPanePage: (contents) => contents.session === session.fromPartition(PANE_PARTITION),
74
77
  }));
75
78
  } catch (err) {
76
79
  try { process.stderr.write(`[main] safety-net load failed: ${err.message}\n`); } catch { }
@@ -113,6 +116,7 @@ const {
113
116
  const { showBackendCrashDialog } = require("./services/backend-crash-dialog.cjs");
114
117
  const { showRendererGoneDialog } = require("./services/renderer-gone-dialog.cjs");
115
118
  const { createBackendSupervisor } = require("./services/backend-supervisor.cjs");
119
+ const { createBackendHealthMonitor } = require("./services/backend-health-monitor.cjs");
116
120
  const { buildIndexQuery, INSTALL_SCREEN_QUERY } = require("./services/index-query.cjs");
117
121
  const backendInstaller = require("./services/backend-installer.cjs");
118
122
  const { createEngineInstall } = require("./services/engine-install.cjs");
@@ -123,8 +127,12 @@ const {
123
127
  isAllowedExternalUrl,
124
128
  isInAppNavigation,
125
129
  describeBlockedUrl,
130
+ describeOpenFailure,
131
+ openExternalSafely,
132
+ linkNoticeText,
126
133
  } = require("./services/link-policy.cjs");
127
134
  const { installWindowKeys } = require("./services/window-keys.cjs");
135
+ const { installContextMenu } = require("./services/context-menu.cjs");
128
136
  const { installQuitCleanup } = require("./services/quit-cleanup.cjs");
129
137
  const { chromiumSwitches } = require("./services/chromium-switches.cjs");
130
138
  const { titleBarKind, titleBarOptions } = require("./services/window-frame.cjs");
@@ -228,6 +236,7 @@ const APP_NAME = "GAIA";
228
236
  // from prior aborted sessions (issue #782 / T5).
229
237
  const DEFAULT_BACKEND_PORT = 4200;
230
238
  const STARTUP_TIMEOUT = 30000;
239
+ const BACKEND_HEALTH_CHECK_TIMEOUT = 2000;
231
240
  // A restart must answer within this, or it counts as a failed try.
232
241
  const RESTART_TIMEOUT = 90000;
233
242
 
@@ -259,6 +268,9 @@ const windowConfig = appConfig.window || {
259
268
  // ── State ──────────────────────────────────────────────────────────────────
260
269
 
261
270
  let backendProcess = null;
271
+ let backendCleanupPending = null;
272
+ let backendHealthMonitoringEnabled = false;
273
+ let backendHealthMonitor = null;
262
274
  // The in-flight startBackend(), so a quit during startup can wait for the
263
275
  // spawn and stop it instead of leaving it behind.
264
276
  let backendStarting = null;
@@ -348,6 +360,15 @@ async function cleanupOrphanedBackend() {
348
360
  });
349
361
  }
350
362
 
363
+ /** What the user reads when GAIA's backend program can't be found: what to do, and where it looked. */
364
+ function missingBackendMessage() {
365
+ const looked = [backendInstaller.BUNDLED_GAIA_BIN, backendInstaller.GAIA_BIN].filter(Boolean).join(", ");
366
+ return (
367
+ "GAIA's backend program is missing, so GAIA can't start: the app's files are incomplete. " +
368
+ `Reinstall GAIA from https://amd-gaia.ai/#install. Looked for ${looked} and for gaia on PATH.`
369
+ );
370
+ }
371
+
351
372
  /**
352
373
  * Start the GAIA Python backend. Expects the backend installer to have
353
374
  * already ensured the venv is populated — callers should await
@@ -489,19 +510,47 @@ async function startBackend() {
489
510
  return child;
490
511
  }
491
512
 
513
+ /** Stop a backend tree and keep its handle pending until termination is verified. */
514
+ async function stopBackendTree(proc) {
515
+ backendCleanupPending = proc;
516
+ isIntentionalKill = true;
517
+ try {
518
+ const result = await portManager.killBackend(proc);
519
+ if (!result || !Array.isArray(result.survivors)) {
520
+ throw new Error("The backend stop did not confirm that its process tree exited.");
521
+ }
522
+ if (result.survivors.length) {
523
+ throw new Error(`The backend process tree is still running (pid ${result.survivors.join(", ")}).`);
524
+ }
525
+ if (result.verified !== true) {
526
+ throw new Error(
527
+ "The backend process tree could not be verified as stopped. " +
528
+ "Quit GAIA, end any leftover GAIA or Python processes in Task Manager, then reopen GAIA."
529
+ );
530
+ }
531
+ } catch (err) {
532
+ isIntentionalKill = false;
533
+ throw err;
534
+ }
535
+ if (backendCleanupPending === proc) backendCleanupPending = null;
536
+ if (backendProcess === proc) backendProcess = null;
537
+ }
538
+
492
539
  /**
493
540
  * Start a new backend for the supervisor and resolve once it answers.
494
541
  * Rejects when it exits first or never answers, so the supervisor retries.
542
+ * A backend still alive here is a hung one Restart GAIA was pressed for:
543
+ * stop it first, or the new backend would run beside it on a new port.
495
544
  */
496
545
  async function restartBackend() {
546
+ const previousBackend = backendCleanupPending || backendProcess;
547
+ if (previousBackend) await stopBackendTree(previousBackend);
548
+
497
549
  backendStarting = startBackend();
498
550
  const child = await backendStarting;
499
- if (!child) {
500
- throw new Error("GAIA's backend program is missing, so it can't restart. Reinstall GAIA.");
501
- }
551
+ if (!child) throw Object.assign(new Error(missingBackendMessage()), { terminal: true });
502
552
  if (quitStarted()) {
503
- isIntentionalKill = true;
504
- await portManager.killBackend(child);
553
+ await stopBackendTree(child);
505
554
  throw new Error("GAIA is quitting, so the restarted backend was stopped.");
506
555
  }
507
556
  backendProcess = child;
@@ -511,10 +560,10 @@ async function restartBackend() {
511
560
  if (!alive()) {
512
561
  throw new Error(`The backend exited (code ${child.exitCode}, signal ${child.signalCode}) before it answered.`);
513
562
  }
514
- isIntentionalKill = true;
515
- await portManager.killBackend(child);
563
+ await stopBackendTree(child);
516
564
  throw new Error(`The backend did not answer within ${RESTART_TIMEOUT / 1000} s.`);
517
565
  }
566
+ enableBackendHealthMonitoring();
518
567
  console.log(`[main] Backend restarted on port ${backendPort} (pid=${child.pid})`);
519
568
  if (trayManager) {
520
569
  trayManager.setBackendPort(backendPort);
@@ -531,21 +580,42 @@ function backendStateForRenderer(state) {
531
580
  const backendSupervisor = createBackendSupervisor({
532
581
  start: restartBackend,
533
582
  onStopped: (state) => {
534
- const { code = null, signal = null } = state.lastExit || {};
535
- void handleBackendCrash(code, signal);
583
+ void handleBackendCrash(state);
536
584
  },
537
585
  onState: (state) => {
586
+ if (backendHealthMonitor) {
587
+ if (backendHealthMonitoringEnabled && state.status === "running") backendHealthMonitor.start();
588
+ else backendHealthMonitor.stop();
589
+ }
538
590
  console.log(
539
591
  `[main] Backend ${state.status}` +
540
592
  (state.status === "restarting" ? ` (try ${state.attempt} of ${state.maxRestarts})` : "") +
541
593
  (state.lastError ? `: ${state.lastError}` : "")
542
594
  );
595
+ // A backend up again after a failed start leaves nothing to roll back from.
596
+ if (state.status === "running") autoUpdater.clearStartFailure();
543
597
  if (mainWindow && !mainWindow.isDestroyed()) {
544
598
  mainWindow.webContents.send("backend:state", backendStateForRenderer(state));
545
599
  }
546
600
  },
547
601
  });
548
602
 
603
+ backendHealthMonitor = createBackendHealthMonitor({
604
+ check: checkBackendHealth,
605
+ onUnhealthy: (error, failures) => {
606
+ const message = error && error.message ? error.message : String(error);
607
+ const reason = new Error(`Health check failed ${failures} consecutive times: ${message}`);
608
+ console.warn(`[main] ${reason.message}`);
609
+ backendSupervisor.healthFailed(reason);
610
+ },
611
+ });
612
+
613
+ function enableBackendHealthMonitoring() {
614
+ if (quitStarted()) return;
615
+ backendHealthMonitoringEnabled = true;
616
+ if (backendSupervisor.getState().status === "running") backendHealthMonitor.start();
617
+ }
618
+
549
619
  ipcMain.handle("backend:get-state", () => backendStateForRenderer(backendSupervisor.getState()));
550
620
  ipcMain.handle("backend:restart", () => {
551
621
  backendSupervisor.restartNow();
@@ -556,7 +626,8 @@ ipcMain.handle("backend:restart", () => {
556
626
  * Tell the user the backend stopped and offer Restart / Save diagnostics /
557
627
  * Quit. Invoked by the supervisor's onStopped once automatic restarts run out.
558
628
  */
559
- async function handleBackendCrash(code, signal) {
629
+ async function handleBackendCrash(state) {
630
+ const { code = null, signal = null } = state.lastExit || {};
560
631
  autoUpdater.reportStartFailure();
561
632
  try {
562
633
  const choice = await showBackendCrashDialog({
@@ -564,6 +635,7 @@ async function handleBackendCrash(code, signal) {
564
635
  app,
565
636
  code,
566
637
  signal,
638
+ reason: state.lastError,
567
639
  tailLines: backendStderrTail.slice(-8),
568
640
  writeDiagnostics: () => portManager.writeDiagnosticsBundle(),
569
641
  // The backend is gone, so there is no running work to ask about.
@@ -606,24 +678,10 @@ async function handleRendererGone(contents, { reason }) {
606
678
 
607
679
  async function waitForBackend(timeoutMs, isAlive = () => true) {
608
680
  const start = Date.now();
609
- const http = require("http");
610
681
 
611
682
  while (Date.now() - start < timeoutMs && isAlive()) {
612
683
  try {
613
- await new Promise((resolve, reject) => {
614
- const req = http.get(healthCheckUrl, (res) => {
615
- if (res.statusCode === 200) {
616
- resolve();
617
- } else {
618
- reject(new Error(`Status ${res.statusCode}`));
619
- }
620
- });
621
- req.on("error", reject);
622
- req.setTimeout(2000, () => {
623
- req.destroy();
624
- reject(new Error("timeout"));
625
- });
626
- });
684
+ await checkBackendHealth();
627
685
  return true;
628
686
  } catch {
629
687
  await new Promise((r) => setTimeout(r, 500));
@@ -632,6 +690,51 @@ async function waitForBackend(timeoutMs, isAlive = () => true) {
632
690
  return false;
633
691
  }
634
692
 
693
+ function checkBackendHealth(signal) {
694
+ const http = require("http");
695
+ return new Promise((resolve, reject) => {
696
+ let settled = false;
697
+ let deadline = null;
698
+ let req = null;
699
+ const onAbort = () => {
700
+ const error = new Error("Health check was cancelled.");
701
+ finish(reject, error);
702
+ req.destroy(error);
703
+ };
704
+ const finish = (handler, value) => {
705
+ if (settled) return;
706
+ settled = true;
707
+ if (deadline) clearTimeout(deadline);
708
+ if (signal) signal.removeEventListener("abort", onAbort);
709
+ handler(value);
710
+ };
711
+ req = http.get(healthCheckUrl, (res) => {
712
+ if (res.statusCode !== 200) {
713
+ finish(reject, new Error(`Health endpoint returned status ${res.statusCode}.`));
714
+ res.destroy();
715
+ return;
716
+ }
717
+ res.once("end", () => finish(resolve));
718
+ res.once("aborted", () => finish(reject, new Error("Health endpoint response was aborted.")));
719
+ res.once("close", () => {
720
+ if (!res.complete) finish(reject, new Error("Health endpoint response closed before completion."));
721
+ });
722
+ res.once("error", (error) => finish(reject, error));
723
+ res.resume();
724
+ });
725
+ deadline = setTimeout(() => {
726
+ const error = new Error("Health endpoint did not answer within 2 s.");
727
+ finish(reject, error);
728
+ req.destroy(error);
729
+ }, BACKEND_HEALTH_CHECK_TIMEOUT);
730
+ req.once("error", (error) => finish(reject, error));
731
+ if (signal) {
732
+ if (signal.aborted) onAbort();
733
+ else signal.addEventListener("abort", onAbort, { once: true });
734
+ }
735
+ });
736
+ }
737
+
635
738
  // ── Window ─────────────────────────────────────────────────────────────────
636
739
 
637
740
  function findDistPath() {
@@ -652,21 +755,41 @@ function findDistPath() {
652
755
 
653
756
  /** Refuse a link loudly — the user clicked it, so they get told why nothing happened. */
654
757
  function reportBlockedLink(url) {
655
- const message = describeBlockedUrl(url);
656
- console.error(`[main] ${message}`);
758
+ const locale = app.getLocale();
759
+ warnAboutLink(
760
+ linkNoticeText(locale).blockedTitle,
761
+ describeBlockedUrl(url, locale),
762
+ describeBlockedUrl(url),
763
+ locale,
764
+ );
765
+ }
766
+
767
+ function reportLinkNotOpened(url, err) {
768
+ const locale = app.getLocale();
769
+ warnAboutLink(
770
+ linkNoticeText(locale).notOpenedTitle,
771
+ describeOpenFailure(url, err, locale),
772
+ describeOpenFailure(url, err),
773
+ locale,
774
+ );
775
+ }
776
+
777
+ // The log line stays English so bug reports stay readable.
778
+ function warnAboutLink(title, message, logMessage, locale) {
779
+ console.error(`[main] ${logMessage}`);
657
780
  // Non-blocking and parented: showErrorBox would freeze the main process.
658
781
  dialog
659
782
  .showMessageBox(mainWindow && !mainWindow.isDestroyed() ? mainWindow : null, {
660
783
  type: "warning",
661
- title: "Link blocked",
662
- message: "Link blocked",
784
+ title,
785
+ message: title,
663
786
  detail: message,
664
- buttons: ["OK"],
787
+ buttons: [linkNoticeText(locale).ok],
665
788
  noLink: true,
666
789
  })
667
790
  .catch((err) =>
668
791
  console.error(
669
- `[main] Could not show the link-blocked dialog: ${err && err.message ? err.message : err}`
792
+ `[main] Could not show the "${title}" dialog: ${err && err.message ? err.message : err}`
670
793
  )
671
794
  );
672
795
  }
@@ -733,13 +856,14 @@ function createWindow() {
733
856
  installWindowKeys(mainWindow.webContents, { devTools: !app.isPackaged });
734
857
  }
735
858
  mainWindow.setMenuBarVisibility(false);
859
+ installContextMenu(mainWindow, { Menu, clipboard, locale: app.getLocale() });
736
860
 
737
861
  // Open external links in the default browser. The URL here is already
738
862
  // RESOLVED against the file:// document, so a scheme-less markdown link
739
863
  // arrives as file:///C:/… — check the scheme before handing it to the OS.
740
864
  mainWindow.webContents.setWindowOpenHandler(({ url }) => {
741
865
  if (isAllowedExternalUrl(url)) {
742
- shell.openExternal(url);
866
+ openExternalSafely(shell, url, (err) => reportLinkNotOpened(url, err));
743
867
  } else {
744
868
  reportBlockedLink(url);
745
869
  }
@@ -753,7 +877,7 @@ function createWindow() {
753
877
  if (isInAppNavigation(url, currentUrl)) return;
754
878
  event.preventDefault();
755
879
  if (isAllowedExternalUrl(url)) {
756
- shell.openExternal(url);
880
+ openExternalSafely(shell, url, (err) => reportLinkNotOpened(url, err));
757
881
  return;
758
882
  }
759
883
  reportBlockedLink(url);
@@ -861,9 +985,11 @@ async function loadApp() {
861
985
  </div>
862
986
  </body>
863
987
  </html>`;
864
- mainWindow.loadURL(
865
- "data:text/html;charset=utf-8," + encodeURIComponent(waitingHtml)
866
- );
988
+ mainWindow
989
+ .loadURL("data:text/html;charset=utf-8," + encodeURIComponent(waitingHtml))
990
+ .catch((err) =>
991
+ console.error(`[main] Could not show the waiting page: ${err && err.message ? err.message : err}`)
992
+ );
867
993
  }
868
994
  }
869
995
 
@@ -980,22 +1106,13 @@ function setupJumpList() {
980
1106
  items: [
981
1107
  {
982
1108
  type: "task",
983
- title: "New Task",
984
- description: "Start a new agent task",
1109
+ title: "Open GAIA",
1110
+ description: "Show the GAIA window",
985
1111
  program: process.execPath,
986
1112
  args: "",
987
1113
  iconPath: process.execPath,
988
1114
  iconIndex: 0,
989
1115
  },
990
- {
991
- type: "task",
992
- title: "Agent Manager",
993
- description: "View and manage OS agents",
994
- program: process.execPath,
995
- args: "--show-agents",
996
- iconPath: process.execPath,
997
- iconIndex: 0,
998
- },
999
1116
  ],
1000
1117
  },
1001
1118
  ]);
@@ -1188,7 +1305,9 @@ app.whenReady().then(async () => {
1188
1305
  if (shutdownStarted) return;
1189
1306
  backendStarting = startBackend();
1190
1307
  backendProcess = await backendStarting;
1308
+ // The window reads this state and shows the failure instead of waiting for a backend.
1191
1309
  if (backendProcess) backendSupervisor.running(backendPort);
1310
+ else backendSupervisor.failedToStart(missingBackendMessage());
1192
1311
  if (shutdownStarted) {
1193
1312
  console.log("[main] Quit during startup — not opening the window");
1194
1313
  return;
@@ -1224,9 +1343,10 @@ app.whenReady().then(async () => {
1224
1343
  let backendReady = false;
1225
1344
  if (backendProcess) {
1226
1345
  console.log("Waiting for backend to start...");
1227
- backendReady = await waitForBackend(STARTUP_TIMEOUT);
1346
+ backendReady = await waitForBackend(STARTUP_TIMEOUT, () => !quitStarted());
1228
1347
  if (backendReady) {
1229
1348
  console.log("Backend API is ready on port", backendPort);
1349
+ enableBackendHealthMonitoring();
1230
1350
  } else {
1231
1351
  console.warn("Backend did not respond within timeout.");
1232
1352
  }
@@ -1234,8 +1354,16 @@ app.whenReady().then(async () => {
1234
1354
  if (!backendReady) {
1235
1355
  autoUpdater.reportStartFailure();
1236
1356
  if (backendProcess) {
1237
- waitForBackend(STARTUP_TIMEOUT * 10).then((ready) => {
1238
- if (ready) autoUpdater.clearStartFailure();
1357
+ waitForBackend(STARTUP_TIMEOUT * 10, () => !quitStarted()).then((ready) => {
1358
+ if (ready) {
1359
+ autoUpdater.clearStartFailure();
1360
+ enableBackendHealthMonitoring();
1361
+ } else if (backendProcess && !quitStarted() && backendSupervisor.getState().status === "running") {
1362
+ backendHealthMonitoringEnabled = true;
1363
+ backendSupervisor.healthFailed(
1364
+ new Error("The backend health endpoint did not respond during the startup grace period.")
1365
+ );
1366
+ }
1239
1367
  });
1240
1368
  }
1241
1369
  }
@@ -1321,6 +1449,7 @@ const quitGuard = installQuitGuard({
1321
1449
  // Mark any subsequent backend exit as intentional so we don't pop the
1322
1450
  // crash dialog during normal shutdown.
1323
1451
  isIntentionalKill = true;
1452
+ backendHealthMonitor.stop();
1324
1453
  backendSupervisor.stop();
1325
1454
  },
1326
1455
  onError: (err) => {
@@ -1336,6 +1465,7 @@ const quitGuard = installQuitGuard({
1336
1465
  // The installer is already running: a restart now would hold its files open.
1337
1466
  electronAutoUpdater.on("before-quit-for-update", () => {
1338
1467
  updateQuitStarted = true;
1468
+ backendHealthMonitor.stop();
1339
1469
  backendSupervisor.stop();
1340
1470
  });
1341
1471
 
@@ -1345,6 +1475,7 @@ installQuitCleanup({ app, cleanup });
1345
1475
 
1346
1476
  async function cleanup() {
1347
1477
  shutdownStarted = true;
1478
+ backendHealthMonitor.stop();
1348
1479
  backendSupervisor.stop();
1349
1480
  const installStopped = engineInstall ? engineInstall.stop() : null;
1350
1481
  const updating = app.isPackaged && autoUpdater.installsOnQuit();
@@ -1427,7 +1558,7 @@ async function stopBackendForQuit() {
1427
1558
  if (backendStarting) {
1428
1559
  try {
1429
1560
  const started = await backendStarting;
1430
- if (started && !backendProcess && started.exitCode === null && started.signalCode === null) {
1561
+ if (started && !backendProcess && !backendCleanupPending && started.exitCode === null && started.signalCode === null) {
1431
1562
  backendProcess = started;
1432
1563
  }
1433
1564
  } catch (err) {
@@ -1439,17 +1570,16 @@ async function stopBackendForQuit() {
1439
1570
  // (SIGTERM → wait 3 s → SIGKILL).
1440
1571
  // F5: previously we did this inline; extracted so main.cjs stays lean and
1441
1572
  // to prevent orphan leaks across runs (issue #782).
1442
- if (backendProcess) {
1573
+ const processToStop = backendCleanupPending || backendProcess;
1574
+ if (processToStop) {
1443
1575
  console.log("Stopping backend process...");
1444
- const proc = backendProcess;
1576
+ const proc = processToStop;
1445
1577
  backendProcess = null;
1446
- isIntentionalKill = true;
1447
1578
 
1448
1579
  try {
1449
- // Pass the ChildProcess handle (not a bare pid) so port-manager
1450
- // can short-circuit via `proc.exitCode` and close the PID-reuse
1451
- // TOCTOU window.
1452
- await portManager.killBackend(proc);
1580
+ // Pass the ChildProcess handle so the process-tree tracker can safely
1581
+ // retry descendants if the launcher exits during termination.
1582
+ await stopBackendTree(proc);
1453
1583
  } catch (err) {
1454
1584
  console.error("Error stopping backend:", err.message);
1455
1585
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amd-gaia/agent-ui",
3
- "version": "0.27.0-rc.10",
3
+ "version": "0.27.0-rc.13",
4
4
  "type": "module",
5
5
  "productName": "GAIA Agent UI",
6
6
  "desktopName": "gaia-desktop.desktop",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@playwright/test": "1.65.1",
74
- "@testing-library/jest-dom": "^7.0.0",
74
+ "@testing-library/jest-dom": "^8.0.0",
75
75
  "@testing-library/react": "^16.1.0",
76
76
  "@testing-library/user-event": "^14.5.2",
77
77
  "@types/react": "^19.2.17",
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  /**
5
- * The dialog shown when GAIA's backend exits on its own. Every choice ends
5
+ * The dialog shown when GAIA's backend cannot recover after an exit or outage. Every choice ends
6
6
  * somewhere: Restart relaunches the app, Quit quits it, and Save diagnostics
7
7
  * writes the bundle and comes back to the same choice.
8
8
  */
@@ -19,8 +19,11 @@ function stripAnsi(text) {
19
19
  }
20
20
 
21
21
  /** The dialog's detail text: what happened, what to do, then the log tail. */
22
- function crashDetail(code, signal, tailLines) {
23
- const how = signal ? `signal ${signal}` : `exit code ${code}`;
22
+ function crashDetail(code, signal, tailLines, reason) {
23
+ let how;
24
+ if (signal) how = `signal ${signal}`;
25
+ else if (code !== null && code !== undefined) how = `exit code ${code}`;
26
+ else how = `last error: ${reason || "unknown cause"}`;
24
27
  const tail = (tailLines || []).map(stripAnsi).join("\n") || "(nothing was logged)";
25
28
  return (
26
29
  `GAIA's background service stopped unexpectedly (${how}). Your chats are saved.\n` +
@@ -50,8 +53,19 @@ function relaunchOptions(env = process.env, argv = process.argv) {
50
53
  * @param {object} [deps.parent] window the dialog is modal to, e.g. mainWindow
51
54
  * @returns {Promise<"restart"|"quit">}
52
55
  */
53
- async function showBackendCrashDialog({ dialog, app, code, signal, tailLines, writeDiagnostics, beforeQuit, env = process.env, parent }) {
54
- const detail = crashDetail(code, signal, tailLines);
56
+ async function showBackendCrashDialog({
57
+ dialog,
58
+ app,
59
+ code,
60
+ signal,
61
+ reason,
62
+ tailLines,
63
+ writeDiagnostics,
64
+ beforeQuit,
65
+ env = process.env,
66
+ parent,
67
+ }) {
68
+ const detail = crashDetail(code, signal, tailLines, reason);
55
69
  // Modal to GAIA's window and in front: unparented, it can open behind other apps.
56
70
  const owner = parent && !parent.isDestroyed() ? parent : null;
57
71
  if (owner) {