Skip to content

fix(#1732): resolve dsh binary beyond bare PATH name; decode GBK subprocess output - #1734

Merged
ranxianglei merged 4 commits into
masterfrom
2026-09-30_dsh-bin-resolution
Sep 30, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-09-30_dsh-bin-resolution

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #1732

Problem

A dsh profile bundle's bili proxy (installed at $DSH_HOME/profiles/<name>/node_modules/billion-context) runs inside the dsh desktop app's process tree. That process's PATH does not carry the npm/pnpm global bin dirs, so the periodic self-update's owner-channel refresh (dsh plugin --profile <name> add billion-context@<latest>) spawned a bare dsh through cmd.exe /d /s /c and failed every check cycle with 'dsh' 不是内部或外部命令… — leaving the profile copy permanently frozen. That violates the #1196 Install-Lane & Update-Ownership Contract rule 2 ("every copy must have a LIVE update path … Permanent divergence is a bug"). Secondary symptom: the GBK error bytes landed mojibaked in the UTF-8 log file.

Changes (src/dsh-channel.ts + tests only)

  1. resolveDshBinary(env, platform, existsImpl, execPath) (exported for tests) replaces the private dshCommand. Resolution order:

    No isDshProfileCopy gate: probes only accept files that exist and PATH always wins, so this is strictly broader with no behavior risk for shell-launched setups.

  2. decodeChildOutput(buf) (exported for tests) — strict UTF-8 → GBK → lossy UTF-8. Both default runners now capture raw buffers instead of encoding: "utf8", so Chinese-Windows cmd.exe/pnpm stderr decodes correctly into the log instead of mojibake. Pure ASCII and valid UTF-8 output decodes byte-identically to before.

  3. Actionable failure guidance: the per-profile refresh-failure warn now ends with the exact manual command (dsh plugin --profile <name> add billion-context@<v> from a shell where dsh resolves, or point BILI_DSH_BIN at the executable); the ENOENT message mentions the probed locations.

Behavior changes (old → new)

Area Old New Why
dsh spawn target always bare dsh (unless BILI_DSH_BIN) full resolved path via PATH → known locations → bare fallback bare name ENOENTs under GUI-host minimal PATHs, killing the #1196 update path on Windows
Resolution cost none bounded existsSync probes per dsh plugin invocation negligible vs the 5-min timeout pnpm runs already take
Subprocess output decoding lossy UTF-8 (encoding: "utf8") strict UTF-8 → GBK → lossy UTF-8 GBK console bytes became mojibake in logs (#1732 secondary symptom)
Refresh-failure warn text …failed: <detail> …failed: <detail> — manual fix: run … (or point BILI_DSH_BIN …) users were left without next steps while it retried every cycle
ENOENT error text "not found on PATH — install deepseek-harness first…" "not found (not on PATH, not in the known install locations probed) — install deepseek-harness, or set BILI_DSH_BIN…" dsh may well be installed outside PATH+probes; the override stays the escape hatch

No config surface changes: BILI_DSH_BIN pre-existed and is untouched; no new env vars, fields, or CLI flags.

Shipping note (§5 — load-bearing updater machinery)

This touches the auto-update's dsh channel (src/dsh-channel.ts, imported by src/update.ts). Per AGENTS.md §5 it must ship after a no-op release validates the current upgrade path end-to-end — see the accompanying no-op release PR (v0.1.175, branch 2026-09-30_release-v0.1.175). Ship order: merge the no-op release first, confirm a real auto-updated 0.1.174 → 0.1.175 observation, then merge this PR and release it as v0.1.176.

Pre-flight (local, branch head)

  • npm run typecheck — clean
  • npm test — 3342 tests, 0 fail (17 skipped by design), incl. 10 new: resolver matrix (override / PATHEXT ordering / GUI-minimal-PATH→%APPDATA%\npm / node-dir / %LOCALAPPDATA%\pnpm / posix fallbacks / bare-fallback), wiring test (resolved binary actually reaches the runner), GBK + UTF-8 decode vectors
  • npm run build — success, dist-import-annotations OK

…rocess output

A dsh profile bundle's bili proxy runs inside the dsh desktop app's process tree, whose PATH does not carry the npm/pnpm global bin dirs — bare 'dsh' failed with the cmd.exe 'not recognized' error every check cycle, freezing the profile copy (violates the #1196 live-update-path contract).

- resolveDshBinary: BILI_DSH_BIN override -> PATH (win32 honors PATHEXT) -> known install locations a GUI host omits (node dir, %APPDATA%\npm, %LOCALAPPDATA%\pnpm, ~/.local/bin, /usr/local/bin, homebrew) -> bare 'dsh' fallback. Same pattern as launcher.resolveNodeRuntime (#1429).
- decodeChildOutput: strict UTF-8 -> GBK -> lossy UTF-8, so Chinese-Windows cmd.exe stderr no longer lands in the log as mojibake; runners capture raw buffers.
- refreshDshProfileBundles failure warn now carries the manual-fix command; ENOENT message mentions the probed locations.
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_dsh-bin-resolution (570f3f0)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1753-pr.1734.8aeab23

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1734.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到 PR #1734(fix #1732,分支 2026-09-30_dsh-bin-resolution,2 文件 +161/-12)。这是你/agent 已完成的工作,我不重做——正在按 review 规范走:① 审原 issue #1732 方向 → ② 回归审查 → ③ 代码审查 → ④ 测试有效性 → ⑤ diff 整洁度,并核对 CI。结论稍后回帖。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

placeholder

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

⚠️ Correction: the bare placeholder comment I posted here moments ago was an accidental mispost — my session was composing a review for the release PR #1735 and that draft landed in the wrong thread. It carries no content; please ignore it. The intended review has been posted on #1735.

更正:我几分钟前误发到本线程的 “placeholder” 评论是空草稿发错了地方(当时正在审 #1735 发布 PR),不含任何内容,请忽略。正式 review 已发到 #1735。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — one test bug found & fixed directly on the PR branch (b8f1907c); production code is sound.

① Original issue (#1732) — direction verified. Root-cause analysis holds: dshCommand() returned bare "dsh" unless BILI_DSH_BIN was set, so a bili copy running from a dsh profile bundle (inside the desktop app's process tree, minimal PATH) could never drive the #1196 owner-channel refresh → permanent divergence. The fix acts at the producer (spawn-target resolution) and at the source of the mojibake (raw-buffer capture + codepage-aware decode) — not by masking symptoms downstream. Correct layer.

② Regression audit — existing behaviors inventoried:

  • Preserved: BILI_DSH_BIN override used as-is; PATH precedence over known locations; PATHEXT per-dir ordering; cmd.exe /d /s /c wrap decision for .cmd/.bat/extensionless ([bug] Windows: a space in the client or -e path truncates the launch (spawn shell:true, unquoted) — and silently kills compression when only the command is quoted #679); 5-min DSH_EXEC_TIMEOUT_MS; windowsHide; per-profile failure isolation in refreshDshProfileBundles; local-pin skip (isRegistryDepSpec); refreshed>0 info log; bare-dsh fallback keeps today's ENOENT path when nothing is found (worst case = current behavior).
  • Changed (all disclosed in PR body): spawn target always-bare → resolved path; output decode lossy-UTF8 → strict-UTF8 → GBK → lossy (byte-identical for ASCII/valid UTF-8); refresh-failure warn gains manual-fix suffix; ENOENT text reworded.
  • Callers checked: src/update.ts (:617/:750/:1085) + src/plugin-install.ts (:1360/:1371/:2182) — all flow through the two entry points; no wire/message-shape impact (update-side only). Config surface: unchanged (BILI_DSH_BIN pre-exists on master, verified).

③ Code review. Resolver logic sound: empty APPDATA/HOME dirs skipped, mixed separators accepted by Windows fs, TextDecoder("gbk") unsupported → caught → lossy fallback. Residual (acceptable): dsh installed in a location neither on PATH nor among probed dirs still fails — covered by BILI_DSH_BIN + the now-actionable guidance.

④ Tests. The 9 new tests have teeth (resolver matrix, real-file wiring, GBK hex vector, degrade-without-throw). Minor non-blocking gap: the raw-Buffer→decode wiring inside defaultSyncRun/defaultAsyncRun isn't exercised end-to-end (decodeChildOutput itself is unit-tested).

⑤ CI failure — root-caused, fixed on-branch. Both Windows runners failed exactly one test (3342 total, 1 fail each): the new spawn-wiring test asserted command === <resolved path>, but on win32 planDshSpawn deliberately wraps .cmd shims through comspec /d /s /c (#679), so command === C:\Windows\system32\cmd.exe and the resolved path lives in the wrapped line. Test bug, not code bug. Fix pushed as b8f1907c (test file only, +8/−1): win32 now asserts comspec + wrapped-line containment; posix assertion unchanged. Verification: typecheck clean, npm test 3342 pass / 0 fail, build OK; plus a local win32 simulation driving resolveDshBinary + planDshSpawn with platform="win32" using the exact CI temp-dir shape and a space-in-path quoting case — all green. Re-run for b8f1907c is in flight.

Ship order reminder (§5): this touches auto-update machinery — merge no-op v0.1.175 (PR #1735) first, observe a real auto-updated 0.1.174 → 0.1.175, then merge this and release as v0.1.176. Auto-merge gate doesn't apply anyway (updater machinery + message-text changes) → human merge.

修复了 Windows GUI 宿主下 dsh profile 副本因裸 "dsh" 解析失败而自更新永久停更的问题(改为 PATH+已知安装位置解析真实二进制,子进程输出按 GBK 兜底解码);CI 红是新测试断言未考虑 win32 comspec 包装,已直接在 PR 分支补 commit 修正,生产代码无回归,可以合并(注意先合 no-op v0.1.175 再发 v0.1.176)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI follow-up: re-run on b8f1907c is fully green — 12/12 checks passed, including both windows-latest test jobs that previously failed. The PR is ready for human merge whenever convenient (ship order: no-op v0.1.175 / #1735 first, then this as v0.1.176).

ework-agent and others added 2 commits September 30, 2026 23:29
- defaultAsyncRun: execFile's default utf8 mode lossily stringified GBK bytes
  BEFORE decodeChildOutput ever saw them — and the async lane is exactly the
  auto-update refresh path, #1732's main victim. Capture raw buffers with
  encoding:"buffer" instead.
- formatDshError: the Buffer branch used toString("utf8"), bypassing the
  decoder; raw stderr buffers (reachable now that the async runner throws
  with Buffer stderr) must go through decodeChildOutput.
- decodeChildOutput: strict UTF-8 alone cannot distinguish GBK runs whose
  lead/trail bytes are also valid UTF-8 (GBK 系统 = cfb5cdb3 decodes as Greek
  "ϵς" with no U+FFFD in sight). Content heuristic: consecutive
  Greek/Coptic/Cyrillic plus a GBK re-read that yields CJK means the bytes
  were GBK all along.

Verified on a zh-CN Windows VM against a stripped PATH: cmd.exe's
系统找不到指定的路径。 and dsh-forwarded "'pnpm' 不是内部或外部命令" now render
readably in refresh failures (previously mojibake); resolveDshBinary probing
was re-confirmed in the same runs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[update] dsh profile bundle refresh fails on Windows: bare dsh not resolvable on PATH — profile copy stays frozen (#1196 contract)

1 participant