Repository navigation
[PR] fix(#4121): opencode V2 direct-degrade gate — media-aware two-stage byte judgment - #4382
ranxianglei wants to merge 1 commit into
Conversation
…ia as text The opencode V2 native degrade gate (oversizeDirectRefusal) priced the raw body byte count / 4 as an optimistic token floor, so inline base64 images (resolution-billed upstream, ~2-4 KB/token vs ~6.8 B/token text) minted phantom text tokens and false-refused media-heavy requests during the direct-degrade window (proxy down / busy-exhausted) even though upstream would accept them. Third instance of the same root mechanism as the dsh takeover gate fixed in #4119/#4111. Reuse #4119's media-aware two-stage predicate (mediaBytesOfWireBody + bodyProvablyOverWindow) so both lanes share ONE judgment: stage 1 keeps the raw bytes/4 fast screen (unchanged for pure-text bodies); stage 2 runs only on the would-refuse path and re-prices on media-EXCLUDED core bytes, disarming the refusal when the text alone fits. bodyProvablyOverWindow gains an optional { applyFloor } flag. dsh callers pass nothing -> the #4079 max(declared, 1M) floor still applies (zero change). The opencode arm passes applyFloor:false because s.windows is a MEASURED lane window, not a host declaration -> preserves this lane's existing bar verbatim (flooring a measured window would be a behavior change, tracked separately). Both refusal wording branches (busy-exhausted #3654 and proxy-down #3308) share the math and the fix; error text now reports core bytes and the media mass excluded when nonzero. Tests: media-heavy body rides direct (both branches); over-limit text still refuses (teeth); image + huge-text still refuses and reports excluded media.
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 本 PR 是 #4119(dsh 车道)同机制的第三处实例,落在 opencode V2 native 车道的 结构化八问
决策点 #1(opencode 臂要不要加窗口地板)我独立评估后认同 PR 的建议:保持不加( 相关观察(PR 已记录于 #4121,不在本 PR 修)服务端 CI 状态与合并判定
结论:代码与测试我判可合(逻辑成立、双向有测试、typecheck 干净、dsh 臂零回归)。但合并门禁要求 rebase 到最新 master + CI |
|
(ai: zhipuai-lb/glm-5.3) 陈旧票清理(第三批动作①):目标 issue #4121 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。 |
Third unpatched instance of the #4111 bytes/4 media-as-text false-refusal, on the opencode V2 native lane. Reuses the exact two-stage predicate that #4119 landed for the dsh takeover gate, so both lanes now share ONE media-aware judgment.
What was wrong
oversizeDirectRefusal(src/agent/opencode-native.ts) priced the raw request-body byte count / 4 as an optimistic token floor and refused locally whenever that floor exceeded the model window. Inline base64 images cost ~2–4 KB/token upstream (resolution-billed) vs ~6.8 B/token for text, sobytes/4wildly overbilled them: during the direct-degrade window (proxy down, or busy-exhausted / saturated event loop) a media-heavy session was refused locally ("body ~N tok exceeds context window") even though upstream would accept it. Pure-text bodies were unaffected. Both wording branches shared the math (#3654busy-exhausted and#3308proxy-down).Fix
Reuse #4119's exported
mediaBytesOfWireBody+bodyProvablyOverWindowfromsrc/agent/dsh-native.ts:bytes/4fast screen (byte-identical result for pure-text bodies);bodyProvablyOverWindowgains an optional{ applyFloor }flag:#4079 max(declared, 1M)floor still applies → zero behavior change on the dsh arm;applyFloor:falsebecauses.windowshere is a measured lane window, not a host declaration → preserves this lane's existing bar verbatim.Both refusal branches updated; the error text now reports core bytes and the media mass excluded (when nonzero).
Behavior changes (old → new)
bytes/4overbilled them (the bug)floor estimate N B/4core est N B/4[ , X B media excluded]applyFloordefaults to the floored pathNo config surface change. No new env var. No kernel change.
Open question for owner (decision point #1)
Shipped without a window floor on the opencode arm (minimal surface — fixes only the media mispricing). The dsh arm carries a
max(declared, 1M)floor (#4079); the opencode arm uses the measured lane window with no floor. Adding a floor to a measured window would be a behavior change beyond this bug. If wanted, it is a one-line flip (applyFloor:false→ omitted). Recommend keeping it off for now.Related observation (recorded in #4121, not fixed here)
Server-side
estimateRawBodyTokens(src/preflight.ts) exclusion set does not recognize the responses-wireinput_image.image_urlstring form, so such images double-count in the#554side-request adaptation (conservative side-request, not a false-refusal; different subsystem). Same root mechanism (media-shape recognition missing the string form); align together later.Closes #4121