Repository navigation
fix(opencode-native): proxy 不可用时超窗请求本地拒发,不再静默直连撞上游 400 - #3318
Conversation
…he proxy is unavailable (#3308) The V2 native route's degrade branch sent every model request direct (uncompressed) whenever no live proxy existed — documented as an availability fail-open. But per the #2924 ruling (always compress OR always refuse), a body that provably cannot fit the model's context window must not ride that fallback into a guaranteed upstream 400; on an over-window session history that 400 then repeats on every later turn until restart (the reported field failure). Apply #2924's refuse-oversized arm to this lane: when resolveLive() finds nothing healthy, measure the body through a clone (original stays sendable) and compare the FLOOR estimate (bytes/4) against the model's window from the plugin's own catalog harvest — same conservative math as the dsh gate, so unknown window/model/body keeps the fail-open and the guard cannot false-refuse. A hit throws a host-visible retryable error (opencode v2 turns http.request hook failures into model-request failures, verified against @opencode/cli 2.0.29 source) plus a one-time bili.log diagnostic. The window map is primed before the route decides (native mode only) so the guard arms from the second request even when bootstrap never landed.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3916-pr.3318.59509faThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3318.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。检索 open/closed issues 与全部 open PR:无其他条目处理「opencode V2 native 车道 proxy 不可用 + 超窗直发 400」;#3292 是增量 turn 压缩(机制不同),#3308 是本 PR 的原 issue。 ① 是什么问题 ② 什么原因导致的 ③ 影响范围与严重程度 ④ 怎么修复的
⑤ 是否有回归问题
⑥ 是否破坏缓存 ⑦ 是否改了设计方向 ⑧ 是否引入新配置 结论:代码可合。方向正确(疏而非堵:修的是「裁定漏落」这个根因,判定标准与 #2924 逐字一致,保守 floor 不误拒,fail-open 面完整保留)、测试有牙(guard 或 ordering 任一回归都会红)、本地 typecheck clean + 定向套件 75/75、CI 红全部为既有签名(#3314/#3317 待合 + AC12 flake)与本 diff 无关。本 PR 涉及 fallback 行为变更,按 §7.4 属人工合并范畴——请自行合并:#3318 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.483-master.d8c0e50 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Fixes #3308
问题
opencode v2 plugin-native 车道(
createNativeRoute)在 proxy attach/spawn 未就绪时,把所有模型请求静默直连(未压缩)——文件头文档化的可用性 fail-open。长会话的 raw 历史(~1.05–1.09M tok)超过 deepseek-flash 1,048,576 窗口后,直发必然被上游 400;且历史只增不减,此后每一轮都 400,直到重启进程。字段证据:18 次降级信号、5 次配对上游 400、失败回合在 bili.log 零痕迹。根因与修法
#2924 已确立裁定「要么一定压缩,或者一定拒绝」,dsh fetch 车道按此实现了
refuse-oversized臂;但 opencode V2 车道的降级分支完全绕过了 gate 机制,漏掉了同一裁定。本 PR 把该裁定补到这条车道:src/agent/opencode-native.ts—createNativeRoute降级分支加超窗拒发臂:resolveLive()无活 proxy 时,克隆请求体测字节数(原始 Request 保持可发送),对照插件自己从ctx.model.list()采集的模型窗口做与 [dsh-native] takeover-gate refusal (threw state) fails open with the FULL uncompressed transcript; a >window local history dies upstream with 400 (maximum context length) #2924 完全相同的保守判定——ceil(bytes/4) > window才拒(floor 估计不会误拒;[dsh-native] takeover-gate refusal (threw state) fails open with the FULL uncompressed transcript; a >window local history dies upstream with 400 (maximum context length) #2924 ledger 实证真实 body 高于 floor ~1.14×)。命中则抛出带完整信息的错误(估算 token vs 窗口 + 「恢复中,稍后重试或开新会话」)+ 一次性 bili.log 诊断。窗口未知 / body 不可读 / 未超窗 → 保持原 fail-open 直连(可用性设计不动)。packages/core/src/session/model-request.ts:343-364确认:hook 触发与发送在同一 Effect 内,失败即请求失败(与上游 400 同通道),不会崩进程。src/agent/opencode-v2.ts— 原生模式把窗口采集提前到 route 之前:覆盖「bootstrap 从未成功的新会话」——catalog 应答快时第 1 个请求即可判定,慢时第 2 个请求起生效。launcher 模式顺序不变(无 proxy 时采集只会产生误导性告警)。行为变更披露(旧 → 新 + 原因)
bili: proxy unavailable and this request cannot be sent uncompressed — body ~N tok … exceeds the <model> context window (M); … retry shortly, or start a fresh session,该回合以可见错误结束;bili.log 记一条一次性诊断。Config surface
不涉及——无新增 env/config/CLI flag。判定用的窗口来自插件既有的
ctx.model.list()采集通道(x-bili-plugin-context-window同源)。验证
不在本 PR 范围(已在本 issue 记录为子缺陷清单)