Repository navigation
feat: route pi native-mode Codex Responses WebSocket traffic through bili (#2111) - #2121
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2167-pr.2121.7aaa8daThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2121.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Review pass over the pi codex WS intercept (closes #2111). Three small findings fixed directly on the PR branch: 1. DeferredWebSocket.dispatchEvent ignored the on* handler properties: a client registered via ws.onclose = fn missed the synthetic close frame emitted when close() lands inside the deferred window (a real EventTarget fires listeners AND handler properties). Now invoked alongside the recorded addEventListener entries. 2. settle() let constructLive's last-resort throw escape as an unhandled promise rejection (void this.settle(rest)) — an unhandledRejection can crash the host process. Total construct failure now surfaces as a socket error event + abnormal close frame instead. 3. Aligned two misindented blocks in buildTop/routed (whitespace only). Tests: two regression tests added (onclose property delivery in the window; total-failure containment via a FakeWs ctorFail seam) — suite 19/19 green locally, typecheck clean.
The two agent-tree lines added by this PR started with a stray leading space, breaking the ASCII tree alignment. Strip it (no content change).
[bot] 🏷 Review 完成。我在 PR 分支上直接推了两个小修 commit(已验证、CI 全绿),结论如下。 顺手修掉的小问题(两个标注 commit,新 head
结构化七问
测试有效性:unit 19/19(含我补的两个有牙回归);e2e 用真 pi-stable@0.83.6 + 单端口双腿 mock(SSE zstd 契约、upgrade 503 拒绝模拟真实状态码语义、one-shot directive guard 防脚本模型死循环)零 token 覆盖 #2111 全部验收项:A fold/decompress 往返且后续请求反映、B auto 路由 + 给作者的一个开放问题(不阻塞): Residuals(与 PR 一致):Bedrock( 判定:可合(合并由人执行:https://github.com/ranxianglei/billion-context/pull/2121)。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.24-master.c7c10ba # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2111
What
Client-side WebSocket interception for pi's native mode: when pi's codex provider connects over WebSocket (
transport: "auto"default /"websocket"/"websocket-cached"), the model connection now routes through bili and gets an ACP session instead of bypassing the proxy entirely (the #2073 gap documented by #2080).src/agent/native-ws-intercept.ts(new): idempotent wrapper aroundglobalThis.WebSocket, installed next to the existing fetch intercept (same enable conditions and lifecycle inpi-native.ts). Only supported Codex Responses model URLs are rewritten —wss://chatgpt.com/backend-api/codex/responses→ws://<proxy>/bili/https://chatgpt.com/backend-api/codex/responses(scheme split per the feat: ACP-aware OpenCode V2 Responses WebSocket proxy + generic WS bridge shell (#1844/#1467) #1968 codec contract). Constructor args, subprotocols and request headers are preserved, so pi'ssession-id(= the pi session id, same value as on the SSE leg) and thex-bili-plugin*stamps ride the upgrade unchanged. Non-model WS, already-routed URLs and self-origin traffic pass through verbatim. While the proxy origin is not settled yet, a deferred facade shell preserves listener/send/close semantics until bootstrap resolves (degrades to direct with a logged warning if it never does).installWebSocketBridge+codexResponsesCodec(feat: ACP-aware OpenCode V2 Responses WebSocket proxy + generic WS bridge shell (#1844/#1467) #1968) admit the connection and run it through the same pipeline (witness feed, preflight, nudge, billing, ACP).Behavior change (old → new)
auto/websocket/websocket-cached: old = WS traffic bypassed bili entirely while the handshake succeeded (documented limitation, [Pi] 原生入口 fetch-only 拦截漏掉 WebSocket 模型流量:Codex provider auto 模式直连上游,工具已注册但会话状态未建立 #2073/docs: pi 原生模式传输覆盖说明与 WS 绕行配置(#2073) #2080); new = intercepted and routed through/bili/with a full ACP session. This is the point of the issue.auto: old topology = client-side handshake failure → pi's same-turn SSE fallback. New topology = the client handshake targets the local proxy (always succeeds), so an upstream refusal surfaces as a mid-stream transport failure (no same-turn fallback). Explicitsseremains the deterministic escape hatch and is behaviorally unchanged (scenario D regression-guards it).Config surface
None. No new config-file fields, env vars or CLI flags. The E2E gate
ACP_TEST_E2E_PI_WSplusE2E_PI_BIN/E2E_TMOare test-harness-only knobs documented intests/e2e/README.md, following the existing real-client lane convention.Verification
tests/native-ws-intercept.test.ts(17 tests: claim predicate, rewrite shape, idempotency, passthrough, deferred-shell semantics, third-party constructor adoption, reset) — green.tests/e2e/e2e-pi-codex-ws.test.ts, gated, zero tokens, deterministic mock upstream speaking both legs through the real built proxy): 6/6 scenarios — explicit-websocket fold/decompress round trip; auto routing +previous_response_idcontinuation expansion; upstream-refusal behavior + sse unaffected; explicit-sse regression guard; two concurrent subagent-style sessions sharing one proxy with identical tool args and no cross-talk..github/workflows/ci-e2e-pi-ws.ymlmirrorsci-e2e-native.yml(pinspi-stable@0.83.6).Residuals: Bedrock (
bedrock-converse-stream) stays out of scope per the issue (no custom headers on its upgrades — needs a dedicated proxy-side codec; remains tracked under #2073). The Bun runtime leg is argued from pi's constructor-caching timing analysis (Bun caches its subclass at first call, so load-time install precedes it); local e2e runs on Node 22.