@amd-gaia/agent-ui 0.25.4-rc.4 → 0.25.4-rc.7

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 (37) hide show
  1. package/dist/assets/AdvancedSettings-D1PbqQtF.js +1 -0
  2. package/dist/assets/ConnectorsPane-B_IM_sQZ.js +1 -0
  3. package/dist/assets/DocumentLibrary-OQGMKNkO.js +4 -0
  4. package/dist/assets/FileBrowser-dev5yv69.js +4 -0
  5. package/dist/assets/MemoryDashboard-DwrWAXi6.css +1 -0
  6. package/dist/assets/MemoryDashboard-Vz8OFC3_.js +1 -0
  7. package/dist/assets/MobileAccessModal-DpHtJVxo.js +2 -0
  8. package/dist/assets/ScheduleManager-BbmXSIUD.js +1 -0
  9. package/dist/assets/ScheduleManager-CjHJ4NbD.css +1 -0
  10. package/dist/assets/api-BsMIEtSA.js +4 -0
  11. package/dist/assets/index-CNhwlnjv.css +1 -0
  12. package/dist/assets/index-eGMUmm-L.js +78 -0
  13. package/dist/assets/useT-DmcuCJlO.js +3 -0
  14. package/dist/assets/zap-CORjwTA2.js +1 -0
  15. package/dist/index.html +4 -4
  16. package/dist/sw.js +1 -1
  17. package/main.cjs +8 -5
  18. package/package.json +1 -1
  19. package/preload.cjs +3 -0
  20. package/services/backend-installer.cjs +290 -21
  21. package/services/engine-install.cjs +100 -9
  22. package/services/lock-holders.cjs +200 -0
  23. package/services/quit-guard.cjs +17 -0
  24. package/dist/assets/AdvancedSettings-DoIDd09m.js +0 -1
  25. package/dist/assets/ConnectorsPane-CK3h7C7E.js +0 -1
  26. package/dist/assets/DocumentLibrary-BWvkvxTu.js +0 -4
  27. package/dist/assets/FileBrowser-DhqWGirJ.js +0 -4
  28. package/dist/assets/MemoryDashboard-BF-o8284.js +0 -1
  29. package/dist/assets/MemoryDashboard-Dt6zI60b.css +0 -1
  30. package/dist/assets/MobileAccessModal-51t2kQaJ.js +0 -2
  31. package/dist/assets/ScheduleManager-2xjZsnLK.js +0 -2
  32. package/dist/assets/ScheduleManager-D5c4gVIt.css +0 -1
  33. package/dist/assets/api-BzlFpP4T.js +0 -4
  34. package/dist/assets/apiBase-BMkGbdXt.js +0 -1
  35. package/dist/assets/index-C_Cx5IlD.css +0 -1
  36. package/dist/assets/index-hAcJijAU.js +0 -78
  37. package/dist/assets/zap-D7aLu_f0.js +0 -1
@@ -0,0 +1 @@
1
+ import{W as e}from"./useT-DmcuCJlO.js";var t={name:`message-square`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]};t.node;var n=e(t),r={name:`zap`,size:24,node:[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]};r.node;var i=e(r);export{n,i as t};
package/dist/index.html CHANGED
@@ -12,11 +12,11 @@
12
12
  <meta name="apple-mobile-web-app-capable" content="yes" />
13
13
  <meta name="apple-mobile-web-app-title" content="GAIA" />
14
14
  <title>GAIA Agent UI</title>
15
- <script type="module" crossorigin src="./assets/index-hAcJijAU.js"></script>
15
+ <script type="module" crossorigin src="./assets/index-eGMUmm-L.js"></script>
16
16
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-XKyaHtl9.js">
17
- <link rel="modulepreload" crossorigin href="./assets/apiBase-BMkGbdXt.js">
18
- <link rel="modulepreload" crossorigin href="./assets/api-BzlFpP4T.js">
19
- <link rel="stylesheet" crossorigin href="./assets/index-C_Cx5IlD.css">
17
+ <link rel="modulepreload" crossorigin href="./assets/useT-DmcuCJlO.js">
18
+ <link rel="modulepreload" crossorigin href="./assets/api-BsMIEtSA.js">
19
+ <link rel="stylesheet" crossorigin href="./assets/index-CNhwlnjv.css">
20
20
  </head>
21
21
  <body>
22
22
  <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.25.4rc4-518e97fcc849b823';
12
+ const CACHE_NAME = CACHE_PREFIX + '0.25.4rc7-5bfd5826c9744ded';
13
13
  const ASSETS_PATH = new URL('assets/', self.registration.scope).pathname;
14
14
 
15
15
  self.addEventListener('install', () => {
package/main.cjs CHANGED
@@ -92,6 +92,7 @@ const {
92
92
  fetchWorkInProgress,
93
93
  installQuitGuard,
94
94
  QUIT,
95
+ quitOnTermSignal,
95
96
  RESTART_FOR_UPDATE,
96
97
  } = require("./services/quit-guard.cjs");
97
98
  const AgentProcessManager = require("./services/agent-process-manager.cjs");
@@ -1186,7 +1187,7 @@ app.whenReady().then(async () => {
1186
1187
  if (showingInstallScreen) {
1187
1188
  const installed = await engineInstall.run();
1188
1189
  if (!installed) {
1189
- console.log("[main] Quit while the install waited on Try again");
1190
+ console.log("[main] Quit during the backend install");
1190
1191
  return;
1191
1192
  }
1192
1193
  engineInstall.starting();
@@ -1338,11 +1339,13 @@ const quitGuard = installQuitGuard({
1338
1339
  },
1339
1340
  });
1340
1341
 
1342
+ quitOnTermSignal({ proc: process, app, guard: quitGuard });
1343
+
1341
1344
  installQuitCleanup({ app, cleanup });
1342
1345
 
1343
1346
  async function cleanup() {
1344
1347
  shutdownStarted = true;
1345
- if (engineInstall) engineInstall.stop();
1348
+ const installStopped = engineInstall ? engineInstall.stop() : null;
1346
1349
 
1347
1350
  // Phase F: tear down auto-updater timers and IPC handlers.
1348
1351
  try {
@@ -1365,9 +1368,9 @@ async function cleanup() {
1365
1368
  keepAwake = null;
1366
1369
  }
1367
1370
 
1368
- // The agents and the backend stop side by side: each waits out its own
1369
- // grace period, and in series they could overrun the quit's time limit.
1370
- await Promise.all([stopAgentsForQuit(), stopBackendForQuit()]);
1371
+ // The install, the agents and the backend stop side by side: each waits out
1372
+ // its own grace period, and in series they could overrun the quit's time limit.
1373
+ await Promise.all([installStopped, stopAgentsForQuit(), stopBackendForQuit()]);
1371
1374
 
1372
1375
  // Destroy tray icon
1373
1376
  if (trayManager) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amd-gaia/agent-ui",
3
- "version": "0.25.4-rc.4",
3
+ "version": "0.25.4-rc.7",
4
4
  "type": "module",
5
5
  "productName": "GAIA Agent UI",
6
6
  "description": "Chat with the GAIA agent - local and private by default on AMD Ryzen AI, cloud models when you choose them",
package/preload.cjs CHANGED
@@ -123,6 +123,9 @@ contextBridge.exposeInMainWorld("gaiaInstall", {
123
123
  // After a failed update, go back to the version before it; the app restarts into it.
124
124
  revert: () => ipcRenderer.invoke("install:revert"),
125
125
 
126
+ // After a 'locked' failure held only by GAIA processes: ends those and installs again.
127
+ closeLockingPrograms: () => ipcRenderer.invoke("install:close-lockers"),
128
+
126
129
  // Open the log file in the OS's default viewer.
127
130
  openLogFile: () => ipcRenderer.invoke("install:open-log-file"),
128
131
  });
@@ -17,6 +17,7 @@
17
17
  * - installBackend(opts) → Promise<void>
18
18
  * - ensureBackend(opts) → Promise<string> (returns gaia bin path)
19
19
  * - isBackendCurrent() → boolean (nothing to install or refresh)
20
+ * - stopRunningDaemon(opts) → Promise<void> (before the venv is touched)
20
21
  * - getInstalledVersion(gaiaBin) → string | null
21
22
  * - findGaiaBin() → string | null
22
23
  * - getState() / setState() → state machine helpers
@@ -150,8 +151,16 @@ const FAILURE_REASONS = Object.freeze({
150
151
  NETWORK: "network",
151
152
  TLS: "tls",
152
153
  LOCKED: "locked",
154
+ DAEMON: "daemon",
153
155
  });
154
156
 
157
+ // `gaia daemon stop` can take about 90 s: up to 45 s for a graceful exit, then
158
+ // terminating the daemon and its agents, then up to 20 s for GAIA's Lemonade Server.
159
+ const DAEMON_STOP_TIMEOUT_MS = 120 * 1000;
160
+ /** `gaia daemon stop` exit code: the daemon stopped, GAIA's Lemonade Server did not. */
161
+ const DAEMON_STOP_LEMONADE_EXIT = 3;
162
+ const DAEMON_INSTANCE_FILE = path.join(GAIA_HOME, "host", "instance.json");
163
+
155
164
  // Stage an older installer recorded while it ran `gaia init`; the package was
156
165
  // already in place by then.
157
166
  const LEGACY_SETUP_STAGE = "gaia-init";
@@ -459,9 +468,13 @@ function findGaiaBin() {
459
468
  *
460
469
  * `onLine(line)` sees each whole stdout line as it arrives; a line it returns
461
470
  * true for is left out of the log.
471
+ *
472
+ * When `signal` aborts, the child and everything it started are stopped and
473
+ * the Promise rejects with InstallCancelled once they are gone.
462
474
  */
463
- function runCommand(cmd, args, { env, stageLabel, onLine } = {}) {
464
- return new Promise((resolve) => {
475
+ function runCommand(cmd, args, { env, stageLabel, onLine, signal, timeoutMs } = {}) {
476
+ if (signal && signal.aborted) return Promise.reject(new InstallCancelled());
477
+ return new Promise((resolve, reject) => {
465
478
  log(`$ ${cmd} ${args.join(" ")}`);
466
479
  let proc;
467
480
  try {
@@ -478,6 +491,21 @@ function runCommand(cmd, args, { env, stageLabel, onLine } = {}) {
478
491
  return;
479
492
  }
480
493
 
494
+ let stopping = false;
495
+ const onAbort = () => {
496
+ stopping = true;
497
+ stopTimer();
498
+ log(`Stopping ${cmd}: GAIA is quitting`);
499
+ require("./process-tree.cjs")
500
+ .killProcessTree(proc, { label: stageLabel || cmd, log, logError })
501
+ .then(() => reject(new InstallCancelled()), reject);
502
+ };
503
+ if (signal) signal.addEventListener("abort", onAbort, { once: true });
504
+ const finish = (result) => {
505
+ if (signal) signal.removeEventListener("abort", onAbort);
506
+ if (!stopping) resolve(result);
507
+ };
508
+
481
509
  let stdout = "";
482
510
  let stderr = "";
483
511
  let partial = "";
@@ -525,18 +553,123 @@ function runCommand(cmd, args, { env, stageLabel, onLine } = {}) {
525
553
  });
526
554
  });
527
555
 
556
+ // From `timers`, not the globals: the installer tests run this file in a bare vm context.
557
+ let timer = null;
558
+ if (timeoutMs) {
559
+ timer = require("timers").setTimeout(() => {
560
+ logError(`${cmd} ${args.join(" ")} did not finish within ${Math.round(timeoutMs / 1000)}s — ending it`);
561
+ killTree(proc);
562
+ finish({ code: null, stdout, stderr, timedOut: true });
563
+ }, timeoutMs);
564
+ }
565
+ const stopTimer = () => {
566
+ if (timer) require("timers").clearTimeout(timer);
567
+ };
568
+
528
569
  proc.on("error", (err) => {
570
+ stopTimer();
529
571
  logError(`${cmd} error: ${err.message}`);
530
- resolve({ code: -1, stdout, stderr, error: err });
572
+ finish({ code: -1, stdout, stderr, error: err });
531
573
  });
532
574
 
533
575
  proc.on("exit", (code) => {
576
+ stopTimer();
534
577
  log(` exit code: ${code}`);
535
- resolve({ code, stdout, stderr });
578
+ finish({ code, stdout, stderr });
536
579
  });
537
580
  });
538
581
  }
539
582
 
583
+ /** End `proc` and what it started: a Windows venv launcher runs Python as a child. */
584
+ function killTree(proc) {
585
+ if (IS_WINDOWS) {
586
+ const r = spawnSync("taskkill", ["/PID", String(proc.pid), "/T", "/F"], {
587
+ windowsHide: true,
588
+ timeout: 30 * 1000,
589
+ });
590
+ if (r.error || r.status !== 0) {
591
+ logError(`taskkill /PID ${proc.pid} /T /F failed: ${r.error ? r.error.message : `exit ${r.status}`}`);
592
+ }
593
+ return;
594
+ }
595
+ try {
596
+ proc.kill("SIGKILL");
597
+ } catch (err) {
598
+ logError(`Could not end pid ${proc.pid}: ${err.message}`);
599
+ }
600
+ }
601
+
602
+ /** The pid of the GAIA daemon ~/.gaia/host/instance.json records, when that process is alive. */
603
+ function liveDaemonPid() {
604
+ let pid;
605
+ try {
606
+ pid = Number(JSON.parse(fs.readFileSync(DAEMON_INSTANCE_FILE, "utf8")).pid);
607
+ } catch (err) {
608
+ if (err.code !== "ENOENT") log(`Could not read ${DAEMON_INSTANCE_FILE}: ${err.message}`);
609
+ return null;
610
+ }
611
+ if (!Number.isInteger(pid) || pid <= 0) return null;
612
+ try {
613
+ process.kill(pid, 0);
614
+ return pid;
615
+ } catch (err) {
616
+ // EPERM: the process exists but belongs to someone else.
617
+ return err.code === "EPERM" ? pid : null;
618
+ }
619
+ }
620
+
621
+ /**
622
+ * Stop the GAIA daemon (and the agents it runs) that the existing venv may be
623
+ * running, so the install doesn't trip over its open files. Throws an
624
+ * InstallError naming the daemon only when one is still alive afterwards: a
625
+ * stop that fails with no daemon running (a broken venv, say) must not block
626
+ * the reinstall that repairs it.
627
+ */
628
+ async function stopRunningDaemon({ timeoutMs = DAEMON_STOP_TIMEOUT_MS, signal } = {}) {
629
+ if (!fs.existsSync(GAIA_BIN) || !fs.existsSync(GAIA_PYTHON_BIN)) return;
630
+ const result = await runCommand(GAIA_BIN, ["daemon", "stop"], {
631
+ stageLabel: "daemon",
632
+ timeoutMs,
633
+ signal,
634
+ // gaia prints emoji, which a Windows pipe's code page can't encode.
635
+ env: { ...process.env, PYTHONIOENCODING: "utf-8" },
636
+ });
637
+ if (result.code === 0) return;
638
+ const output = `${result.stdout || ""}\n${result.stderr || ""}`;
639
+ if (result.code === 2 && /invalid choice: '?daemon'?/.test(output)) {
640
+ log("The installed GAIA predates the daemon — nothing to stop");
641
+ return;
642
+ }
643
+ const pid = liveDaemonPid();
644
+ if (pid === null) {
645
+ if (result.code === DAEMON_STOP_LEMONADE_EXIT) {
646
+ log(
647
+ "The GAIA daemon stopped, but GAIA's Lemonade Server did not (see the lines above). " +
648
+ "It lives outside the backend's files, so the install goes on."
649
+ );
650
+ } else {
651
+ log(
652
+ `gaia daemon stop ${result.timedOut ? "timed out" : `exited ${result.code}`}, ` +
653
+ "but no GAIA daemon is running — continuing"
654
+ );
655
+ }
656
+ return;
657
+ }
658
+ const why = result.timedOut
659
+ ? `did not stop within ${Math.round(timeoutMs / 1000)} seconds`
660
+ : `could not be stopped (gaia daemon stop exit ${result.code})`;
661
+ log(`To stop it by hand: ${GAIA_BIN} daemon stop`);
662
+ throw new InstallError(
663
+ `GAIA's background service (the GAIA daemon, pid ${pid}) ${why}, so its files can't be updated.`,
664
+ {
665
+ stage: STAGES.CREATE_VENV,
666
+ code: result.code,
667
+ reason: FAILURE_REASONS.DAEMON,
668
+ suggestion: `It has no window to close. Restart your PC, then try again. The log at ${LOG_FILE} has the details.`,
669
+ }
670
+ );
671
+ }
672
+
540
673
  /**
541
674
  * Detect the Windows "file in use" signature in command output. An upgrade's
542
675
  * `uv pip install --refresh` can't replace gaia.exe while a previous GAIA
@@ -547,6 +680,91 @@ function isFileLockedError(output) {
547
680
  return /os error 32/i.test(output) || /being used by another process/i.test(output);
548
681
  }
549
682
 
683
+ /** The files uv could not replace, as absolute paths, in the order it named them. */
684
+ function lockedFiles(output) {
685
+ const files = [];
686
+ for (const m of String(output || "").matchAll(/failed to \w+ (?:file|directory) `([^`]+)`/gi)) {
687
+ const file = path.resolve(m[1]);
688
+ if (!files.includes(file)) files.push(file);
689
+ }
690
+ return files;
691
+ }
692
+
693
+ const MOVED_ASIDE_SUFFIX = /\.old-\d+$/i;
694
+
695
+ function sameFile(a, b) {
696
+ return path.resolve(a).toLowerCase() === path.resolve(b).toLowerCase();
697
+ }
698
+
699
+ /**
700
+ * Rename each locked launcher in the venv's Scripts folder to <name>.old-<ts>
701
+ * so uv can write a fresh one (#6570). A launcher something is running can't
702
+ * be renamed; it is left alone. Returns [{ file, aside }] for those moved.
703
+ */
704
+ function moveLockedAside(files) {
705
+ const scripts = path.join(GAIA_VENV, "Scripts");
706
+ const stamp = Date.now();
707
+ const moved = [];
708
+ for (const file of files) {
709
+ if (!/\.exe$/i.test(file) || !sameFile(path.dirname(file), scripts)) continue;
710
+ const aside = `${file}.old-${stamp}`;
711
+ try {
712
+ fs.renameSync(file, aside);
713
+ moved.push({ file, aside });
714
+ log(`Moved locked ${file} aside to ${path.basename(aside)}`);
715
+ } catch (err) {
716
+ log(`Could not move locked ${file} aside (${err.code || err.message}); it stays where it is`);
717
+ }
718
+ }
719
+ return moved;
720
+ }
721
+
722
+ /** Put back every moved launcher uv did not replace, so a failed upgrade leaves the venv whole. */
723
+ function putBackUnreplaced(moved) {
724
+ for (const { file, aside } of moved) {
725
+ if (fs.existsSync(file)) {
726
+ log(`${path.basename(file)} was reinstalled; ${path.basename(aside)} is deleted on a later install`);
727
+ continue;
728
+ }
729
+ try {
730
+ fs.renameSync(aside, file);
731
+ } catch (err) {
732
+ throw new Error(`Could not put ${aside} back at ${file}: ${err.message}`);
733
+ }
734
+ log(`Put ${path.basename(file)} back from ${path.basename(aside)}`);
735
+ }
736
+ }
737
+
738
+ /**
739
+ * Tidy what an earlier upgrade moved aside. A .old file whose original was
740
+ * reinstalled is deleted unless still in use; one whose original is missing
741
+ * is put back, newest first.
742
+ */
743
+ function removeMovedLaunchers() {
744
+ const dir = path.join(GAIA_VENV, "Scripts");
745
+ const stampOf = (name) => Number(/\.old-(\d+)$/i.exec(name)[1]);
746
+ const leftovers = listDir(dir)
747
+ .filter((name) => MOVED_ASIDE_SUFFIX.test(name))
748
+ .sort((a, b) => stampOf(b) - stampOf(a));
749
+ for (const name of leftovers) {
750
+ const aside = path.join(dir, name);
751
+ const file = aside.replace(MOVED_ASIDE_SUFFIX, "");
752
+ if (!fs.existsSync(file)) {
753
+ fs.renameSync(aside, file);
754
+ log(`Put ${path.basename(file)} back from ${name}: no newer copy was installed`);
755
+ continue;
756
+ }
757
+ try {
758
+ fs.unlinkSync(aside);
759
+ log(`Removed ${aside}, moved aside by an earlier upgrade`);
760
+ } catch (err) {
761
+ // Windows refuses to delete a program that is running (EPERM) or open (EBUSY).
762
+ if (err.code !== "EBUSY" && err.code !== "EPERM") throw err;
763
+ log(`Left ${aside} in place: it is still in use (${err.code})`);
764
+ }
765
+ }
766
+ }
767
+
550
768
  /**
551
769
  * Detect a transient network failure in `uv pip install` output so the
552
770
  * install stage can retry instead of failing the whole bootstrap. The
@@ -956,13 +1174,23 @@ async function runPreChecks(opts = {}) {
956
1174
  // ── uv install ───────────────────────────────────────────────────────────────
957
1175
 
958
1176
  class InstallError extends Error {
959
- constructor(message, { stage, code, suggestion, reason } = {}) {
1177
+ constructor(message, { stage, code, suggestion, reason, lockedFiles } = {}) {
960
1178
  super(message);
961
1179
  this.name = "InstallError";
962
1180
  this.stage = stage || null;
963
1181
  this.code = code || null;
964
1182
  this.suggestion = suggestion || null;
965
1183
  this.reason = reason || null;
1184
+ // The files another program held open, for main to find who holds them.
1185
+ this.lockedFiles = lockedFiles || null;
1186
+ }
1187
+ }
1188
+
1189
+ /** The caller's signal stopped the install: the app is quitting, nothing failed. */
1190
+ class InstallCancelled extends Error {
1191
+ constructor() {
1192
+ super("The install stopped because GAIA is quitting; it continues on the next launch.");
1193
+ this.name = "InstallCancelled";
966
1194
  }
967
1195
  }
968
1196
 
@@ -1190,7 +1418,7 @@ function addManagedBinToPath() {
1190
1418
  *
1191
1419
  * Throws InstallError on failure.
1192
1420
  */
1193
- async function ensureUv({ onProgress, isPackaged } = {}) {
1421
+ async function ensureUv({ onProgress, isPackaged, signal } = {}) {
1194
1422
  const report = makeProgressReporter(onProgress);
1195
1423
  report(STAGES.ENSURE_UV, 0, "Checking uv (Python package manager)");
1196
1424
 
@@ -1289,13 +1517,13 @@ async function ensureUv({ onProgress, isPackaged } = {}) {
1289
1517
  "-Command",
1290
1518
  "irm https://astral.sh/uv/install.ps1 | iex",
1291
1519
  ],
1292
- { stageLabel: "uv-install-dev" }
1520
+ { stageLabel: "uv-install-dev", signal }
1293
1521
  );
1294
1522
  } else {
1295
1523
  result = await runCommand(
1296
1524
  "bash",
1297
1525
  ["-c", "curl -LsSf https://astral.sh/uv/install.sh | sh"],
1298
- { stageLabel: "uv-install-dev" }
1526
+ { stageLabel: "uv-install-dev", signal }
1299
1527
  );
1300
1528
  }
1301
1529
 
@@ -1356,7 +1584,7 @@ async function ensureUv({ onProgress, isPackaged } = {}) {
1356
1584
  "-Command",
1357
1585
  "irm https://astral.sh/uv/install.ps1 | iex",
1358
1586
  ],
1359
- { stageLabel: "uv-install-packaged-rescue" }
1587
+ { stageLabel: "uv-install-packaged-rescue", signal }
1360
1588
  );
1361
1589
  if (rescue.code === 0) {
1362
1590
  // Ensure common install locations are present on PATH for this
@@ -1382,6 +1610,7 @@ async function ensureUv({ onProgress, isPackaged } = {}) {
1382
1610
  log(`Packaged Windows: automated uv installer exited ${rescue.code}`);
1383
1611
  }
1384
1612
  } catch (rescueErr) {
1613
+ if (rescueErr instanceof InstallCancelled) throw rescueErr;
1385
1614
  log(`Packaged Windows: rescue installer threw: ${rescueErr.message}`);
1386
1615
  }
1387
1616
  }
@@ -1483,13 +1712,14 @@ async function installBackend(opts = {}) {
1483
1712
  setState(STATES.INSTALLING, { stage: STAGES.ENSURE_UV, version });
1484
1713
 
1485
1714
  // Stage 1: ensure uv
1486
- await ensureUv({ onProgress: opts.onProgress, isPackaged: opts.isPackaged });
1715
+ await ensureUv({ onProgress: opts.onProgress, isPackaged: opts.isPackaged, signal: opts.signal });
1487
1716
 
1488
1717
  // Stage 2: create venv
1489
1718
  setState(STATES.INSTALLING, { stage: STAGES.CREATE_VENV, version });
1490
1719
  report(STAGES.CREATE_VENV, 0, "Creating Python 3.12 environment");
1491
1720
 
1492
1721
  ensureGaiaHome();
1722
+ await stopRunningDaemon({ signal: opts.signal });
1493
1723
 
1494
1724
  // If the venv exists but the python binary is missing, treat as partial.
1495
1725
  const venvLooksValid =
@@ -1506,7 +1736,7 @@ async function installBackend(opts = {}) {
1506
1736
  }
1507
1737
 
1508
1738
  const venvArgs = ["venv", GAIA_VENV, "--python", "3.12"];
1509
- let venvResult = await runCommand("uv", venvArgs, { stageLabel: "venv" });
1739
+ let venvResult = await runCommand("uv", venvArgs, { stageLabel: "venv", signal: opts.signal });
1510
1740
  // uv downloads Python 3.12 when none is installed; behind a corporate
1511
1741
  // proxy that fails on uv's bundled roots exactly like the pip step below.
1512
1742
  let venvNativeTls = false;
@@ -1529,6 +1759,7 @@ async function installBackend(opts = {}) {
1529
1759
  }
1530
1760
  venvResult = await runCommand("uv", [...venvArgs, "--native-tls"], {
1531
1761
  stageLabel: "venv",
1762
+ signal: opts.signal,
1532
1763
  });
1533
1764
  }
1534
1765
  if (venvResult.code !== 0) {
@@ -1553,6 +1784,7 @@ async function installBackend(opts = {}) {
1553
1784
  // Stage 3: pip install
1554
1785
  setState(STATES.INSTALLING, { stage: STAGES.INSTALL_PACKAGE, version });
1555
1786
  report(STAGES.INSTALL_PACKAGE, 0, `Installing ${pipPackage}`);
1787
+ if (IS_WINDOWS) removeMovedLaunchers();
1556
1788
 
1557
1789
  const pipArgs = [
1558
1790
  "pip",
@@ -1568,14 +1800,14 @@ async function installBackend(opts = {}) {
1568
1800
  // deps (numpy, faiss, pypdfium2, …) are fetched live from PyPI even
1569
1801
  // when the gaia wheel itself is local, so a single broken-pipe mid-download
1570
1802
  // would otherwise fail the whole bootstrap (and block a release). File-lock
1571
- // failures (Windows os-error-32) are NOT retried — they need user action.
1803
+ // failures (Windows os-error-32) get their own single retry after this loop.
1572
1804
  let installResult;
1573
1805
  if (!localWheel && isBackendPrefetched(version)) {
1574
1806
  report(STAGES.INSTALL_PACKAGE, 0, `Installing ${pipPackage} from the downloaded update`);
1575
1807
  const offline = await runCommand(
1576
1808
  "uv",
1577
1809
  ["pip", "install", pipPackage, "--offline", "--compile-bytecode", "--python", GAIA_PYTHON_BIN],
1578
- { stageLabel: "pip" }
1810
+ { stageLabel: "pip", signal: opts.signal }
1579
1811
  );
1580
1812
  fs.rmSync(_prefetchMarker(toPep440(version)), { force: true });
1581
1813
  if (offline.code === 0) {
@@ -1597,7 +1829,7 @@ async function installBackend(opts = {}) {
1597
1829
  ) {
1598
1830
  const attemptArgs = useNativeTls ? [...pipArgs, "--native-tls"] : pipArgs;
1599
1831
  if (useNativeTls) nativeTlsAttempted = true;
1600
- installResult = await runCommand("uv", attemptArgs, { stageLabel: "pip" });
1832
+ installResult = await runCommand("uv", attemptArgs, { stageLabel: "pip", signal: opts.signal });
1601
1833
  if (installResult.code === 0) break;
1602
1834
  const attemptOutput = `${installResult.stdout || ""}\n${installResult.stderr || ""}`;
1603
1835
  // A corporate proxy's custom root CA isn't in uv's bundled webpki roots, so
@@ -1634,16 +1866,41 @@ async function installBackend(opts = {}) {
1634
1866
  );
1635
1867
  await sleep(backoffMs);
1636
1868
  }
1869
+ // A launcher that is only open, not running, can be renamed out of uv's way (#6570).
1870
+ const firstOutput = `${installResult.stdout || ""}\n${installResult.stderr || ""}`;
1871
+ if (IS_WINDOWS && installResult.code !== 0 && isFileLockedError(firstOutput)) {
1872
+ const moved = moveLockedAside(lockedFiles(firstOutput));
1873
+ if (moved.length > 0) {
1874
+ report(STAGES.INSTALL_PACKAGE, 0, "Another program has GAIA's files open — retrying the install");
1875
+ try {
1876
+ installResult = await runCommand("uv", useNativeTls ? [...pipArgs, "--native-tls"] : pipArgs, {
1877
+ stageLabel: "pip",
1878
+ signal: opts.signal,
1879
+ });
1880
+ } finally {
1881
+ putBackUnreplaced(moved);
1882
+ }
1883
+ }
1884
+ }
1637
1885
  if (installResult.code !== 0) {
1638
- // Windows: an upgrade can't replace gaia.exe while a previous GAIA
1639
- // process still holds it open (issue #1388). The orphan cleanup in
1640
- // main.cjs should have killed it first; if the lock persists, point the
1641
- // user at the live process rather than the generic manual-install hint.
1642
1886
  const output = `${installResult.stdout || ""}\n${installResult.stderr || ""}`;
1643
1887
  let suggestion;
1644
1888
  if (isFileLockedError(output)) {
1645
- suggestion =
1646
- "A running GAIA process is locking the install. Close GAIA completely (including any leftover gaia.exe in Task Manager), then relaunch.";
1889
+ // pip's own line is already in the log, which the setup screen's details show.
1890
+ const files = lockedFiles(output);
1891
+ const names = files.map((file) => path.basename(file)).join(", ");
1892
+ throw new InstallError(
1893
+ `GAIA couldn't replace its own files because another program has them open${names ? ` (${names})` : ""}.`,
1894
+ {
1895
+ stage: STAGES.INSTALL_PACKAGE,
1896
+ code: installResult.code,
1897
+ reason: FAILURE_REASONS.LOCKED,
1898
+ lockedFiles: files,
1899
+ suggestion:
1900
+ "Close other GAIA apps and any terminal running gaia, or restart your PC, then try again. " +
1901
+ `The log at ${LOG_FILE} names the file.`,
1902
+ }
1903
+ );
1647
1904
  } else if (isTlsCertError(output)) {
1648
1905
  suggestion =
1649
1906
  "PyPI's certificate isn't trusted on this network — usually a corporate proxy presenting its own root CA. " +
@@ -1782,6 +2039,7 @@ async function refreshAgent(gaiaBin, opts = {}) {
1782
2039
  const result = await runCommand(gaiaBin, ["init", "--agent-only"], {
1783
2040
  stageLabel: "agent",
1784
2041
  env: { ...process.env, COLUMNS: "1000" },
2042
+ signal: opts.signal,
1785
2043
  });
1786
2044
  const lastLine = `${result.stderr || ""}`.trim().split(/\r?\n/).pop();
1787
2045
  if (result.code === AGENT_KEPT_EXIT) {
@@ -1961,8 +2219,11 @@ function venvPackageVersion() {
1961
2219
  * - version: override the pinned version
1962
2220
  * - allowPartialRestart: bool (default true) — restart from scratch if
1963
2221
  * the state file indicates a `partial` install.
2222
+ * - signal: AbortSignal — stops the running step (the app is quitting)
1964
2223
  *
1965
- * Throws InstallError on failure and updates the state file.
2224
+ * Throws InstallError on failure and updates the state file. Throws
2225
+ * InstallCancelled when `signal` stopped it; the state file then still says
2226
+ * installing, so the next launch runs the install again.
1966
2227
  */
1967
2228
  async function ensureBackend(opts = {}) {
1968
2229
  openLog({ truncate: true });
@@ -2098,6 +2359,10 @@ async function ensureBackend(opts = {}) {
2098
2359
  await refreshAgent(verified, opts);
2099
2360
  return verified;
2100
2361
  } catch (err) {
2362
+ if (err instanceof InstallCancelled) {
2363
+ log(err.message);
2364
+ throw err;
2365
+ }
2101
2366
  if (err instanceof InstallError) {
2102
2367
  setState(STATES.FAILED, {
2103
2368
  stage: err.stage || null,
@@ -2129,6 +2394,7 @@ module.exports = {
2129
2394
  getInstalledVersion,
2130
2395
  findGaiaBin,
2131
2396
  toPep440,
2397
+ stopRunningDaemon,
2132
2398
 
2133
2399
  // Pre-checks
2134
2400
  runPreChecks,
@@ -2162,6 +2428,8 @@ module.exports = {
2162
2428
  STATES,
2163
2429
  STAGES,
2164
2430
  FAILURE_REASONS,
2431
+ DAEMON_STOP_TIMEOUT_MS,
2432
+ DAEMON_STOP_LEMONADE_EXIT,
2165
2433
  GAIA_HOME,
2166
2434
  GAIA_VENV,
2167
2435
  GAIA_BIN,
@@ -2169,4 +2437,5 @@ module.exports = {
2169
2437
 
2170
2438
  // Error
2171
2439
  InstallError,
2440
+ InstallCancelled,
2172
2441
  };