前言¶
在 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。
資料中歸納的兩類症狀:
- 應用內更新無法完成安裝,日誌類似:
Host did not complete graceful task teardown
(exit null, signal SIGTERM, shutdown acknowledged true, graceful deadline exceeded true)
- 關窗後 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