Repository navigation
fix(#1958): bind V2 hook proxyBase to the baked origin on already-routed model requests - #1959
ranxianglei wants to merge 1 commit into
Conversation
…ted model requests createNativeRoute recorded the pinned origin via noteRoutedOrigin but then exited before initializing s.proxyBase (isModelApiUrl is false for /bili/ paths), so the generic V2 http.request hook never stamped x-bili-plugin / conversation / window / output headers on pre-routed sessions — the proxy ran them as plain-client proxy-mode traffic while the ACP-native agent believed it owned compression (#1365 pinned-channel semantics kept the URL untouched; this binds stamping without touching the URL). Bind s.proxyBase to new URL(url).origin — the origin baked into the request URL, NOT lifecycle state.origin (which may point elsewhere) — and skip resolveLive/rewrite: a pinned channel must not follow a replacement instance (#1365/#1370). Launcher lane (opencode.ts) and the shared fetch patch already handled pre-routed URLs; only this native V2 route had the gap.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1964-pr.1959.e9e7a80This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1959.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR Review — fix(#1958): bind V2 hook proxyBase to the baked origin on already-routed model requests 已按 review 规范完整审查(方向 → 回归清点 → 代码 → 测试有效性 → diff 整洁度),并本地做了定向验证。结论:可合并(待 CI 全绿;按 §7.4,wire/message-shape 变更必须人工合并)。 结构化七问1. 是什么问题 2. 什么原因导致的 3. 怎么修复的 4. 是否有回归问题
5. 是否破坏缓存 6. 是否改了设计方向 7. 是否引入了新的配置 验证证据(本地定向,全量交 CI)
收工判定:通过,可合并(wire-shape 变更,按 §7.4 留给人工合并)。 |
[bot] 🏷 CI 跟进:head review 结论维持:可合并(wire-shape 变更,按 §7.4 由人工合并:https://github.com/ranxianglei/billion-context/pull/1959)。 |
…e config — expose, don't absorb, don't gate install Maintainer direction change on ranxianglei#1958: the 'native plugin + hand-written /bili/ provider baseURL' combo is a conflicting configuration (two access paths claiming routing ownership of the same requests). The correction is a loud runtime warning — not silent compat (no stamping/rewrite, the request stays on the plain-proxy path it encodes) and not an install-time refusal (a scanner false positive would permanently block installs). - src/agent/opencode-native.ts (createNativeRoute): on a pre-routed model URL, warn once per (session, origin) unless BILLION_CONTEXT_PROXY pins the SAME origin (supported attach posture — compared via URL.origin so trailing-slash/default-port spellings fold; env, not state.origin, because attach arming does not freeze state.origin synchronously). No behavior change to the request itself: ranxianglei#1365 pinned-channel recording (noteRoutedOrigin) and the isModelApiUrl fall-through are untouched; s.proxyBase stays unset for pre-routed URLs. - tests/issue1958-routed-warn.test.ts: 4 cases — dedup per (session, origin) + no stamping; benign pin silent incl. port folding; mismatched pin warns; non-model /bili/ paths and /__bili/health never warn. - CLIENTS(.zh-CN).md / CONFIGURATION(.zh-CN).md: the three OpenCode access paths are mutually exclusive; runtime warning + fix-it guide documented. Supersedes ranxianglei#1959 (silent stamping) and ranxianglei#1972 (install refusal + stamping).
Closes #1958
Problem
OpenCode V2 native entry (
src/agent/opencode-native.ts,createNativeRoute): model requests that ALREADY carry a/bili/prefix (origin baked into the URL by config/overlay) skips.proxyBaseinitialization. The routed gate records the pinned origin vianoteRoutedOrigin, then exits early becauseisModelApiUrl()is false for/bili/paths — correct for avoiding a double URL rewrite, but it leaves the hook state unbound. The generic V2http.requesthook requiresstate.proxyBasebefore stamping (opencode-v2.tshttpRequestHook), so every request of such a session arrived at the proxy WITHOUTx-bili-plugin/x-bili-plugin-conversation/ context-window / max-output markers.Consequences on the server side:
pluginMode = pluginAgent !== undefined(server.ts) → the session ran as plain-client proxy mode (server-side compression, nudge injection, acp_summary carrier) while the ACP-native agent believed it owned compression locally (KDD "Two compression modes").x-bili-plugin-conversationis ignored for identity resolution without the plugin marker (session-id.ts).The launcher lane (
opencode.tsroute) and the shared fetch patch both handle pre-routed URLs correctly; only this native V2 route had the gap.Fix
In
createNativeRoute, when the URL is already routed: afternoteRoutedOrigin, bind the hook's stamping base to the origin baked into the request URL (new URL(url).origin) and return.Deliberately NOT via
resolveLive/rewrite:state.originmay point elsewhere — the request URL is authoritative for where THIS traffic rides;state.originis not modified here (hook state only).Behavior change (intended)
Pre-routed OpenCode V2 native sessions: model requests previously carried NO plugin identity headers (proxy treated them as plain clients → proxy-mode compression binding) → now carry
x-bili-plugin: opencode+ conversation/window/output markers bound to the baked origin (plugin-mode binding, as designed). No URL rewrite, no respawn, no config surface change, no persistence/wire-format change beyond the intended headers.Tests
New
tests/issue1958-routed-session.test.ts(4 cases):null !== 'opencode');state.origin; zero respawns triggered;/bili/…/v1/modelsand/__bili/healthstay unbound and unstamped.Updated
tests/opencode-native.test.ts("route: non-model-API and already-routed URLs are left untouched") — its final assertion (s.proxyBase === undefinedafter a routed URL) encoded the bug; it now asserts the baked origin binds while the request reference stays untouched, and pins non-model URLs as unbound separately.Verified locally: targeted suites green (issue1958 + opencode-native + opencode-v2: 33/33), typecheck clean, build OK. Full suite → CI.