Skip to content

[bug] ensureProxyRunning: missing child error handler kills host on async spawn failure #835

Closed

Description

@ranxianglei

来源: #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.ts ensureProxyRunning 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.

Refs: found in #809; fixed in #824.

Activity

  1. ranxianglei commented on Sep 16, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    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.ts ensureProxyRunning (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.

  2. ranxianglei commented on Sep 16, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    Fixed and shipped as a PR → #838

    Verification (bug-class triage — proved real before touching code):

    Change (PR #838):

    • 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.

  3. ranxianglei commented on Sep 17, 2026

    @ranxianglei
    OwnerAuthor

    继续

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions