Skip to content

feat(launcher): persist spawned proxy for reuse across clients + bili stop - #136

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-08-13_launcher-durable-reuse
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-08-13_launcher-durable-reuse

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Launcher-spawned proxies now persist after the client exits and are reused by subsequent bili <client> invocations on the same port, instead of one-proxy-per-invocation (deterministic cleanup was fragile — see #24 floor 103: a reused proxy dying when its owning terminal closed broke other terminals' clients).

Changes

  • ensureProxyRunning: removed the domainsNeedFreshProxy gate. After feat(mitm): auto-discover model domains from client configs (no hardcoding) #125 (MITM discovery), the proxy discovers ALL client domains at runtime, so a running proxy covers every client. The gate was obsolete AND harmful (open.bigmodel.cn was removed from DEFAULT_MITM_DOMAINS in feat(mitm): auto-discover model domains from client configs (no hardcoding) #125, so the gate always forced a fresh spawn for pi/ZCode → never reused). Reuse is now pure health-probe.
  • runLaunch: removed stopProxy in the finally block. The spawned proxy (already detached:true+unref) now persists after the client exits; logs proxy left running at ORIGIN for reuse (run "bili stop" to terminate). runTestPi (one-off smoke) keeps its cleanup.
  • bili stop (new command): reads ~/.local/share/billion-context/launcher-proxy-<port>.pid files, kills the persisted proxies, removes stale PID files (handles ESRCH). Only stops launcher-spawned proxies — a standing bili start is left alone.
  • New exports: launcherPidFile(port, env), stopLauncherProxy(env).

Verified

  • Reuse confirmed: standing proxy on 8787 → bili test pi logs reusing existing proxy at http://127.0.0.1:8787 (not a fresh spawn). bili stop cleans up.
  • Persist confirmed: proxy (PID 2513068) survives launcher process exit; /__bili/health → 200.
  • typecheck clean, 343/343 tests, build OK.
  • Regression: bili test pi ✓ (GLM via MITM), bili codex exec ✓ (MITM ai.comfly.org, replied REGRESS-CODEX). (claude needs ANTHROPIC auth; opencode uses the extension + standing proxy, not the launcher.)

Lifecycle

  • bili pi → spawns (or reuses) proxy on 8787 → runs pi → proxy persists.
  • bili codex (next) → reuses the persisted 8787 proxy.
  • bili stop → terminates the persisted launcher proxy(es).
  • A standing bili start is reused identically (and is NOT stopped by bili stop).

… stop

Per user direction (改成复用): the launcher's spawned proxy now persists after
the client exits, so subsequent 'bili <client>' invocations reuse it instead of
spawning a new one. This makes reuse robust across terminals (the detached proxy
survives terminal close — it was already detached:true, but runLaunch killed it
on client exit, defeating reuse).

- ensureProxyRunning writes a PID file (~/.local/share/billion-context/
  launcher-proxy-<port>.pid) after a successful spawn.
- runLaunch no longer kills the spawned proxy on client exit; logs
  'proxy left running at ORIGIN for reuse (run bili stop to terminate)'.
- runTestPi (bili test pi smoke) KEEPS kill-on-exit (one-off, clean up).
- New 'bili stop' command reads all launcher-proxy-*.pid files, kills the
  processes, removes the files. stopLauncherProxy() exported for cli.ts.
- HELP updated.

Discovery (#125, merged) ensures the standing/spawned proxy covers ALL client
domains at runtime (isMitmHost → discoverMitmDomains), so reuse always finds a
domain-matching proxy. 343/343 tests, typecheck clean.
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