Skip to content

[PR] pi inline mode: add Codex WebSocket channel — local loopback WS bridge + relaxed toggle value constraints | pi inline 模式补上 codex WebSocket 通道:本地回环 WS 桥 + 开关取值放宽 - #4527

Closed
ranxianglei wants to merge 6 commits into
masterfrom
2026-10-24_pi-inline-ws-bridge
Closed

ranxianglei wants to merge 6 commits into
masterfrom
2026-10-24_pi-inline-ws-bridge

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #4526

修什么

开 BILI_PI_INLINE 后,codex 的 Responses WebSocket 流量原来直连上游、完全绕过压缩(原因分析见 issue)。本 PR 三件事:

  1. 进程内 WS 桥(新文件 src/inline-ws.ts):inline 引擎启动时在 127.0.0.1:0 起一个只服务 WS 升级的监听,复用现有 ws-bridge.ts 的全套安全检查(只认本机回环来源、会话头校验、隧道目的地防 SSRF、unref() 不拖住进程生命周期)。codex WS 改写到这个真端口,由进程内引擎照常压缩。
  2. 降级安全:桥起不来(或 20 秒内没起来)时,这条 WS 通道退回直连并打 warn,HTTP 压缩继续走进程内,不影响 inline 整体可用性。桥的 origin 通过 state.wsOrigin 传给 WS 包装器,只影响 inline 模式,spawn/attach 模式行为不变。
  3. 开关取值放宽 + 明确日志:BILI_PI_INLINE 除 0/false/no/off 外任何非空值都算开(原来只认 1/true,on/yes 会静默落回起 server——这就是"inline 不管用"的一个真实来源);inline 生效时打 info 日志"inline 模式,不另起 proxy",失效原因从此可见。

改动文件

  • src/inline-ws.ts(新):回环 WS 桥启动器
  • src/inline-engine.ts:引擎启动时一并起桥,暴露 wsOrigin;HTTP 形管线驱动 dispatchHttp(给桥的会话信封用,裸驱动,不再包自己的传输层——会话外层已包 WS 出口)
  • src/agent/native-ws-intercept.ts:快路径优先 state.wsOrigin;pending 的桥启动有 20 秒上限,超时按"没桥"降级,不会把连接卡在 CONNECTING
  • src/agent/native-intercept.ts:NativeInterceptState 加可选 wsOrigin 字段
  • src/agent/pi-native.ts:inline 分支挂 wsOrigin、不再跳过 WS 包装器、修正错误注释、放宽取值、加 info 日志
  • tests/pi-inline-ws.test.ts(新):全链路(假 codex WS 上游 → 包装器 → 回环桥 → 假引擎管线 → 三帧响应逐帧核对)、桥口纯 HTTP 426、桥失败降级直连、取值矩阵
  • tests/pi-inline.test.ts:假引擎补两个新字段
  • CONFIGURATION.md:取值表和说明更新

测试

  • 新用例 4/4 绿;直接相关回归 52/52 绿(pi-native 18、pi-inline、native-ws-intercept、ws-bridge、responses-ws)
  • 邻接面 461/461 绿(所有 import 到改动模块的测试文件)
  • tsc --noEmit 0 错误;unused-export 门 clean
  • 注意:本仓库外层套着 billion-context 跑测试时,BILI_PROVIDER_REWRITES 等残留环境变量会让 pi-native 的模块级用例假红,清掉再跑(与 CI 无关)

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-24_pi-inline-ws-bridge (28ab76d)

Latest build — install this exact version

npm install -g billion-context@0.0.5487-pr.4527.9039b11

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
28ab76d billion-context@0.0.5487-pr.4527.9039b11 build
81e34b8 billion-context@0.0.5486-pr.4527.289836f build
481ccbb billion-context@0.0.5464-pr.4527.29d0670 build
a5dc39e billion-context@0.0.5460-pr.4527.b5eab01 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title pi inline 模式补上 codex WebSocket 通道:本地回环 WS 桥 + 开关取值放宽 [PR] pi inline 模式补上 codex WebSocket 通道:本地回环 WS 桥 + 开关取值放宽 Oct 24, 2026
@ranxianglei ranxianglei changed the title [PR] pi inline 模式补上 codex WebSocket 通道:本地回环 WS 桥 + 开关取值放宽 [PR] pi inline mode: add Codex WebSocket channel — local loopback WS bridge + relaxed toggle value constraints | pi inline 模式补上 codex WebSocket 通道:本地回环 WS 桥 + 开关取值放宽 Oct 24, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重:不重复。 本 PR 对应 issue #4526(inline 模式 codex WS 绕过压缩),open/closed 里无同机制的其他 PR。但发现一处跨 PR 重叠:本 PR 第 2 个 commit(481ccbb94)里"restore the missing pluginLaneServerHistory seed"与在途的 PR #4534(专门修 master docs-sync 红、恢复同一个 seed)撞了——两者都往 website/config-reference/rollout.yaml 补同一条缺失 seed。这不是重复立项问题,是合并顺序/冲突问题,review 结论里会说明处置建议。

开始按 PR 规范审核:①原 issue 方向 → ②回归审查 → ③代码 → ④测试有效性 → ⑤diff 整洁度,结论用结构化八问回复。

@ranxianglei ranxianglei reopened this Oct 24, 2026
…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.
…n guard fired on restored artifacts

The #4377 cache skip left kernel/dist with save-time mtimes while the
checkout rewrote kernel/src mtimes; kernelDistStale() compares mtimes, so
the first real cache-HIT PR (this one — no kernel changes) made the
golden-storage drives refuse to run on 5 legs. Touch the dist tree on
every HIT (metadata-only; bytes are already marker-verified).
… this branch (other branches do create runs)
@ranxianglei
ranxianglei force-pushed the 2026-10-24_pi-inline-ws-bridge branch from 27e81a4 to 81e34b8 Compare October 24, 2026 12:41
… (throttle429 #4204, BILI_CODEX_STATE_MODE, #4524 zh punctuation) without regenerating CONFIGURATION.zh-CN.md, leaving docs-sync drifted for every PR
@ranxianglei
ranxianglei force-pushed the 2026-10-24_pi-inline-ws-bridge branch from 81e34b8 to 28ab76d Compare October 24, 2026 12:43
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

一句话:这个 PR 的合并冲突已经解决了,本次冲突 lane 无需 rebase / push。 现在挡住合入的不是文本冲突,而是 CI 红——而且红的主体是 master 自身的存量红,不是本 PR 或这次 rebase 带进来的。

冲突维度证据(为什么无需动作)

  • GitHub 实时状态:mergeable=true、mergeable_state=blocked(=检查未过,不是 dirty / 有冲突)。
  • 本地非破坏性 git merge-tree(origin/master ↔ PR head):退出码 0,零冲突文件。
  • git merge-base --is-ancestor:master(6d7c587)已是 PR head(28ab76d)的祖先,head = master + 6 个提交,完全落在最新 master 之上;远端分支 2026-10-24_pi-inline-ws-bridge 当前就指向 28ab76d,与 PR head 一致。
  • 时间线:dirty 于 11:35Z 触发(当时 master 还没到 6d7c587),之后分支在 12:43Z 被重新落到新 master 上(那几笔 retrigger / docs-regen 提交),冲突随之消失。
  • 再 rebase 是空操作、再 push 同一个 SHA 只会白触发一轮本就起不来的 CI,所以未做任何 git 改动、不 push。

结构化八问

  1. 是什么问题:系统转发「上游 PR 冲突(dirty)」,要求 rebase 解冲突。
  2. 什么原因导致:触发时 master 领先于 PR base,产生文本冲突;此后分支已被重新 rebase 到最新 master 之上,冲突消除。当前状态是 blocked(检查未过)而非 dirty(有冲突)。
  3. 影响范围与严重程度:冲突维度 = 无(已可干净合并;功能代码完好——src/inline-ws.ts、tests/pi-inline-ws.test.ts 等全部改动经 diff 核对都在,rebase 没丢东西)。真正阻塞合入的是 CI 红:主体是 master 存量红(阻塞全仓所有 PR),外加本 PR 侧一处测试类型小坑。
  4. 怎么修的(冲突):无需修——已无冲突,故未改任何代码、未 push(避免空操作空跑 CI)。
  5. 回归风险 / 既有行为:核对 rebase 后 diff,PR 所述改动完整保留,未见丢提交或语义漂移。CI 定位到两个具体报错:
    • src/agent/dsh-native.ts:1287 Cannot find name 'sidScope' —— 这是 master 的红,不是本 PR 的:该文件不在本 PR 改动清单里、与 master 逐字节一致;master 顶(6d7c587)的 static-gates 用同一行同一错挂掉。要等 master 先绿。
    • tests/ci-pretest-cache.test.ts:99 Property 'refreshDistMtimes' does not exist —— 本 PR 侧,由本 PR commit 9c418b9(ci-pretest 缓存 mtime 修复)带入:.mjs 里其实有 export function refreshDistMtimes(head 上第 142 行),但 .ts 测试从 .mjs 推断类型时没看到这个导出。属可在 PR 内修的小问题,但 master 转绿前修了仍是红。
    • 其余失败项(test (...) 多个分片、lifecycle-ledger-guard)在 master 顶同样失败 → 同为存量红,非本 PR 引入。
  6. 是否破坏缓存:不涉及(仅做冲突 / CI 状态判定,未碰任何运行时或缓存逻辑)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入新配置:不涉及(未做任何代码改动)。

建议(供 owner / reviewer 定夺,我不越界去动 load-bearing 路径)

  • 冲突 lane:完成,判定「无需动作」。
  • CI 红的主战场在 master(sidScope + test 分片 + lifecycle-ledger-guard),建议在既有的 master 修复线程里收敛,别塞进本 PR;本 PR 等 master 转绿后重跑即可。
  • 本 PR 唯一可顺手修的是 refreshDistMtimes 的类型可见性(涉及 .mjs→.ts 类型解析,需确认修法),建议由本 PR 作者 / reviewer 在 PR 内处理。

收工判定:冲突已解决、无 rebase 可做;PR 暂不可合的原因已从「冲突」澄清为「master 存量 CI 红 + 本 PR 一处测试类型小坑」。冲突 lane 到此收工。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

审核完成(针对 rebase 后的分支 tip 28ab76d59,6 commits / 13 files / +520−29)。结论:代码质量达到可合标准,方向正确、回归干净、自身测试全绿;但当前不可合——master 本身是红的(与本子无关)+ 一个需要你拍板的重复提交问题 + 一行配套声明缺失。详见下方发现清单。

标签: bug, pi, codex, scope/wiring, p2(pi inline 车道的 codex WS 压缩绕过缺陷;能用但 inline+codex 用户丢压缩,有绕行,非数据丢失类)

结构化八问

  1. 是什么问题:开了 BILI_PI_INLINE 后,codex 的 Responses WebSocket 流量直连上游、完全绕过压缩,也不形成 ACP 会话记录。
  2. 什么原因导致的:三层根因(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 分支把 origin 冻成假地址 http://billion-context.inline,WS 改写无处可拨;② installNativeWebSocketIntercept 在 inline 模式被跳过(注释声称"pi 车道不用 codex WS",与事实相反);③ 开关只认 1/true,on/yes 等值静默落回 spawn 且无日志。
  3. 影响范围与严重程度:仅「启用 inline 且会话走 codex WS」的用户面;HTTP 流量不受影响;绕行 = 不开 inline(spawn 模式全功能正常)。p2。
  4. 怎么修复的:进程内回环 WS 桥(127.0.0.1:0,复用 ws-bridge.ts 全套安全检查:只认本机回环来源、会话头校验、隧道目的地防 SSRF、unref()),codex WS 改写到真端口走进程内引擎压缩;WS 包装器改为无条件安装;桥起不来时该通道降级直连 + warn,HTTP 压缩继续——可用性优先,降级不猜。
  5. 是否有回归问题:无。逐项审过既有行为:spawn/attach 模式字节级不变(wsOrigin 为 undefined 时走原快速路径);inline HTTP 车道不受桥状态影响(readyOrigin 在 INLINE_ORIGIN 短路);桥的 admission/close/unref 语义与 src/server.ts:713 的 spawn 侧安装逐参数核对一致(codecs 顺序、egress-proxy lambda、instanceId 全同);三个 dispatch catch 变体的差异(makeDispatcher 抛 / makeHttpDispatch 吞 / server.ts 无守卫)各自匹配其调用方契约,属有意设计非漂移。全部 e2e 车道绿(含 e2e-pi-codex-ws 真实客户端 WS 车道、e2e-native-pi);本 PR 新增/改动套件在 CI 全绿(inline WS 四例 ok 1323–1326 / 1935–1938,移植 billion-context-pi 版本的非 server 模式 #3278 系列绿)。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/增量游标/去重键逻辑;WS 通道只是被路由进既有压缩管线,前缀缓存接缝无变化。
  7. 是否改了设计方向:没有。是既有设计(进程内引擎 + 客户端拦截 + ws-bridge)的自然补全,不是转向。
  8. 是否引入了新的配置:无新 env/config key。BILI_PI_INLINE 取值集合放宽,见下方行为变更披露。

行为变更披露(旧值→新值 + 原因)

  • BILI_PI_INLINE 取值:旧 {1,true}(+文件配置兜底)→ 新「{0,false,no,off} 之外的任何非空值」。on/yes/TRUE 等现在生效;no/off 现在显式压过文件值。原因:旧解析下这些值静默落回 spawn 且零日志,是"inline 不管用"报告的真实来源之一。CONFIGURATION.md/.zh-CN.md/website yaml 已同步(docs-sync 门绿)。
  • inline 模式 codex WS 通道:直连上游不压缩 → 经回环桥压缩(修复本体);桥启动失败时退回旧行为并 warn。
  • 新增一条 info 日志(inline 生效时:"inline 模式,不另起 proxy"),失效原因从此可见。

发现清单

A.[拦路·与本子无关]master 本身红。本分支 rebase 到当前 master 后继承其红,失败签名全部落在本 PR 未触碰的文件上,且与 master 自己的 CI 运行(12:22Z)逐条同签名:

B.[需拍板]commit 3(CI mtime 修复)与在途 PR #4549 重复:两者修同一个 #4548(pretest-cache HIT 后 dist mtime 陈旧触发 #3325 golden guard)。建议从本 PR 移除该 commit(保单 scope,让 #4549 专修 CI),或反向关掉 #4549 留在这里——二选一。

C.[一行修复·耦合 B].d.mts 声明漏更新:scripts/ci-pretest-cache.d.mts 是手写声明文件,commit 3 往 .mjs 加了 refreshDistMtimes 却没加声明行 → static-gates TS2339(此错仅本分支有,master 无)。补一行即解:export function refreshDistMtimes(distDir: string, now?: Date): number; 若 B 拍板把该 commit 移去 #4549,那边同样漏了这行(diff 也只含 2 个文件)。作者"tsc 0 错误"是在旧 base 上测的,rebase 后才暴露。

D.[噪音]两个空 retrigger commit(f0188ccee、05b5a09b4,CI 事件投递异常所致),下次 rebase 顺手清掉即可。

E.[非阻塞 P3 小疵,不影响正确性]:① raceWsOriginBound 的 20 秒 timer 未 unref()(有界、宿主进程本就保活,无害);② makeHttpDispatch 的 413/502 响应体缺 server.ts 在 #3776-subdefect-3 加的 upstreamFailure 诊断字段(sibling parity gap,可后续补);③ 20 秒超时路径无测试覆盖(需 timer mock);④ 降级用例标题里的 "warned once" 未断言(无日志捕获)。

F.[首条回复的重叠项,已自动消解]#4534(pluginLaneServerHistory seed):rebase 后该 seed 已在 master(rollout.yaml:52),本 PR 不再触碰 rollout.yaml;#4534 现在冗余,可由你关闭。

G. 作者注明的本地假红警告已核实:planNativePi 在存在 BILI_PROVIDER_REWRITES 时整体返回 off,残留环境变量确实会让模块级用例本地假红,CI hermetic 环境不受影响——说明属实。

收工判定

暂不合。代码本身(主修复 + docs seed + zh 再生成)质量达标,可以合;先决条件三件:① master 红(A)由你定夺处置;② B 的重复 commit 二选一;③ 按 B 的结果落 C 的那一行 .d.mts(或随 commit 一起移走)。三者清掉后本 PR 可直接合并,无需再过一轮实质审查。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: zhipuai-lb/glm-5.3)

收尾清理:同 issue 存在更新的 PR #4559。关单;误判请 reopen。

ranxianglei added a commit that referenced this pull request Oct 24, 2026
…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.
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 里)
antclt pushed a commit to antclt/billion-context that referenced this pull request Oct 25, 2026
…inline lane's pseudo-origin rewrite was dying on real DNS (ranxianglei#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 ranxianglei#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 ranxianglei#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 ranxianglei#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant