Skip to content

fix(launcher): isolate launches on a random free port; drop proxy attach (#446) - #465

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-03_launcher-isolated-random-port
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-03_launcher-isolated-random-port

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

Closing as superseded by #526 (plan 1: port isolation only).

This PR over-interpreted 「启动器模式都是隔离」 as process isolation — dropping the #417 attach-or-spawn share path and adding per-token handshake files. Per the issue thread, the intent was port isolation only: launcher proxies shouldn't squat on 8787, but a healthy compatible instance (including an explicitly-started bili start) should still be attached, keeping the single-writer property #417 was built for.

The crash-root-cause narrative here also predates part of #417's guards; the residual owner-exit cascade was accepted in the issue thread. Thanks for the groundwork — the ephemeral-port portion lives on in #526.

…ach (#446)

Launcher mode (`bili pi`, `bili codex`, ...) now always spawns its own proxy on
a random free port instead of defaulting to 8787 and attaching to a running one.

Root cause of the reported crash: the attach-or-spawn path (#394/#417) was keyed
by the instance file, not the requested port, so two launchers could share one
proxy. When one client exited, its stopProxy killed the shared proxy and took
down every other launcher attached to it.

- launcher: no explicit --port -> pickEphemeralPort() (OS-assigned free port);
  removed the attach-or-spawn share path + now-dead compat/probe helpers;
  stopProxy always kills its own child
- server/instance: per-launchToken handshake report file so N concurrent
  isolated launchers don't clobber the single proxy-origin record; cleared on
  graceful shutdown. Retains the #407 EADDRINUSE-retry self-bind handshake
- standalone `bili start` is unchanged (still defaults to 8787) — explicit
  sharing happens there, per the owner's direction

Pre-flight: typecheck + build clean; npm test 913/914 (only the pre-existing
resolveClientCommand environment failure).
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-03_launcher-isolated-random-port (c0a3c25)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-465

Each push to this PR publishes a new version under the pr-465 npm tag.

Option B — Download artifact

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

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 🏷 Review of #465 — LGTM, no blockers. Two minor notes at the end.

Root cause & approach — verified correct. The old attach-or-spawn path decided share-vs-spawn by reading the shared proxy-origin instance file, not the requested port — so a second launcher attached to the first one's proxy, and when the first client exited its stopProxy() killed the shared proxy and took down every attached launcher. Changing only the default port would indeed not have fixed this; removing attach entirely matches the decision (launcher mode = always isolated; sharing only via a separately-started server).

Verified on c0a3c25:

Pre-flights I ran:

  • npm run typecheck — clean; npm run build — OK
  • npm test — 913/914. The single failure (resolveClientCommand: codex/claude resolve to themselves) also fails on master in this environment (verified via worktree) → the "pre-existing environment-only" claim is accurate.
  • Full E2E could not run here: the default upstream http://127.0.0.1:8199/v1 refuses connections in this sandbox (warmup dies ECONNREFUSED→502 before any PR-changed code runs). Note the suite doesn't set BILI_LAUNCH_TOKEN anyway, so the changed handshake path isn't exercised by it; the server.ts delta is instance-file bookkeeping guarded by the token. Worth one standard 4-phase E2E run against a local upstream before merge, per AGENTS.md §3.

Minor notes (non-blocking):

  1. Cosmetic: the --port <N> help line in src/cli.ts is indented 3 spaces while all sibling options use 2.
  2. Orphaned proxy-origin-<token> files linger in the state dir if the proxy dies without graceful shutdown (crash/SIGKILL — finishShutdown is the only unlink site). No correctness risk (only the owning launcher ever reads a given token file), but they accumulate ~200B each with no GC. Optional follow-up: prune stale proxy-origin-* entries at startup.

Happy to push the one-line indent fix onto this branch if you want it included.

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.

1 participant