Skip to content

fix(agent): gate opencode native route behind nativeActive (#840) - #842

Merged
ranxianglei merged 1 commit into
2026-09-15_opencode-native-pluginfrom
2026-09-16_840-coexistence-audit
Sep 17, 2026
Merged

ranxianglei merged 1 commit into
2026-09-15_opencode-native-pluginfrom
2026-09-16_840-coexistence-audit

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

#840 audit fix (a): gate the opencode native entry's traffic-touching route/setup creation on nativeActive, mirroring pi's gated fetch intercept (src/agent/pi-native.ts).

Under a bili opencode launch the launcher owns the proxy; the native entry previously still created its http.request route unconditionally. The idle route never rewrote anything (no origin to probe), but on HTTPS (cert-MITM) launches it fired one misleading proxy unavailable — model requests go direct (uncompressed) line even though the launcher's proxy was compressing fine.

With this change the overlap-mode export degrades to exactly the launcher-mode shape (src/agent/opencode.ts): no route → no probing, no rewriting, no warning; header stamping falls back to /bili/-URL or BILLION_CONTEXT_PROXY env detection, which is correct in overlap mode (both plugins stamp identical values — the known harmless redundancy of #840 gap 3).

Why not fully inert the export (which would also fix gap 3): that changes behavior for manual-BILLION_CONTEXT_PROXY edge users (they currently keep native tools via env detection) and exceeds the scope of (a) as scoped in the issue. Gap 3 stays deferred for owner decision.

Per-seam tests (owner constraint: per-seam e2e before merging)

  • tests/opencode-native-overlap.test.ts — evaluates the REAL native entry under a launcher env (BILLION_CONTEXT_PROXY + BILI_PROVIDER_REWRITES): request reference untouched across hook fires, zero proxy unavailable / bili-native warnings, launcher-mode header stamping intact (env-detection and /bili/-wrapped URL cases). Regression proof: with the source fix stashed, this file FAILS (the spurious warning fires); with the fix, green.
  • tests/pi-native-overlap.test.ts — real pi native entry under both launcher-env variants: global fetch NOT patched (intercept flag absent, fetch identity unchanged), no native host marker, plugin export unconditional. Codifies the hands-on pi-seam verification (passes pre-fix too — pi's seam was already correctly gated).

Hands-on verification (real binaries, local upstream)

  • pi seam: overlap run (native plugin installed + bili pi) — single proxy instance, compression active (prefix-affinity chain advancing, high cache-hit ratio), zero bili-native: lines in any log. Confirms the code-read inference: pi overlap is fully silent (fetch intercept never installed).
  • opencode seam: canonical overlap run from a clean cwd — the forwarded request at the upstream carries the proxy's x-bili-hop / x-bili-tunnel stamps (via-proxy proven), single proxy, no double spawn, zero spurious warnings post-fix.

Pre-flight

  • npm run typecheck — clean
  • npm test — 1654 pass / 0 fail / 2 skipped (ACP_TEST_E2E-gated e2e)
  • npm run build — success

Stacks on PR #824 (base = 2026-09-15_opencode-native-plugin) because the native-mode entries are not on master yet; rebase onto master once #824 lands.

Fixes #840

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,这是 agent 已完成的 [PR],按规范不重做——正在核对分支代码、跑 pre-flight(typecheck/test/build)、检查 CI 状态,结论稍后回复。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Verified — no rework done (per [PR] protocol: audited code + CI + reproduced pre-flight instead of redoing).

Diff cleanliness: single commit, 3 files, +164/−1 — every line serves the stated purpose. The source change is 3 lines of logic (src/agent/opencode-native.ts:178-180): route creation gated behind nativeActive, export degrades to bare createOpencodeV2Setup() (launcher-mode shape) otherwise. Plus the two per-seam test files. No stray files, no whitespace churn.

Correctness (code read):

  • nativeActive (= nativeBootstrapGate(env, "BILI_NATIVE_OPENCODE")) is false exactly when a launcher owns the proxy (BILLION_CONTEXT_PROXY / BILI_PROVIDER_REWRITES) or on opt-out — the same gate the bootstrap block above already uses (src/agent/opencode-native.ts:159-169). The export shape now matches bootstrap behavior instead of diverging from it.
  • In overlap mode the shared V2 setup falls back to /bili/-URL or env detection for header stamping — identical values to launcher mode (the known-harmless [coexistence] cross-host dual-mode (launcher vs native) isolation audit — per-seam verification + opencode spurious-warning wart #840 gap-3 redundancy), so no stamping regression.
  • Gap 3 deferral (not fully inverting the export) is correctly scoped: full inversion would change manual-BILLION_CONTEXT_PROXY edge users who currently keep native tools via env detection. Deferred for owner decision, as documented.

Local pre-flight at head b7a26fd (detached checkout, Node 22 / Linux):

  • npm run typecheck — clean
  • npm test — 1654 pass / 0 fail / 2 skipped (ACP_TEST_E2E-gated) — matches the PR's claim exactly
  • npm run build — success
  • Both new seam tests pass individually.

Regression proof reproduced: restored the pre-fix src/agent/opencode-native.ts from base 54f8fb2 → tests/opencode-native-overlap.test.ts fails (the spurious proxy unavailable warning fires); with the fix, green. The per-seam test genuinely guards this fix.

CI status on head b7a26fd:

Stacking: verified merge-base(head, #824-tip) == 54f8fb2 — no drift. Rebase onto master once #824 merges, as the PR body notes.

Nothing to fix in the PR branch itself — no small issues found during review.

中文摘要:修复了 opencode native 插件在 overlap 模式下无条件创建 http.request 路由导致的误报警告(proxy unavailable),把路由创建收敛进 nativeActive 门控(与 pi 的 fetch intercept 对齐);diff 干净、本地 pre-flight 全绿(1654/0/2)、回归证明已复现(撤掉修复新测试即失败),代码可合并——待 #824 落地后 rebase 到 master 让标准 CI 矩阵覆盖当前 head 即可。

@ranxianglei

Copy link
Copy Markdown
Owner Author

继续

@ranxianglei
ranxianglei merged commit 0a997a4 into 2026-09-15_opencode-native-plugin Sep 17, 2026
1 check passed
@ranxianglei
ranxianglei deleted the 2026-09-16_840-coexistence-audit branch October 15, 2026 05:32
cskwork pushed a commit to cskwork/billion-context that referenced this pull request Oct 21, 2026
…existence-audit

fix(agent): gate opencode native route behind nativeActive (ranxianglei#840)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant