Skip to content

[PR] pi inline full rollout: fixed real-device stream drops + default to in-process engine (previously scattered across unmer | pi inline 全套落地:修好真机断流 + 默认走进程内引擎(之前散在未合并的 #4527/#4571 里) - #4669

Merged
ranxianglei merged 11 commits into
masterfrom
2026-10-25_pi-inline-stack
Oct 25, 2026

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是啥

之前以为 #4571 合了、inline 的活就进 master 了——其实不是:#4571 的基分支是 #4527 的分支,#4527 后来被关闭没合并,这一整套工作全部悬空,master 上一行都没有(本机能用只是因为全局装的是 worktree 构建)。这个 PR 把全部 10 个提交 rebase 到最新 master 重新提交。

里面有什么

按提交顺序:

  1. WS 桥(原 [PR] pi inline mode: add Codex WebSocket channel — local loopback WS bridge + relaxed toggle value constraints | pi inline 模式补上 codex WebSocket 通道:本地回环 WS 桥 + 开关取值放宽 #4527 主体,issue After enabling pi inline mode, codex's WebSocket traffic is not intercepted and still connects directly to the model (co | pi inline 模式打开后 codex 的 WebSocket 流量没被接管,仍直连模型(压缩被绕过) #4526):inline 模式下 codex Responses WebSocket 流量不再直连绕过压缩——起一个仅回环的 WS 桥,桥挂了该通道退回直连(打 warn),HTTP 压缩不受影响。
  2. 真机断流根因修复:inline 一开模型请求全断(Connection error)。根因是两个自家拦截环嵌套时被 DSH0.1.7-rc.2中billion-context与dsh-codex-subscription的冲突? #1662 的防外层包装协议误伤——改写后的伪源站 URL 没被进程内引擎接住,直接去做了真 DNS 查询(billion-context.inline → ENOTFOUND)。修复:自家环的下沉调用打上精确标记,合法下沉照常执行,外来包装的截断保护原样保留。这是 master 上 移植 billion-context-pi 版本的非 server 模式 #3278 以来的坑,一开 inline 必炸,之前的测试全过是因为从没按真实安装顺序堆过两个环。
  3. TUI 刷屏修复:引擎日志不再打爆 pi 终端挤掉输入框(默认只写 bili.log,要看 stderr 设 BILI_INLINE_DEBUG=1)。
  4. bili pi-inline 一条命令车道:直接用进程内引擎拉起 pi。
  5. 默认翻转:pi 车道默认走进程内引擎,不再另起代理进程;配置 "pi":{"inline":false} 或环境变量 BILI_PI_INLINE=0 可退回。附着已运行的 server(启动器预置目标)仍优先于默认值。
  6. 面板与 Web:状态面板标注 · inline、真实可点的 Web UI 链接(仅回环);会话列表/基本信息新增引擎徽章(进程内 inline / 独立进程 server),一眼分清这个会话是谁服务的。
  7. 文档种子 + 再生(pi.inline、BILI_PI_INLINE、BILI_INLINE_DEBUG,中英)。

冲突处理

验证

  • 相关回归 70 + 442 项全绿(pi-inline×7 / pi-native / launcher / native-intercept / fetch-chain / ci-pretest-cache / web-i18n / web-sessions / 4457 家族),typecheck 0 错误。
  • 真机已用同一树构建全局安装实测过:裸 pi -p 默认 inline 返回正常、日志确认零代理进程;inline 会话在共享 index.db 落 engineLane=inline 徽章。

Closes #4526

…ge in pi inline mode (#3278 follow-up)

Inline mode froze state.origin to the never-dialable INLINE_ORIGIN and
skipped installNativeWebSocketIntercept entirely, so codex WS traffic
went DIRECT and bypassed compression with no ACP session. The inline
engine now boots the same ws-bridge the spawned server serves, bound to
127.0.0.1:0 (loopback-only admission, tunnel guard, unref'd), the WS
wrapper prefers state.wsOrigin over the pseudo-origin, and a failed or
wedged bridge degrades that lane DIRECT (warned, 20s bound) while HTTP
compression keeps running in-process.

planNativePi now treats any non-empty BILI_PI_INLINE except 0/false/no/off
as on: on/yes/TRUE used to miss the 1/true set and silently spawn a proxy
server — the 'inline does not work' report.
…store the missing pluginLaneServerHistory seed (#4491 drift)

docs-sync regenerates CONFIGURATION*.md from website/config-reference
yaml seeds — hand edits to the generated blocks drift. The #4491 row was
hand-added without its seed, so every generate run (incl. docs-sync in
CI) wanted to delete it; seeding it keeps the row and the env index
entry. Backticks are forbidden in seed descs, hence the de-ticked row
text.
… (throttle429 #4204, BILI_CODEX_STATE_MODE, #4524 zh punctuation) without regenerating CONFIGURATION.zh-CN.md, leaving docs-sync drifted for every PR
…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
… 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.
…inline lane's pseudo-origin rewrite was dying on real DNS (#4527)

The native intercept rewrites model URLs to ${INLINE_ORIGIN}/bili/<upstream>
and hands them DOWN its send() to the inline transport link. But the inline
link's patched wrapper runs inside the #1662 depth protocol: depth===1 means
're-entry', so it skipped its own dispatch and the pseudo-origin URL fell
through to the raw fetch — ENOTFOUND billion-context.inline. Every model AND
management fetch in the real inline lane failed this way since #3278 (no e2e
ever exercised the two links stacked like the production arm).

Fix: each link's send() now stamps the exact downstream function it calls
(chainHop AsyncLocalStorage); a patched wrapper entered with the hop pointing
at ITSELF is a legitimate descent from the bili link directly above and runs
its dispatch one level deeper. A foreign wrapper in between re-issues the
call as its own hop, so the identity match fails and #1662 truncation keeps
protecting the descent exactly as before.

Adds the missing composition test: inline link + native intercept installed
in production order; a plain model URL must land on the engine and the real
upstream must stay untouched.
… 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.
…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.
#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 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-25_pi-inline-stack (024282c)

Latest build — install this exact version

npm install -g billion-context@0.0.5714-pr.4669.da30606

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
024282c billion-context@0.0.5714-pr.4669.da30606 build
35bae3d billion-context@0.0.5711-pr.4669.eb0ac59 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title pi inline 全套落地:修好真机断流 + 默认走进程内引擎(之前散在未合并的 #4527/#4571 里) [PR] pi inline full rollout: fixed real-device stream drops + default to in-process engine (previously scattered across unmer | pi inline 全套落地:修好真机断流 + 默认走进程内引擎(之前散在未合并的 #4527/#4571 里) Oct 25, 2026
…ow for the #4669 default flip

lifecycle-ledger-guard red: BILI_INLINE_DEBUG was read from src/ but not
in the ledger. While here, the BILI_PI_INLINE row still said 默认 off —
this stack flips the default, so the row now says so (and the file/env
opt-out spelling that gets the spawned server back).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复——本 PR 即 #4526/#4527/#4571 悬空工作的合并重提(三个原条目均已关闭,master 上一行没有,与 PR 描述一致)。但发现一个在途重叠:PR #4559(10-24 创建,open)做的是同一机制(codex Responses WS 在 inline 模式下的拦截/WS 桥),本 PR 第 1 个提交是其超集。已按政策给 #4559 打 duplicate 标签并留「duplicate of #4669」说明评论,关闭动作留给你。

标签:bug / pi / codex / scope/wiring / p1 —— 本 PR 含「inline 一开必炸」的断流根因修复(p1 级缺陷),且默认翻转波及全部 pi 车道用户,主域是协议接线。

开始审核:已拉取分支 2026-10-25_pi-inline-stack @ 35bae3d(base = master 28b667b,无落后)。23 文件 +1051/−68,按提交逐个过 diff、核对既有行为回归面与测试有效性,结论稍后按结构化八问给出。

@ranxianglei
ranxianglei merged commit fbfac66 into master Oct 25, 2026
79 of 126 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.833-master.fbfac66 (rolling master tag).

npm install -g billion-context@0.0.833-master.fbfac66  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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.
@github-actions github-actions Bot mentioned this pull request Oct 27, 2026
ranxianglei pushed a commit that referenced this pull request Nov 3, 2026
…route model traffic at fetch time (#5625)

Rework of PR #4280 (reverted by c076614 over a master conflict; original
report #4276) on top of current master.

The opencode-lane http.request hook used to replace e.request with a new
Request pointed at `${proxyOrigin}/bili/<originalUrl>`. opencode hands that
one mutable event to every later http.request/http.response hook, including
provider-scoped hooks from other plugins, so provider auth plugins validating
the upstream URL broke: Kiro's bridge silently stopped engaging (empty
responses after ~10 retries) and Antigravity threw "pool requests need the
default Google base URL" before its own hook could run.

The routes now only DISCOVER the proxy (state.proxyBase; oversize refusal /
direct-degrade on death) and leave the hook-visible payload untouched. Both
setup()s install the shared native fetch intercept chain, which performs the
/bili/ rewrite at fetch time — the bytes other plugins see in their hooks are
unchanged. The WS handshake hook builds its own tunnel URL instead of relying
on the rewritten request. These lanes also honour providers.<url>.direct
(#1622), previously implemented only in the ZCode lane: matching requests are
marked biliDirect in the hook and sent direct by the chain.

Behavior changes (disclosed per policy):
- Provider plugins in opencode lanes see original upstream URLs again.
- Signed-body model requests (x-goog-api-key / SDK-HMAC-SHA256) in V2
  processes get the local #1884 refusal instead of unsigned-through-bili.
- #3304 prepareDirectSend and #3248 onResponse acks activate in V2 processes
  (dead code before the chain existed there).
- Launcher dead-origin handling moves from preemptive unwrap-to-upstream to
  the chain's recover/retry/give-up-direct path.
- v1internal pool-shaped URLs (e.g. daily-cloudcode-pa.googleapis.com,
  recognized since #4256 for DSH Desktop Code-Assist traffic) ride the chain
  like any other model request: byte-preserving forward through bili, no
  bili identity headers invented. Hosts wanting such traffic fully off bili
  opt out per upstream via providers.<url>.direct.

Tests: new tests/issue5625-opencode-v2-hook-payload.test.ts pins the hook
payload contract (untouched request, fetch-time routing, pool dialect,
direct exemption, install gate); launcher/native suites updated to the
fetch-time contract; the #4669 inline-composition test installs the chain
like its sibling and asserts the hook keeps the payload intact.

Closes #5625
ranxianglei pushed a commit that referenced this pull request Nov 3, 2026
… the fetch-time contract (#5625)

CI follow-up on PR #5626 head 58438f1:
- unused-exports gate: replaceRequestTarget had no remaining callers once the
  routes stopped rewriting e.request — removed.
- tests/opencode-native.test.ts: the #4669 V2-composition pin asserted the old
  hook-time rewrite; it now installs the chain like its sibling and asserts
  the hook keeps the payload intact while the chain rewrites at send time.
- tests/issue5625-opencode-v2-hook-payload.test.ts: the pool-endpoint pin
  predated #4256's classifier arm for the v1internal dialect (DSH Desktop
  Code-Assist traffic rides exactly that URL); it now asserts the post-#4256
  contract — the hook stays out of the provider plugin's way and the chain
  forwards the pool URL byte-preserving with no bili identity invented.
ranxianglei pushed a commit that referenced this pull request Nov 4, 2026
…route model traffic at fetch time (#5625)

Rework of PR #4280 (reverted by c076614 over a master conflict; original
report #4276) on top of current master.

The opencode-lane http.request hook used to replace e.request with a new
Request pointed at `${proxyOrigin}/bili/<originalUrl>`. opencode hands that
one mutable event to every later http.request/http.response hook, including
provider-scoped hooks from other plugins, so provider auth plugins validating
the upstream URL broke: Kiro's bridge silently stopped engaging (empty
responses after ~10 retries) and Antigravity threw "pool requests need the
default Google base URL" before its own hook could run.

The routes now only DISCOVER the proxy (state.proxyBase; oversize refusal /
direct-degrade on death) and leave the hook-visible payload untouched. Both
setup()s install the shared native fetch intercept chain, which performs the
/bili/ rewrite at fetch time — the bytes other plugins see in their hooks are
unchanged. The WS handshake hook builds its own tunnel URL instead of relying
on the rewritten request. These lanes also honour providers.<url>.direct
(#1622), previously implemented only in the ZCode lane: matching requests are
marked biliDirect in the hook and sent direct by the chain.

Behavior changes (disclosed per policy):
- Provider plugins in opencode lanes see original upstream URLs again.
- Signed-body model requests (x-goog-api-key / SDK-HMAC-SHA256) in V2
  processes get the local #1884 refusal instead of unsigned-through-bili.
- #3304 prepareDirectSend and #3248 onResponse acks activate in V2 processes
  (dead code before the chain existed there).
- Launcher dead-origin handling moves from preemptive unwrap-to-upstream to
  the chain's recover/retry/give-up-direct path.
- v1internal pool-shaped URLs (e.g. daily-cloudcode-pa.googleapis.com,
  recognized since #4256 for DSH Desktop Code-Assist traffic) ride the chain
  like any other model request: byte-preserving forward through bili, no
  bili identity headers invented. Hosts wanting such traffic fully off bili
  opt out per upstream via providers.<url>.direct.

Tests: new tests/issue5625-opencode-v2-hook-payload.test.ts pins the hook
payload contract (untouched request, fetch-time routing, pool dialect,
direct exemption, install gate); launcher/native suites updated to the
fetch-time contract; the #4669 inline-composition test installs the chain
like its sibling and asserts the hook keeps the payload intact.

Closes #5625
ranxianglei pushed a commit that referenced this pull request Nov 4, 2026
… the fetch-time contract (#5625)

CI follow-up on PR #5626 head 58438f1:
- unused-exports gate: replaceRequestTarget had no remaining callers once the
  routes stopped rewriting e.request — removed.
- tests/opencode-native.test.ts: the #4669 V2-composition pin asserted the old
  hook-time rewrite; it now installs the chain like its sibling and asserts
  the hook keeps the payload intact while the chain rewrites at send time.
- tests/issue5625-opencode-v2-hook-payload.test.ts: the pool-endpoint pin
  predated #4256's classifier arm for the v1internal dialect (DSH Desktop
  Code-Assist traffic rides exactly that URL); it now asserts the post-#4256
  contract — the hook stays out of the provider plugin's way and the chain
  forwards the pool URL byte-preserving with no bili identity invented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant