Skip to content

[PR] bili pi-inline: Enter the in-process engine with a single command (no proxy spawned, includes WS bridge) | bili pi-inline:一条命令进入 in-process 引擎(不起 proxy,含 WS 桥) - #4571

Merged
ranxianglei merged 3 commits into
2026-10-24_pi-inline-ws-bridgefrom
2026-10-24_pi-inline-launcher
Oct 24, 2026
Merged

ranxianglei merged 3 commits into
2026-10-24_pi-inline-ws-bridgefrom
2026-10-24_pi-inline-launcher

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是干嘛的

新命令 bili pi-inline:一条命令启动 pi,压缩跑在 pi 进程内(in-process 引擎),完全不起 proxy、不装 MITM 证书。之前想测 inline 只能手动 BILI_PI_INLINE=on pi,而且如果 shell 里残留 BILLION_CONTEXT_PROXY 之类的变量,inline 会被静默顶掉、退回起 server——这正是 #4526 里"我测试不起作用"的另一个来源。

改了什么

  • src/launcher.ts:新增 pi-inline 车道。启动前把继承来的 BILLION_CONTEXT_PROXY/HTTPS_PROXY/BILI_MITM_HOSTS 清掉(不清的话 planNativePi 会去 attach 而不是进 inline),给子进程设 BILI_PI_INLINE=1,并按 proxy 车道同样的规则注入 -e(settings.json 已装插件时不重复注入)。不起 proxy、不做任何健康探测。插件不可加载时直接拒绝(exit 2,不 spawn 任何东西)——没有 proxy 就没有 wire-mode 兜底,静默放行等于整场会话不压缩。
  • src/cli.ts:帮助文本 + 示例。
  • scripts/ci-pretest-cache.d.mts:补 refreshDistMtimes 声明(运行时导出已有,声明文件漏了,typecheck 会报错)。
  • src/agent/dsh-native.ts:一处 sidScope→dispatchScope(6d7c587 合并 [PR] merge: tier-1 consolidation train — 37 green PRs as one (conflicts resolved, #4294 reverted) #4525 时改名漏了这一处,本分支 typecheck 红;master 已在 de29698 修了同样内容,文本一致,合并时无冲突)。
  • tests/launcher-pi-inline.test.ts(新):不起 proxy、零 fetch、恶意继承 proxy 环境下 env 清理、-e 单次注入、拒绝路径不 spawn。

测试

  • 本地:launcher-pi-inline 2/2、launcher 回归面 395/395 全绿;typecheck 0 错误。
  • 实机:bili pi-inline -- --version 打出 "no proxy is started" 横幅,无 proxy 进程残留,退出码 0;外层故意设 BILI_PI_INLINE=0 也不影响(launcher 给子进程强制设 1)。

关系

Closes nothing(入口便利性,#4526 的补充)

…oxy, BILI_PI_INLINE)

- launcher: pi-inline ClientName; refuses (exit 2) when the bili pi extension
  cannot load (no wire-mode fallback without a proxy), strips inherited
  BILLION_CONTEXT_PROXY/HTTPS_PROXY/BILI_MITM_HOSTS so planNativePi arms the
  in-process engine instead of attaching, sets BILI_PI_INLINE=1, same -e
  single-load rule as the proxy lane
- cli help + examples
- scripts/ci-pretest-cache.d.mts: declare refreshDistMtimes (runtime export
  existed; the declaration file lagged and typecheck flagged the test)
- tests/launcher-pi-inline.test.ts: no-proxy/no-fetch assertions, env
  stripping under a hostile inherited proxy posture, -e only when settings
  has no entry, refusal path spawns nothing
) renamed sidScope to the LlmDispatchScope store but left this one use, breaking typecheck on this branch (master already fixed it in de29698; text mirrors that fix for a conflict-free merge)
@ranxianglei ranxianglei changed the title bili pi-inline:一条命令进入 in-process 引擎(不起 proxy,含 WS 桥) [PR] bili pi-inline: Enter the in-process engine with a single command (no proxy spawned, includes WS bridge) | bili pi-inline:一条命令进入 in-process 引擎(不起 proxy,含 WS 桥) Oct 24, 2026
… terminal

Field report on bili pi-inline: at boot every [storage]/[persist]/[inline]
line scrolled the pi input box away ('启动的时候都是日志 输入框没了').
The tee logger's stderr leg exists for the foreground proxy process; in the
inline lane (#3278) the engine runs INSIDE the host agent, so stderr is the
interactive TUI. Mute the terminal leg at engine start (bili.log file leg
stays; the logger re-enables stderr itself if the file leg dies, #2864);
BILI_INLINE_DEBUG=1 opts back in for live troubleshooting (documented in the
env-only seed). Regression test: real engine boot under a stderr spy must
write zero bytes.
@ranxianglei
ranxianglei merged commit 89ac373 into 2026-10-24_pi-inline-ws-bridge Oct 24, 2026
15 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner Author

真机复现的一个更深的坑,已修(edf73af):BILI_PI_INLINE=1 真跑时所有模型+管理请求都报 Connection error,裸 node 复现拿到根因:native 拦截环把模型 URL 改写成 `http://billion-context.inline/bili/<上游>` 后经 send 下沉,但 inline 环的 patched 包装层处在 #1662 的 depth=1 嵌套保护里,直接跳过自己的 dispatch——伪源站 URL 原样掉到裸 fetch,真查 DNS 报 ENOTFOUND。这个坑 master(#3278 起)就有,不是本 PR 引入:此前没有任何测试把两个环按真实 arm 顺序堆起来跑。\n\n修法:每个环的 send() 现在会标记它正要调用的下游函数(AsyncLocalStorage 一跳标记);patched 包装层若发现"上一跳指向的正是我",就是自家环的合法下沉,照常执行 dispatch(深度+1);外来 wrapper 夹在中间时标记对不上人,#1662 的截断保护原样生效。新增缺失的组合测试(inline 环+native 环按生产顺序安装,普通模型 URL 必须落到引擎、真实上游零打扰)。selfheal/#1662/#1410/#1158 全部 66 项回归 + 链路相关 237 项全绿;真机 `BILI_PI_INLINE=1 pi -p` 已通(引擎内建会话+上游响应+计费可见)。

ranxianglei added a commit that referenced this pull request Oct 24, 2026
… a loopback listener (#4571)

Field report: the inline status panel printed a dead 'Web UI:
http://127.0.0.1:0/...' link (no listener exists inline — the fake request
sockets hardcode localPort 0) and nothing in the panel said the engine was
the in-process inline lane.

- startInlineEngine now binds a loopback-only, unref'd, admin-only web
  listener (127.0.0.1:<ephemeral>) that drives the same pipeline; the panel's
  Web UI deep link becomes a real browser-clickable URL. Model lanes
  (/bili/...) are deliberately NOT exposed on it; bind failure is fail-soft
  (link hidden).
- the fake inline sockets report the real port as localPort so admin routes
  compute the true origin even for in-process status calls.
- ProxyOptions.inlineLane marks the lane at boot; /__bili/plugin/status and
  /__bili/plugin/tool pass it through and the panel version line appends
  ' · inline'.
- webSessionUrl hides ':0' origins instead of printing dead links.
ranxianglei added a commit that referenced this pull request Oct 24, 2026
…ver spawn unless opted back in (#4571)

Plain `pi` with the plugin installed now compresses IN-PROCESS (inline lane,
#3278): no proxy server process, no ephemeral port. The spawned-server mode
is one opt-away: "pi": {"inline": false} in billion-context.json, or
BILI_PI_INLINE=0/false/no/off in the env.

Precedence is otherwise unchanged: kill switches and /bili/ launches still
stand down; an explicit env/config inline choice still outranks everything;
an announced attach target (launcher-set BILLION_CONTEXT_PROXY/ATTACH) still
beats the new DEFAULT — wrapped launches keep attaching to their server.
An explicit env OFF still suppresses a file-true value (env > file).

planNativePi's fileInline parameter becomes tri-state (true/false/undefined)
so 'not configured' (default inline) and 'explicitly disabled' (server) are
distinct. Config reference seeds + CONFIGURATION.md regenerated.
ranxianglei added a commit that referenced this pull request Oct 25, 2026
#4571)

Field report: a pi session opened from the inline panel showed 基本信息
with no hint of which engine served it, so "这个是 inline 模式吧?" could
only be answered from bili.log (the session in question had in fact
attached to a running server, not gone inline).

Stamps session.metadata.engineLane at request time (handle.ts, first hit
wins like clientHint): "inline" when the engine runs in-process
(opts.inlineLane), "server" for a standalone proxy process (spawned or
attached). The web session list chips it beside the client hint
(inline / srv) and 基本信息 gains an 引擎 row — in-process (inline) vs
server process. Pre-stamp sessions render nothing (absent = unknown,
not guessed).

Tests: pi-inline.test.ts inline-web case now asserts the pi session
carries engineLane:"inline" in /__bili/sessions.
ranxianglei added a commit that referenced this pull request Oct 25, 2026
[PR] pi inline full rollout: fixed real-device stream drops + default to in-process engine (previously scattered across unmer | pi inline 全套落地:修好真机断流 + 默认走进程内引擎(之前散在未合并的 #4527/#4571 里)
ranxianglei added a commit that referenced this pull request Oct 25, 2026
Owner rule (never change defaults): plain  with no signals plans the
spawned proxy again, exactly as before #4669. Inline arms only on
BILI_PI_INLINE=1/on/yes/TRUE or {"pi":{"inline":true}} (explicit choice
still beats an announced attach target). Seeds/docs/LIFECYCLE updated;
plan matrices re-flipped ({}→spawn pinned in pi-native + pi-inline-ws
tests). Real-machine check: bare import plans spawn (spawn attempt
observed), env-on/file-true plan inline.
antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 25, 2026
… a loopback listener (ranxianglei#4571)

Field report: the inline status panel printed a dead 'Web UI:
http://127.0.0.1:0/...' link (no listener exists inline — the fake request
sockets hardcode localPort 0) and nothing in the panel said the engine was
the in-process inline lane.

- startInlineEngine now binds a loopback-only, unref'd, admin-only web
  listener (127.0.0.1:<ephemeral>) that drives the same pipeline; the panel's
  Web UI deep link becomes a real browser-clickable URL. Model lanes
  (/bili/...) are deliberately NOT exposed on it; bind failure is fail-soft
  (link hidden).
- the fake inline sockets report the real port as localPort so admin routes
  compute the true origin even for in-process status calls.
- ProxyOptions.inlineLane marks the lane at boot; /__bili/plugin/status and
  /__bili/plugin/tool pass it through and the panel version line appends
  ' · inline'.
- webSessionUrl hides ':0' origins instead of printing dead links.
antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 25, 2026
…ver spawn unless opted back in (ranxianglei#4571)

Plain `pi` with the plugin installed now compresses IN-PROCESS (inline lane,
ranxianglei#3278): no proxy server process, no ephemeral port. The spawned-server mode
is one opt-away: "pi": {"inline": false} in billion-context.json, or
BILI_PI_INLINE=0/false/no/off in the env.

Precedence is otherwise unchanged: kill switches and /bili/ launches still
stand down; an explicit env/config inline choice still outranks everything;
an announced attach target (launcher-set BILLION_CONTEXT_PROXY/ATTACH) still
beats the new DEFAULT — wrapped launches keep attaching to their server.
An explicit env OFF still suppresses a file-true value (env > file).

planNativePi's fileInline parameter becomes tri-state (true/false/undefined)
so 'not configured' (default inline) and 'explicitly disabled' (server) are
distinct. Config reference seeds + CONFIGURATION.md regenerated.
antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 25, 2026
ranxianglei#4571)

Field report: a pi session opened from the inline panel showed 基本信息
with no hint of which engine served it, so "这个是 inline 模式吧?" could
only be answered from bili.log (the session in question had in fact
attached to a running server, not gone inline).

Stamps session.metadata.engineLane at request time (handle.ts, first hit
wins like clientHint): "inline" when the engine runs in-process
(opts.inlineLane), "server" for a standalone proxy process (spawned or
attached). The web session list chips it beside the client hint
(inline / srv) and 基本信息 gains an 引擎 row — in-process (inline) vs
server process. Pre-stamp sessions render nothing (absent = unknown,
not guessed).

Tests: pi-inline.test.ts inline-web case now asserts the pi session
carries engineLane:"inline" in /__bili/sessions.
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
Louie0806 pushed a commit to Louie0806/billion-context that referenced this pull request Nov 4, 2026
planNativePi used to fall through to 'spawn' — bare pi with the
extension installed spawned its own proxy (dist/index.js start,
ephemeral port, parent-pid watchdog). Inline was opt-in only since
ranxianglei#4687 reverted the ranxianglei#4571 flip.

This restores the ranxianglei#4571 posture with explicit escape hatches:

  kill-switch > /bili/ launch > explicit inline (BILI_PI_INLINE=1/
  on/yes/TRUE or "pi":{"inline":true}) > ANNOUNCED attach target
  (launcher-set BILLION_CONTEXT_PROXY/ATTACH — bili pi keeps its
  launcher proxy) > inline DEFAULT > spawn (explicit opt-out only)

Opt-out restores the old attach/spawn posture verbatim:
BILI_PI_INLINE=0/false/no/off or "pi":{"inline":false}. Blank
BILI_PI_INLINE="" folds to unset. opencode's lane stays opt-in.

bili pi-inline stays (NOT deprecated): it scrubs inherited
BILLION_CONTEXT_PROXY/BILI_MITM_HOSTS so a stale attach env can't
hijack the child, and preflights extension availability — with no
proxy there is no wire-mode fallback, so a missing extension would
otherwise silently run uncompressed.

Supersedes the ranxianglei#4687 owner decision for the pi lane.
@ranxianglei ranxianglei mentioned this pull request Nov 6, 2026
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