Skip to content

[PR] fix(opencode): inline mode keeps the real upstream URL on the wire (#5931) - #5938

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-08_opencode-inline-bypass
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-08_opencode-inline-bypass

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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 setting BILLION_CONTEXT_PLUGIN=0 fixes it.

Root cause: effect 4.1.0 caches the native fetch in FetchHttpClient.Fetch on 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 — 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, 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:

  • In inline mode the V2 route no longer rewrites e.request.url to the pseudo-origin. It keeps the REAL upstream URL and pins state.proxyBase = INLINE_ORIGIN exactly as before — all x-bili-* stamping, conditional tools, fork adoption and incremental logic are 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 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).
  • New NativeInterceptState.chainEgressSeen flag, set at the single noteDispatchMode("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)

  1. Inline wire bytes: the host now sees the REAL upstream URL on its outgoing Request (was: 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.
  2. NEW degradation path when the host fetch bypasses our chain: direct uncompressed send to the real upstream (custom x-bili-plugin* headers reach the upstream harmlessly) instead of hard failure (302 HTML / finish_reason loop).
  3. Signed bodies in inline mode now pass through the intercept's bili 改写带 body 签名的模型请求,CodeArts(华为 APIG SDK-HMAC-SHA256)全部 401 #1884 resign/refuse gate (previously the route-side rewrite skipped it → silent upstream 401). Improvement.
  4. noteRoutedOrigin no longer records INLINE_ORIGIN for normal inline traffic; its only consumers are attach-mode recovery paths, so this is inert.
  5. Inline incremental seed swap is enabled only after the first observed chain-carried model send (no-op in working steady state; cost in a broken→recovered session is one deferred seed turn).
  6. Inline /responses WS lane: previously rewrote e.url to a pseudo-ws form that could never connect (no WebSocket intercept is installed for opencode — pi only), so those connections failed DNS today anyway; now e.url stays 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

Closes #5931

…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.
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-08_opencode-inline-bypass (71c9b99)

Latest build — install this exact version

npm install -g billion-context@0.0.8615-pr.5938.0b60be9

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
71c9b99 billion-context@0.0.8615-pr.5938.0b60be9 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr5938.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(opencode): inline mode keeps the real upstream URL on the wire (#5931) [PR] fix(opencode): inline mode keeps the real upstream URL on the wire (#5931) Nov 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant