dsh-desktop-clean-exit: Fix DSH Desktop Host Unable to Exit Gracefully

前言

在 DSH 桌面端上,应用内更新有时会在 Host 侧卡住:提示「Host did not complete graceful task teardown」,手动安装同一版本却往往可以成功。另一常见现象是关闭窗口后,Host 进程还要占住 10–15 秒才被系统结束。二者同源,都出在桌面壳与 Host 之间的退出握手机制,而不是安装包本身损坏。社区插件 dsh-desktop-clean-exit(维护者 Genesis-ly,分类:客户端)针对这一上游缺陷,在 Host 完成 teardown 并发出 shutdown-complete 之后,显式结束进程,从而恢复应用内更新并缩短退出等待。下面介绍其背景、做法与安装验证方式。

这是什么

dsh-desktop-clean-exit 是面向 DSH 桌面 Host 的 Cordis 补丁型插件(link: bundle),不改官方发行文件,桌面升级后仍可沿用。它不替代安装器,只修补 Host 在优雅退出阶段未调用 process.exit() 的行为,使壳层要求的「10 秒内 exit code 0 且收到 shutdown-complete」能够成立。

现象与根因(资料所述)

桌面壳会先等 Host 自行退出(约 10 秒),再发 SIGTERM,必要时 SIGKILL;应用内更新还要求在时限内以 0 退出并确认收到 shutdown-complete。

资料中归纳的两类症状:

  1. 应用内更新无法完成安装,日志类似:
   Host did not complete graceful task teardown
   (exit null, signal SIGTERM, shutdown acknowledged true, graceful deadline exceeded true)
  1. 关窗后 Host 仍存活 10–15 秒,最终被强制结束。

根因简述:Host 在 teardown 后已发送 shutdown-complete、断开 IPC,但未调用 process.exit();profile-boot 仅设置 exitCode 并依赖事件循环排空。若仍有 native FFI 管道、插件定时器、文件监视、MCP stdio 子进程、PTY 等句柄引用,循环无法结束,握手必然落到 SIGTERM,与上述报错一致。更完整说明见仓库文档 docs/bugs/01-desktop-update-host-never-exits.md。

核心功能

插件在 Host 发出 shutdown-complete 之后增加显式退出逻辑(实现于 bundle,不直接改官方文件):

setTimeout(() => process.exit(0), 150).unref()

含义(据 README):teardown 已完成;unref 的定时器在事件循环能自然排空时不会拖住进程,仅在仍有遗留句柄时才在约 150 ms 后以 0 退出。

仓库另附带 Windows 下的隔离探针 scripts/host-exit-probe.mjs,用于复现与验证修复(需设置 DSH_ROOT 指向 DSH 安装目录)。探针会写入 desktop-clean-exit.state.json,记录 phase、pid、connected、resources、code 等字段。

安装与启用

安装前请完全退出 DSH。官方流程使用仓库内 PowerShell 脚本,而非凭名称拼接 dsh plugin add github:...。

在仓库根目录执行(将路径换成你的安装位置):

# From this repository root, with DSH fully quit.
.\scripts\install.ps1 -DshRoot 'C:\path\to\DeepSeek Harness'
# or: $env:DSH_ROOT = '...'; .\scripts\install.ps1

脚本会:将包复制到 %USERPROFILE%\.dsh\plugins\dsh-desktop-clean-exit;通过 dsh plugin --profile desktop add "link:<path>" 安装;确保 dsh.profile.bundles 包含该插件;并将 package.json 备份为 package.json.bak-install。

回滚与状态检查:

.\scripts\rollback-clean-exit.ps1
.\scripts\verify-clean-exit.ps1

典型用法与自检

语法检查(仓库内):

npm run check   # node --check lib/index.js

README 说明无独立单元测试套件,退出行为主要依赖下面的探针(仅 Windows;DSH_ROOT 须指向安装目录):

$env:DSH_ROOT = 'C:\path\to\DeepSeek Harness'
node scripts\host-exit-probe.mjs leak    # reproduces: Host alive after 10 s
node scripts\host-exit-probe.mjs both    # fixed: exit 0 in ~0.25 s
node scripts\host-exit-probe.mjs clean   # no regression: exit 0 in ~0.1 s

package.json 中插件版本为 0.2.0,引擎要求为 dsh:>=0.2.1-rc.3 <0.3.0;README 注明在 DSH 0.2.2-rc.5(0.2.2-rc.3 具相同 Host 代码)、Windows 10/11、Node >= 20 下验证。许可证为 MIT。

适用场景与注意

适合在 DSH 桌面端(Windows) 上频繁使用应用内更新,或无法忍受关窗后 Host 长时间占位的开发者。插件以当前 dsh 进程权限运行,安装前应阅读仓库源码、LICENSE 与 SECURITY.md,并理解 link: bundle 会加载 cordis.patch.yml 对 Host 行为打补丁。

社区目录 skillhub.cn 上的插件页 与 GitHub 仓库相互独立索引;DSH 生态强调「一切皆插件」,该目录站与 DeepSeek / 幻方无官方从属关系,本文也不将其表述为官方应用商店。

结尾

若你卡在桌面端「Host did not complete graceful task teardown」或退出迟滞,可先按官方 install.ps1 安装 dsh-desktop-clean-exit,再用 host-exit-probe.mjs 对照 README 中的 leak / both / clean 结果。更多信息见目录页与源码仓库:

  • 目录页:https://www.skillhub.cn/plugins/Genesis-ly/dsh-desktop-clean-exit
  • GitHub:https://github.com/Genesis-ly/dsh-desktop-clean-exit
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye