Skip to content

hermes update destroys Hermes Desktop executable on failed Electron rebuild (desktop shortcut becomes dead link) #44225

@leakey0412

Description

@leakey0412
问题描述

在 Windows 上,通过 Hermes Desktop GUI 点击「Update Now」触发 hermes update 后,如果 Electron 桌面应用重建失败,现有的 Hermes.exe 会被删除且无法恢复——桌面快捷方式成为死链,桌面图标消失。

复现步骤

1. 通过 hermes desktop 或快捷方式启动 Hermes Desktop(Electron 版)
2. 点击 Update Now(或通过后端 /api/hermes/update 触发 hermes update)
3. 更新流程:git pull → 检测到已有 Hermes Desktop → 自动运行 hermes desktop --build-only
4. electron-builder 的 before-pack.cjs 钩子(apps/desktop/scripts/before-pack.cjs)执行 fs.rmSync(appOutDir, { recursive: true, force: true }),删除 release/win-unpacked/ 目录(含 Hermes.exe)
5. 构建失败(常见原因:Electron 下载缓存损坏、网络代理导致下载超时等)
6. Hermes.exe 已被删除,新二进制未生成
7. 桌面快捷方式指向不存在的文件 → "桌面图标不见了"

根因

apps/desktop/scripts/before-pack.cjs 的 cleanStaleAppOutDir() 函数总是在 electron-builder 真正开始构建前清空旧的 appOutDir。这个设计是为了处理中断构建留下的脏数据——但如果构建失败,旧的可执行文件就丢了。

而在 hermes_cli/main.py 的 _cmd_update_impl()(~Line 8572)中,hermes update 在 git pull 后会无条件调用 hermes desktop --build-only 来自动重建桌面应用。没有回退机制。

受影响的代码

1. apps/desktop/scripts/before-pack.cjs — cleanStaleAppOutDir() 总是先删再建,没有失败回退
2. hermes_cli/main.py → _cmd_update_impl() — ~Line 8572,hermes update 阶段触发桌面重建,但重建前没有备份/恢复逻辑

建议修复方案

至少取其一:

A. 在 _cmd_update_impl 中加入备份/恢复(我已在本地应用)
构建前 shutil.copy2 备份已有的 Hermes.exe,构建失败时恢复。具体见 hermes_cli/main.py 中 _cmd_update_impl() 的 desktop rebuild 区块。

B. 让 before-pack.cjs 改为先备份再清理
在删除 appOutDir 前先备份关键可执行文件,构建完成后删除备份,失败时恢复。

C. 分离「更新 Hermes 源码」和「重建桌面应用」
hermes update 只更新 Python 后端和 Web UI,桌面应用由独立命令 hermes desktop --rebuild 控制,或默认不自动重建。



环境信息:
- Windows 10
- Hermes 源码安装(git checkout)
- Electron-builder 26.8.1
- Electron 40.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/cliCLI entry point, hermes_cli/, setup wizardtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions