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
来源: #809 分析 opencode npm-plugin 部署(实际测试)时发现 — finding D
Symptom
When the resolved node runtime cannot spawn (EACCES / ENOENT — e.g. a mis-set BILLION_CONTEXT_NODE, or an exotic runtime path), the hosting process dies instead of failing gracefully.
Root cause
src/launcher.tsensureProxyRunning registered only child.on("exit"), never child.on("error"). An async spawn failure emits 'error' (not 'exit'). With no listener, Node turns the unhandled 'error' event into an uncaughtException that terminates the host process. Meanwhile the poll loop never sees childExit, so it burns the full SPAWN_WAIT_MS and misreports "proxy did not become healthy".
(runClient already handled 'error' correctly — the proxy-spawn path did not.)
Impact
Shared code — affects every launcher that spawns the proxy, not only opencode. A narrow trigger (bad runtime resolution) escalates into killing the launching client.
Fix
Shipped in #824 @ 54f8fb2: register a child.on("error") handler, break the poll loop on it, and reject with the spawn cause (bili: proxy spawn failed (<detail>)). Regression test added in tests/launcher.test.ts (asserts an 'error' handler is registered + rejects spawn failed). Full suite green.
Triage: verified — the bug is real and still live on master.
I checked out the current tree and confirmed the root cause directly:
src/launcher.tsensureProxyRunning (master @ d54070f, function at :1915) registers only child.on?.("exit", …) (:2035) around the spawn/poll loop. There is no "error" listener. An async spawn failure (EACCES/ENOENT on a mis-resolved runtime) emits 'error'; with no handler it becomes an uncaughtException that kills the host process, while the poll loop keeps burning the full SPAWN_WAIT_MS and then misreports "proxy did not become healthy".
runClient (function at :2143) already handles both correctly ("error" :2156 + "exit" :2157) — exactly as reported: the client-spawn path was right, the proxy-spawn path was not.
On "Shipped in #824": that wording overstates it. Commit 54f8fb2 is the HEAD of PR #824, which is still open and targets the feat/pi-native-plugin branch (base ≠ master), so it has not landed on master or any published release. The defect is therefore unfixed in production.
Plan: bring the D-fix forward to master as its own focused PR (register the "error" handler, break the poll on it, reject with the spawn cause + a regression test). The N4 mcp-guard half of that commit is a separate finding (#809 N4) and stays out of scope here. Flagging the overlap with #824 so it isn't double-applied later.
Implementing now — will follow up with the PR link.
Verification (bug-class triage — proved real before touching code):
Confirmed on origin/master (d54070f): ensureProxyRunning (src/launcher.ts:1915) registers only child.on?.("exit") (:2035) inside the spawn/poll loop; there is no"error" handler. On an async spawn failure (EACCES/ENOENT) Node emits 'error', which with no listener becomes an uncaughtException that kills the host, while the poll loop burns the full SPAWN_WAIT_MS and then misreports "did not become healthy". runClient (src/launcher.ts:2143) already handles both ("error":2156, "exit":2157) — only the proxy-spawn path was missing it. Matches the report exactly.
Register child.on("error", …) in ensureProxyRunning.
Break the health-poll loop as soon as either childExit or childError is set (fail fast instead of burning the window).
Reject with the spawn cause: bili: proxy spawn failed (<detail>) (log: <path>).
Regression test in tests/launcher.test.ts: asserts an 'error' handler is registered on the spawned child and that ensureProxyRunning rejects with spawn failed when the child emits an async spawn error (modeled on the existing #707 inline-SpawnChild test).
I deliberately scoped this to the D-fix only. #824 also bundled an N4 mcp-guard change to src/plugin-install.ts (a separate #809 finding) — that stays out of this PR.
Pre-flight (all green):npm run typecheck clean · npm test 1650 tests / 1648 pass / 0 fail / 2 skipped (pre-existing) · npm run build success. Diff touches only src/launcher.ts + tests/launcher.test.ts.
Not merged — PR merges are human-only. Please review #838.
Activity
ranxianglei commentedon Sep 16, 2026
Triage: verified — the bug is real and still live on
master.I checked out the current tree and confirmed the root cause directly:
src/launcher.tsensureProxyRunning(master @d54070f, function at :1915) registers onlychild.on?.("exit", …)(:2035) around the spawn/poll loop. There is no"error"listener. An async spawn failure (EACCES/ENOENT on a mis-resolved runtime) emits'error'; with no handler it becomes anuncaughtExceptionthat kills the host process, while the poll loop keeps burning the fullSPAWN_WAIT_MSand then misreports "proxy did not become healthy".runClient(function at :2143) already handles both correctly ("error":2156 +"exit":2157) — exactly as reported: the client-spawn path was right, the proxy-spawn path was not.On "Shipped in #824": that wording overstates it. Commit
54f8fb2is the HEAD of PR #824, which is still open and targets thefeat/pi-native-pluginbranch (base ≠ master), so it has not landed on master or any published release. The defect is therefore unfixed in production.Plan: bring the D-fix forward to
masteras its own focused PR (register the"error"handler, break the poll on it, reject with the spawn cause + a regression test). The N4 mcp-guard half of that commit is a separate finding (#809 N4) and stays out of scope here. Flagging the overlap with #824 so it isn't double-applied later.Implementing now — will follow up with the PR link.
ranxianglei commentedon Sep 16, 2026
Fixed and shipped as a PR → #838
Verification (bug-class triage — proved real before touching code):
origin/master(d54070f):ensureProxyRunning(src/launcher.ts:1915) registers onlychild.on?.("exit")(:2035) inside the spawn/poll loop; there is no"error"handler. On an async spawn failure (EACCES/ENOENT) Node emits'error', which with no listener becomes anuncaughtExceptionthat kills the host, while the poll loop burns the fullSPAWN_WAIT_MSand then misreports "did not become healthy".runClient(src/launcher.ts:2143) already handles both ("error":2156,"exit":2157) — only the proxy-spawn path was missing it. Matches the report exactly.feat/pi-native-plugin(base ≠ master), so the fix is not on master or in any release — it's orphaned on a feature branch. The bug is live on the mainline, so I brought this specific fix forward independently rather than waiting on that branch.Change (PR #838):
child.on("error", …)inensureProxyRunning.childExitorchildErroris set (fail fast instead of burning the window).bili: proxy spawn failed (<detail>) (log: <path>).tests/launcher.test.ts: asserts an'error'handler is registered on the spawned child and thatensureProxyRunningrejects withspawn failedwhen the child emits an async spawn error (modeled on the existing#707inline-SpawnChild test).I deliberately scoped this to the D-fix only.
#824also bundled an N4 mcp-guard change tosrc/plugin-install.ts(a separate#809finding) — that stays out of this PR.Pre-flight (all green):
npm run typecheckclean ·npm test1650 tests / 1648 pass / 0 fail / 2 skipped (pre-existing) ·npm run buildsuccess. Diff touches onlysrc/launcher.ts+tests/launcher.test.ts.Not merged — PR merges are human-only. Please review #838.
ranxianglei commentedon Sep 17, 2026
继续
fix(launcher): handle async spawn 'error' in ensureProxyRunning (ranx…