Repository navigation
[PR] fix(opencode): inline mode keeps the real upstream URL on the wire (#5931) - #5938
Open
ranxianglei wants to merge 1 commit into
Open
ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
…rigin (#5931) opencode v2.2.6 (effect 4.0.6 -> 4.1.0) caches the native fetch in FetchHttpClient.Fetch on first resolution; early host requests resolve it before the plugin's fetch patch installs, so later model requests leave through the unpatched fetch while createNativeRoute had already rewritten their URLs to http://billion-context.inline/bili/<url> — bypassed pseudo-origin traffic gets a 302 HTML page instead of SSE, producing "OpenAI Chat stream ended without finish_reason" and endless retries. Fix (B'): in inline mode the V2 route no longer rewrites e.request.url to the pseudo-origin — it keeps the real upstream URL and pins proxyBase as before, so all stamping/tools/fork/incremental logic is unchanged. The installed fetch chain's existing model-API branch performs the `${origin}/bili/${url}` rewrite for any model URL that actually passes through it (the pi inline lane already routes this way). A host whose fetch bypasses the chain now degrades to a direct uncompressed send instead of voiding its requests. New NativeInterceptState.chainEgressSeen flag (set at the single noteDispatchMode("proxy") chokepoint) lets the opencode incremental lane swap its lane-only envelope only after at least one chain-carried model send has been observed; a bypassing host keeps sending full-resend bodies the upstream understands. Working hosts are byte-identical to before. Tests: tests/issue5931-opencode-inline-bypass.test.ts (route keeps real URL, gate scope, incremental evidence gate both directions); #4669 composition test updated to install the full production chain.
Contributor
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8615-pr.5938.0b60be9This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5938.tgz
npm install -g packageInstall instructions are refreshed on each push. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
opencode v2.2.6 (effect 4.0.6 → 4.1.0) broke all model requests in bili inline mode (
"opencode": { "inline": true }):OpenAI Chat stream ended without finish_reason, ~10 retries / ~84 s. Rolling back to v2.2.5 or settingBILLION_CONTEXT_PLUGIN=0fixes it.Root cause: effect 4.1.0 caches the native
fetchinFetchHttpClient.Fetchon first resolution. Early host requests (startup / MCP wiring) resolve it BEFORE the plugin's fetch patch installs, so later model requests leave through the unpatched fetch — whilecreateNativeRoutehad already rewritten their URLs tohttp://billion-context.inline/bili/<url>. Bypassed pseudo-origin traffic gets a 302 HTML page instead of SSE, hence the endless retry loop. Reporter's packet capture plus zero forward records in bili.log during the failing window confirm the requests never reached the engine.Fix (B′)
Stop depending on WHICH fetch the host uses:
e.request.urlto the pseudo-origin. It keeps the REAL upstream URL and pinsstate.proxyBase = INLINE_ORIGINexactly as before — allx-bili-*stamping, conditional tools, fork adoption and incremental logic are unchanged.${origin}/bili/${url}rewrite for any model URL that actually passes through it (the pi inline lane already routes entirely this way — it has no per-request hook at all). A host whose fetch bypasses the chain now degrades to a direct uncompressed send instead of voiding its requests (the canonical degraded posture).NativeInterceptState.chainEgressSeenflag, set at the singlenoteDispatchMode("proxy")chokepoint (covers every success site; live-slot discipline per [BUG] DSH 插件热替换后 fetch 拦截仍绑在旧模块实例上 → 模型请求全部直连、压缩静默失效直到重启 #3394). The opencode incremental lane may swap its lane-only envelope only after at least one chain-carried model send has been observed; until then a bypassing host keeps sending full-resend bodies the upstream understands. Working hosts see zero delta: turn 1 is always a full resend that passes the chain, so the flag is set before turn 2's hook runs.Behavior changes (old → new)
http://billion-context.inline/bili/<url>). Engine input is byte-identical — the chain's model branch builds the same${origin}/bili/${url}target. Observable only in host-side captures.x-bili-plugin*headers reach the upstream harmlessly) instead of hard failure (302 HTML / finish_reason loop).noteRoutedOriginno longer records INLINE_ORIGIN for normal inline traffic; its only consumers are attach-mode recovery paths, so this is inert./responsesWS lane: previously rewrotee.urlto a pseudo-ws form that could never connect (no WebSocket intercept is installed for opencode — pi only), so those connections failed DNS today anyway; nowe.urlstays unchanged → direct uncompressed. Improvement, documented here.Residual (NOT fixed here, different seam): the V1 opencode lane bakes
${INLINE_ORIGIN}/bili/<url>into the provider baseURL via config overlay — same bypass class, needs a separate fix if V1 inline users hit it.Tests
tests/issue5931-opencode-inline-bypass.test.ts: inline route keeps real URL + pins proxyBase (discriminating vs pre-fix); non-inline origin still rewrites (gate scope); incremental evidence gate both directions (no swap without observed egress; swap proceeds after one chain-carried send through the installed intercept).tests/opencode-native.test.ts[PR] pi inline full rollout: fixed real-device stream drops + default to in-process engine (previously scattered across unmer | pi inline 全套落地:修好真机断流 + 默认走进程内引擎(之前散在未合并的 #4527/#4571 里) #4669 composition updated: it asserted the removed route-side rewrite; it now installs the full production chain (intercept + inline link) and asserts the engine receives the SAME input as before (${INLINE_ORIGIN}/bili/<url>lands on the engine via the chain).Closes #5931