Repository navigation
[PR] fix(opencode-v2): stop rewriting the shared http.request payload — route model traffic at fetch time (#4276) - #4280
ranxianglei wants to merge 4 commits into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.5096-pr.4280.abe84c2This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4280.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ute model traffic at fetch time (#4276) The V2 opencode entries (native + launcher) rewrote event.request.url in place inside their unscoped http.request hook. opencode hands that one mutable event to every matching hook — provider-ID-scoped plugins included — so URL-validating provider plugins saw the proxied <origin>/bili/<upstream> URL instead of the real upstream: Kiro's AWS bridge silently never engaged (empty assistant replies), Antigravity's request hook threw on the non-canonical origin. Root fix: the routes keep only discovery/degrade (resolveLive -> proxyBase, oversize local refusal); both setup()s now install the shared native fetch intercept chain which performs the rewrite at fetch time, leaving every hook-visible payload untouched. The WS handshake hook builds its tunnel itself (byte-identical output for formerly-working shapes). Also honors providers.<url>.direct in these lanes (previously ZCode-only): the hook marks exempt requests (no stamping/incremental/ws-tunnel) and the chain sends them direct before any proxy resolution. No new config surface — completes the documented field in the opencode lanes. Behavior changes: provider plugins now see original upstream URLs (the fix); signed-body model requests in the V2 lane get the local #1884 refusal instead of unsigned-through-bili -> upstream 401; #3304 prepareDirectSend + #3248 onResponse acks activate in V2 processes (were dead code); launcher dead-origin handling moves from preemptive unwrap to chain recover/retry/give-up-direct. Closes #4276
…fetch-time routing The fetch-time routing change removed every call site of replaceRequestTarget in src/agent/opencode-native.ts and src/agent/opencode.ts but left the exported declaration in place, tripping the CI unused-exports gate (DEAD). Delete it.
58958af to
968ab10
Compare
… exemption The shared state carries directPrefixes to BOTH chains each entry installs (V1 server() + V2 setup), so the exemption is honored on V1 hosts as well; the previous sentence named the V2 lanes only.
(ai: vllm-qwen/qwen3.8-27b) 审核完成。结论先行:方向正确、机制成立;已顺手修掉两处小问题(死导出致 CI 红 + 文档少报覆盖面),新 head CI 绿后可合。 查重: 不重复——#4276 是此症状下唯一的 open 条目,本 PR 正是它的修复 PR;其余 Antigravity 相关条目(#3129/#3142/#3280/#3282)是代理侧 v1internal 信封拆包问题,机制与症状均不同。 标签: bug, opencode, opencodev2, scope/wiring, p2(已打)——opencode V2 车道真实缺陷、破 provider-scoped 插件,但有绕行(BILLION_CONTEXT_PLUGIN=0),p2。 验证证据
八问
行为变更清单(旧 → 新 + 原因)
判定代码与测试通过审查,发现的两个小问题已就地修掉并独立标注。等新 head CI 全绿即可合并。 |
The new tests/issue4276-opencode-v2-hook-payload.test.ts spawns a child process (spawnSync node --import tsx for the setup() install-gate probe), so the run-ci-tests.mjs #1248 tripwire requires it in the shared LIVE_FILES table; without that every shard die()s before running any test. Concurrency review: the probe is a short-lived SYNCHRONOUS child (120s cap) driving the real entry's setup({}) in attach mode against a local listen(0) probe server - no proxy fork, no fixed-port daemon; all ports in the file are ephemeral and XDG_STATE_HOME is mkdtemp-isolated, so its zone band goes unused harmlessly.
(ai: vllm-qwen/qwen3.8-27b) 补充一条:新 head 的主 CI test lane 红了,根因是一个几行级遗漏——新增的 tests/issue4276-opencode-v2-hook-payload.test.ts 用 spawnSync 起子进程做 install-gate 探针,但没登记进 scripts/live-files.mjs 的 LIVE_FILES(#1248 tripwire),导致 6 个 shard 在跑任何测试之前就 die()。已就地修掉并推上分支(commit b8e17d3):并发面核对过——该探针是短命同步子进程(120s 上限)、attach 模式打本地 listen(0) 探针服务器、无 proxy fork、全文件端口皆临时、状态目录 mkdtemp 隔离,登记后其 zone band 闲置无害。等这轮 CI 结果。 |
(ai: vllm-qwen/qwen3.8-27b) CI 全绿确认:最终 head(b8e17d3,含 LIVE_FILES 登记修复)在 master 上的合并 ref 37810b5 全部 10 个 workflow 通过——主 CI(unused-exports gate + 6 个 test shard 全量回归)、e2e 全部车道(含真实客户端 e2e-native-opencode)、Windows codex overlay、build artifact。无红项。 分支最终形态(master + 4 commits):
审核结论维持首条回复(八问 + 行为变更清单):未发现无意回归,可合并。合并动作按规矩留给你:#4280 |
|
(ai: zhipuai-lb/glm-5.3) 陈旧票清理(第三批动作①):目标 issue #4276 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。 |
…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
…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
What & why
Closes #4276 — opencode lane: native /bili/ URL rewrite breaks provider-scoped plugins (Kiro silent empty reply, Antigravity baseURL error).
Both opencode V2 entries (native
src/agent/opencode-native.tsand launchersrc/agent/opencode.ts) rewroteevent.request.urlIN PLACE inside their unscopedhttp.requesthook. opencode dispatches ONE mutable event object to every matching hook — including provider-ID-scoped hooks from other plugins AND opencode's own built-in provider hooks (verified against the opencode 2.x binary: the host sends the post-hook request through a call-time-resolvedglobalThis.fetch; provider SDKs use lazy thunks() => globalThis.fetch, no node:undici). URL-validating provider plugins therefore saw the proxied<origin>/bili/<upstream>URL:@servoy/opencode-kiro-auth): response-hook gateq.*.amazonaws.com|runtime.*.kiro.devfailed → AWS bridge never engaged → raw OpenAI-shaped POST hit AWS → non-SSE 200 → retries → silent empty assistant message.@cortexkit/opencode-antigravity-auth): request hook requires origin ===generativelanguage.googleapis.com→ threw on the proxied URL.Root fix: the shared hook payload is no longer bili's scratch space. The routes keep only discovery/degrade (
resolveLive→s.proxyBase, #1958 conflict warning, #3308/#3654 oversize local refusal); both entries'setup()now installs the existing shared native fetch intercept chain (installNativeFetchIntercept), which performs the<origin>/bili/<url>rewrite AT FETCH TIME. Every hook-visible payload keeps the original upstream URL. The WS handshake hook builds its tunnel itself now (raw-model-URL branch produces byte-identical output to the old rewrite+replace pipeline; already-routed URLs keep the old conversion verbatim).Second half of the issue:
providers.<url>.direct(documented ACTIVE client exemption, previously ZCode-lane only) is now honored in the opencode lanes too — the hook marks matching requests (biliDirect: no stamping, no incremental body swap, no ws tunneling) and the chain sends them direct before any proxy resolution (once-per-prefix log).Config surface
No new fields. This completes an EXISTING documented field (
providers.<url>.direct, CONFIGURATION.md) in a lane that ignored it. The doc section now lists the new lane coverage. No migration needed.Behavior changes (old → new)
prepareDirectSendbody restore + Delta lane: native-mode clients send only deltas, server maintains full state + one-time fold, upstream receives snapsho | 增量车道:native 模式客户端只发增量,服务端全量维护+一次折叠,上游只收快照(#2926 的泛化) #3248 incremental acks (onResponse) activate in V2 processes — these wirings were dead code in V2 before (chain absent); they now cover the degrade/fallback paths only.directmatch in the opencode lane (same boundary class as the ZCode store lane).Verification
tests/issue4276-opencode-v2-hook-payload.test.ts: hook payload immutability + fetch-time routing; Antigravity pool-endpoint passthrough (byte-identical, unproxied); direct exemption; install-gate directions via child-process probe (default installs,BILLION_CONTEXT_PLUGIN=0fully inert).tests/opencode-native.test.ts: 9 contract assertions flipped (hook leavese.requestsame object + original URL;proxyBasecarries the routed origin).tests/opencode-launcher.test.ts: lifecycle tests now drive REAL fetches through the installed chain against recording servers (steady-state routing, native attach 模式(opencode 面)同样缺运行时 respawn:V2 route hook fail-closed + V1 launcher 插件 frozen origin #1135 death-respawn re-target, failed-respawn direct send via local upstream recorder — no real network).