The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): check Windows handoff files before stopping backends
Teknium6caf37b6bddc
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex ecbc3ebb716..d19a36b2e47 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -398,6 +398,7 @@ import {resolvePosixScriptHandoff,resolveStagedUpdaterBinary,resolveUpdateScriptHandoff,+ windowsUpdatePrerequisiteError,sandboxFallbackFromEnv,spawnUpdaterProcess,stagedUpdaterSupportsPrewrittenMarker,@@ -4049,6 +4050,14 @@ async function applyUpdates(opts: { stopSafeBlockers?: boolean } = {}) {// anything. Runs while the backend is still alive.preflightStateDb(HERMES_HOME, rememberLog)+ if (IS_WINDOWS && resolveUpdateScriptHandoff(updateRoot)) {+ const message = windowsUpdatePrerequisiteError(updateRoot)+ if (message) {+ emitUpdateProgress({ stage: 'error', message, percent: null })+ return { ok: false, error: message }+ }+ }+// Stop our own backend(s) and wait for the venv shim to unlock BEFORE we// spawn the updater. Without this the updater races a still-locked// hermes.exe (held by the backend child / its grandchildren) and the updatediff --git a/apps/desktop/electron/update-prerequisites.test.ts b/apps/desktop/electron/update-prerequisites.test.tsnew file mode 100644index 00000000000..791b1530cce--- /dev/null+++ b/apps/desktop/electron/update-prerequisites.test.ts@@ -0,0 +1,26 @@+import assert from 'node:assert/strict'+import { mkdtempSync, mkdirSync, writeFileSync, unlinkSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import path from 'node:path'+import { test } from 'vitest'+import { windowsUpdatePrerequisiteError } from './updater-process'++test('handoff prerequisites fail closed without requiring dependencies, shim or browser UI', () => {+ const root = mkdtempSync(path.join(tmpdir(), 'hermes-prerequisites-'))+ try {+ const python = path.join(root, 'venv', 'Scripts', 'python.exe')+ const script = path.join(root, 'scripts', 'desktop-update', 'windows.ps1')+ assert.match(windowsUpdatePrerequisiteError(root)!, /python.exe/)+ mkdirSync(path.dirname(python), { recursive: true })+ writeFileSync(python, 'file-presence fixture')+ assert.equal(windowsUpdatePrerequisiteError(root), null) // legacy flat layout+ mkdirSync(path.dirname(script), { recursive: true })+ assert.match(windowsUpdatePrerequisiteError(root)!, /windows.ps1/)+ writeFileSync(script, 'file-presence fixture')+ assert.equal(windowsUpdatePrerequisiteError(root), null)+ unlinkSync(python)+ assert.match(windowsUpdatePrerequisiteError(root)!, /python.exe/)+ } finally {+ rmSync(root, { recursive: true, force: true })+ }+})diff --git a/apps/desktop/electron/updater-process.ts b/apps/desktop/electron/updater-process.tsindex bb5e0a02c46..20db836d2d6 100644--- a/apps/desktop/electron/updater-process.ts+++ b/apps/desktop/electron/updater-process.ts@@ -1,9 +1,22 @@import { spawn, type SpawnOptions } from 'node:child_process'-import { statSync } from 'node:fs'+import { existsSync, statSync } from 'node:fs'import path from 'node:path'import { hiddenWindowsChildOptions } from './windows-child-options'+/** File prerequisites only: dependency recovery must remain reachable through update. */+export function windowsUpdatePrerequisiteError(updateRoot: string): string | null {+ const maintainedDir = path.join(updateRoot, 'scripts', 'desktop-update')+ const required = [path.join(updateRoot, 'venv', 'Scripts', 'python.exe')]+ // Pre-reorg flat scripts remain supported; damaged modern trees do not.+ if (existsSync(maintainedDir)) required.push(path.join(maintainedDir, 'windows.ps1'))+ for (const candidate of required) {+ if (stagedFileExists(candidate)) continue+ return `Update aborted: ${candidate} is missing or unreadable. Repair the installation and review antivirus quarantine before retrying.`+ }+ return null+}+export interface UpdaterChild {pid?: numberunref: () => void