You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dsh web burns ~1.2 CPU cores forever when its profile directory is deleted (dsh-hmr config watcher)
#13617
Deleting $DSH_HOME/profiles/<profile> while dsh web is running makes the process spin at ~1.2 CPU cores indefinitely. There is no error, no log line, no disk I/O, and no recovery: recreating the directory does not stop it, and the process never exits.
I traced it to the profile config watcher in @deepseek-ai/dsh-hmr (packages/boot/hmr/src/watch-config.ts). It watches the profile directory itself through chokidar with depth: 0 and awaitWriteFinish: true. Once that directory is deleted, chokidar 5.0.0 spins, and the host process inherits the burn.
Disabling the hmr row in the profile (disabled: true) makes the same experiment idle at 0.33% — that is the A/B proof for the responsible component.
In my case three such servers, started during testing and later orphaned when their DSH_HOME was cleaned up, silently consumed ~46% of an 8-core machine for 9 days.
Environment
Item
Value
DSH
0.2.2.0 (Windows desktop install, Electron)
Bundled runtime
Node v24.21.0, chokidar 5.0.0
OS
Windows 10 Pro, build 19045 (22H2)
CPU
Intel i7-8550U, 8 logical cores
Launch
dsh web --port 0 --no-open from the bundled CLI
Minimal reproduction
$env:DSH_HOME="D:\tmp\dshhome"
dsh web --port 0--no-open # prints: dsh web: http://127.0.0.1:<port>/?token=...# wait for the URL, confirm it idles near 0%Remove-Item"$env:DSH_HOME\profiles\web"-Recurse -Force
That last line is the whole trigger. No client, no session, no model call, no plugins.
Measurements
CPU read from Get-Process <pid>.TotalProcessorTime deltas, 8 logical cores, one fresh profile per row:
Experiment
Before
After
Verdict
Delete profiles/web (default)
0.05%
15.76% (≈1.26 cores)
spins
Delete profiles/web with hmr row disabled: true
0.05%
0.33%
no spin
Delete profiles/ (whole dir)
0.05%
16.02%
spins
Delete profiles/web/package.json only
0.12%
0.28%
no spin
Rename profiles → profiles.bak
0.12%
0.44%
no spin
Delete storages/
0.05%
0.44%
no spin
Delete the whole DSH_HOME
0.16%
16.00%
spins
Recreate DSH_HOME after the spin started
—
17.86%
does not recover
Read/write operation counters did not advance during any 12–15 s spin window, so this is CPU spinning rather than retry-driven I/O.
Root cause
packages/boot/hmr/src/watch-config.ts watches each of the profile's configuration files — the profile manifest package.json, the profile cordis.patch.yml, and the home-level $DSH_HOME/cordis.patch.yml:
Because the profile directory exists at startup, root becomes the profile directory itself with depth: 0. The watcher listens only for add / change / unlink on the configured files (onChange filters observed !== filename && observed !== target.filename), and nothing handles the watched root's own disappearance. When the directory is deleted, no error event is emitted either — the existing watcher.on('error') never fires — so the spin stays completely silent.
I verified the shipped 0.2.2 bundle contains this exact implementation (the distinctive config watch parent is not a directory / config path already registered strings are present in app.asar), so this is the running code, not a stale checkout.
Standalone chokidar reproduction
The spin is reproducible without dsh, against the same chokidar 5.0.0 that the shipped bundle carries:
const{ watch }=require('chokidar')constw=watch('D:/tmp/chk/web',{awaitWriteFinish: true,depth: 0,ignoreInitial: false})w.once('ready',async()=>{// baseline: 0.00% CPUfs.rmSync('D:/tmp/chk/web',{recursive: true,force: true})// measured 10 s later: 122.18% of one process (~1.22 cores)})
Same numbers as the host process, so whichever side fixes it, the trigger is the watch() call above with a directory root that later disappears.
Why this is reachable in normal use
Deleting or recreating a profile directory is not exotic:
dsh --profile <name> --from-default-profile <template> replaces a profile.
sanitizeProfile() (used by Desktop fatal recovery) manipulates the profile directory.
Users and cleanup scripts run rm -rf ~/.dsh/profiles/web, container/CI teardown wipes DSH_HOME, and disk-cleanup tools delete files under the home directory.
In my case the profiles were removed as part of test cleanup while the servers were still running.
Impact
~1.2 cores per orphaned server, indefinitely, with no visible symptom.
On a laptop: constant heat, fan noise, and battery drain.
Three instances had been running for 9 days at ~46% of an 8-core machine; the user had no way to attribute the load.
The process also never exits, so nothing reclaims it.
Suggested fixes (any one breaks the chain)
Watch the parent of the profile directory (dirname(profileDir) with depth: 1) so the profile's disappearance is an unlinkDir of a child rather than the death of the watch root.
Handle the root's disappearance explicitly: on unlinkDir for the watch root, dispose the watcher, re-run findWatchRoot(), and re-arm after a short backoff (this would also make "recreate the directory" recover, which today it does not).
Drop awaitWriteFinish for config watches (it enables polling) and keep atomic-write tolerance through a debounce-plus-retry read instead.
Add a regression test under packages/boot/hmr/tests/watch-config.spec.ts: delete the watched root and assert the process does not enter a CPU loop.
Workaround
Kill the process, or disable the config watcher for that profile:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Summary
Deleting
$DSH_HOME/profiles/<profile>whiledsh webis running makes the process spin at ~1.2 CPU cores indefinitely. There is no error, no log line, no disk I/O, and no recovery: recreating the directory does not stop it, and the process never exits.I traced it to the profile config watcher in
@deepseek-ai/dsh-hmr(packages/boot/hmr/src/watch-config.ts). It watches the profile directory itself through chokidar withdepth: 0andawaitWriteFinish: true. Once that directory is deleted, chokidar 5.0.0 spins, and the host process inherits the burn.Disabling the
hmrrow in the profile (disabled: true) makes the same experiment idle at 0.33% — that is the A/B proof for the responsible component.In my case three such servers, started during testing and later orphaned when their
DSH_HOMEwas cleaned up, silently consumed ~46% of an 8-core machine for 9 days.Environment
dsh web --port 0 --no-openfrom the bundled CLIMinimal reproduction
That last line is the whole trigger. No client, no session, no model call, no plugins.
Measurements
CPU read from
Get-Process <pid>.TotalProcessorTimedeltas, 8 logical cores, one fresh profile per row:profiles/web(default)profiles/webwithhmrrowdisabled: trueprofiles/(whole dir)profiles/web/package.jsononlyprofiles→profiles.bakstorages/DSH_HOMEDSH_HOMEafter the spin startedRead/write operation counters did not advance during any 12–15 s spin window, so this is CPU spinning rather than retry-driven I/O.
Root cause
packages/boot/hmr/src/watch-config.tswatches each of the profile's configuration files — the profile manifestpackage.json, the profilecordis.patch.yml, and the home-level$DSH_HOME/cordis.patch.yml:Because the profile directory exists at startup,
rootbecomes the profile directory itself withdepth: 0. The watcher listens only foradd/change/unlinkon the configured files (onChangefiltersobserved !== filename && observed !== target.filename), and nothing handles the watched root's own disappearance. When the directory is deleted, noerrorevent is emitted either — the existingwatcher.on('error')never fires — so the spin stays completely silent.I verified the shipped 0.2.2 bundle contains this exact implementation (the distinctive
config watch parent is not a directory/config path already registeredstrings are present inapp.asar), so this is the running code, not a stale checkout.Standalone chokidar reproduction
The spin is reproducible without dsh, against the same chokidar 5.0.0 that the shipped bundle carries:
Same numbers as the host process, so whichever side fixes it, the trigger is the
watch()call above with a directory root that later disappears.Why this is reachable in normal use
Deleting or recreating a profile directory is not exotic:
dsh --profile <name> --from-default-profile <template>replaces a profile.sanitizeProfile()(used by Desktop fatal recovery) manipulates the profile directory.rm -rf ~/.dsh/profiles/web, container/CI teardown wipesDSH_HOME, and disk-cleanup tools delete files under the home directory.Impact
Suggested fixes (any one breaks the chain)
dirname(profileDir)withdepth: 1) so the profile's disappearance is anunlinkDirof a child rather than the death of the watch root.unlinkDirfor the watch root, dispose the watcher, re-runfindWatchRoot(), and re-arm after a short backoff (this would also make "recreate the directory" recover, which today it does not).awaitWriteFinishfor config watches (it enables polling) and keep atomic-write tolerance through a debounce-plus-retry read instead.packages/boot/hmr/tests/watch-config.spec.ts: delete the watched root and assert the process does not enter a CPU loop.Workaround
Kill the process, or disable the config watcher for that profile:
To find offenders:
Kill the whole tree (
taskkill /PID <pid> /T /F) — killing only the wrappingcmd.exeleaves the server alive, which is how these accumulate unnoticed.中文摘要
现象:
dsh web运行中若$DSH_HOME/profiles/<profile>目录被删除,进程会持续空转在约 1.2 个 CPU 核心,无报错、无日志、无磁盘 IO;即使把目录重建也不会恢复,进程永不退出。根因:
@deepseek-ai/dsh-hmr的packages/boot/hmr/src/watch-config.ts用 chokidar 监听 profile 目录本身(root = dirname(patch/manifest),depth: 0,awaitWriteFinish: true)。监听根目录被删除后 chokidar 5.0.0 进入忙等,宿主进程随之空转。代码里只处理了配置文件的add/change/unlink,没有处理监听根目录自身消失,而且 chokidar 不抛error,所以连watcher.on('error')里的 warn 都不会打印。A/B 证据:同一实验下,启用
hmr时 0.05% → 15.76%;把hmr行设为disabled: true后 0.05% → 0.33%。另测:删除package.json、改名profiles、删除storages/均不触发。独立用 chokidar 5.0.0 复现得到 122%(约 1.22 核)。影响:每实例约 1.2 核持续消耗,笔记本上表现为持续发热、风扇噪音与耗电;作者这儿曾有 3 个实例静默运行 9 天、约占 8 核机器的 46%。
建议修复:改为监听 profile 目录的父目录(
depth: 1);或在监听根消失时释放并重建 watcher(带退避),顺带让"目录重建后恢复"成立;或对配置监听关闭awaitWriteFinish,改用去抖加重试读取;并补一个"删除监听根不应进入 CPU 忙等"的回归测试。All reactions