Skip to content

feat: seed opencode.ai into the omp/opencode lane MITM whitelist (#1405) - #1409

Closed
ranxianglei wants to merge 0 commit into
masterfrom
2026-09-26_opencode-zen-mitm
Closed

ranxianglei wants to merge 0 commit into
masterfrom
2026-09-26_opencode-zen-mitm

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

opencode's built-in zen gateway (opencode auth login) resolves its baseURL (https://opencode.ai/zen/v1/messages) from the models.dev catalog — it lands in no local config file, so discoverMitmDomains never sees it. Today that traffic blind-tunnels through bili: zero compression, zero session management, one easy-to-miss BLIND TUNNEL WARNING (#897).

This seeds the zen host into discovery using the exact per-lane precedent already in the codebase (QODER_DEFAULT_MODEL_HOSTS, TRAE_DEFAULT_MODEL_HOSTS, AIDER_DEFAULT_MODEL_HOSTS — "stock model gateways, cert-MITM'd so bili X compresses"):

  • src/client-config.ts: new OPENCODE_DEFAULT_MODEL_HOSTS = ["opencode.ai"].
  • src/discover.ts: extractHttpsHosts seeds it when the opencode or omp lane is present (omp runs zen models too). Union semantics — unlike qoder/trae/aider's replace-on-explicit-override, it coexists with explicit provider base URLs, because a user can mix custom providers with zen models in one setup.
  • No launcher change needed: every proxy instance runs discoverMitmDomains() itself inside isMitmHost(), so launched (bili omp / bili opencode) and standalone instances are both covered. /zen/v1/messages already detects as Anthropic wire (server.ts endsWith("/v1/messages")).
  • Docs: CONFIGURATION.md + zh (whitelist paragraph + launcher table rows).
  • Tests: unit (per-lane seeding, coexistence with other lanes) + integration (temp-home discovery includes opencode.ai).

⚠ Behavior change (old → new)

  • OLD: CONNECT opencode.ai:443 → blind TCP tunnel — traffic usable but never decrypted/compressed; one-time BLIND TUNNEL WARNING per host.
  • NEW: CONNECT opencode.ai:443 → TLS terminated by bili's root CA; model endpoints (/zen/v1/messages) enter the compression pipeline; non-model paths on the same host are relayed verbatim ([Bug] DSH native fetch 拦截误伤非 LLM 端点:任何以 /messages 结尾的 URL 都被当成模型 API #1284 fallback). Scope is identical to how api.anthropic.com / qoder / trae / aider stock hosts already behave on any machine running bili (discovery seeds them unconditionally too). Remote clients may now be MITM'd for this host as for other whitelisted hosts (loopback-only blind tunnels unchanged).
  • Non-zen users with explicit third-party base URLs: unchanged (their hosts were never opencode.ai; explicit values coexist, nothing replaced).

Evidence

  • npm run typecheck ✅ · npm test: 2449 pass / 3 fail — the 3 failures (tests/claude-native.test.ts ps-walk/hook-e2e) reproduce identically on clean master in this environment (pre-existing, unrelated) · npm run build ✅
  • Live probe against the real gateway: started dist/index.js start, drove curl -x <proxy> https://opencode.ai/ — log shows mitm … tunnel established (TLS terminated locally) (no BLIND TUNNEL WARNING), CA generated lazily, second attempt trusting the CA returned HTTP 200 from opencode.ai through bili.
  • Remaining real-world validation (needs an authenticated zen account): full bili omp session with a zen model showing compression + context drop — the wire shape is pinned by the existing anthropic-wire tests; [Bug] bili omp 扩展 stampPromptCacheKey 无条件注入顶层 prompt_cache_key —— 严格 schema 上游(opencode zen anthropic 端点)全量 400 #1403's client-side prompt_cache_key leak (the strict-schema 400 risk called out in the issue) is already fixed upstream of this proxy path.

Closes #1405

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-26_opencode-zen-mitm (82b4817)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1409

Each push to this PR publishes a new version under the pr-1409 npm tag.

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR review — #1409 (feat: seed opencode.ai into the omp/opencode lane MITM whitelist)

① 原 issue(方向关) ✅ — PR 精确实现了 #1405 的方案:按既有 per-lane stock-gateway 先例(QODER/TRAE/JCODE/AIDER_DEFAULT_MODEL_HOSTS)新增 OPENCODE_DEFAULT_MODEL_HOSTS = ["opencode.ai"],在 discovery 层 seed。根因判断正确(zen baseURL 来自 models.dev 目录、不落任何本地配置 → discovery 不可见 → 盲隧),修在源头(发现机制的 seed 层),不是掩症状。

② 回归审查(既有行为清点) — 触碰路径:extractHttpsHosts(src/discover.ts)、isMitmHost 消费链(src/mitm.ts:96-98)、launcher domain 合并(launcher.ts:3243)、两份 CONFIGURATION 文档。逐项结论:

  • seed 条件的实际语义:⚠️ 值得点明——readOmpConfig 在 ~/.omp/agent/models.yml 不存在时返回 {providers:{}}(truthy),所以 config.opencode || config.omp 恒为真,opencode.ai 实际是无条件进入每台 bili 机器的发现白名单,而非「lane 存在时」。我核对了 qoder/trae/aider 三个先例(readQoderConfig/readTraeConfig/readAiderConfig 同样恒返回 truthy 对象)——无条件 seed 就是该代码族的既有行为,PR 正文也如实披露了("discovery seeds them unconditionally too")。判定:与先例一致、已披露,有意变更,可接受。仅正文里 "seeded when the lane is present" 这句措辞与实际语义略有出入,披露段已覆盖,不拦。
  • 其他 lane 分支(claude/codex/pi/zcode/codebuddy/qoder/trae/aider):未触碰,逐行核对无漂移。
  • discovery mtime 缓存(configFilePaths,src/discover.ts:83):新输出不依赖任何文件内容(静态 host + 恒真条件),不引入陈旧缓存问题。✅
  • wire 检测:/zen/v1/messages 命中 urlPath.endsWith("/v1/messages")(src/server.ts:1104)→ Anthropic wire,声明属实。非模型路径终止后 verbatim relay([Bug] DSH native fetch 拦截误伤非 LLM 端点:任何以 /messages 结尾的 URL 都被当成模型 API #1284 兜底)。✅
  • 两种压缩模式:变更只影响哪些 host 被 TLS 终止;流量进管线后走既有 mode 处理,未触碰任何 mode-specific 逻辑。✅
  • 非 zen 用户:显式第三方 baseURL 用户不受影响(union 语义,不替换任何值)。✅
  • 无 config schema / persistence / 跨仓依赖(acp-kernel pin 未动)变更。

③ 代码审查 ✅ — 最小改动(client-config +7 / discover +10),完全跟随既有模式与注释风格,无 as any、无 console.error,中英文档同步。注释解释了 why(auth-login 用户无配置可扫),合格。

④ 测试有效性 ✅ — 3 个新测试都有牙:unit deepEqual(OPENCODE_DEFAULT_MODEL_HOSTS) 抓得住缺 seed/错 scheme/多余 host;mixed-lane 测试钉住共存语义;temp-home 集成测试走真实的 loadClientConfig→discoverMitmDomains 全链路并钉住「无客户端配置也 seed」这一行为选择。确定性 OK(不依赖端口/时序)。修复前这些断言必失败(opencode.ai 缺席)= 真回归测试。

⑤ diff 整洁度 ✅ — 5 文件 +44/-7,每一行都服务于本 PR 目的,无跑题/重排/生成物。

验证(我在本地全部重跑,不只信 PR 证据):

⚠ Behavior change(确认作者披露准确):OLD CONNECT opencode.ai:443 = 盲隧+一次性 WARNING → NEW = bili root CA 终止 TLS,/zen/v1/messages 进压缩管线,其余路径 verbatim relay;远程客户端对该 host 同样可被 MITM(与其他白名单 host 同等待遇)。范围=既有 stock host 类(qoder/trae/aider 亦无条件 seed),披露完整。

分析中发现的一个相邻问题(已单独立项 #1411):#1405 正文假设「opencode/omp provider 显式写了 baseURL 会被发现」——不属实:extractHttpsHosts 在 #1409 前后都没有推送这两个 lane 显式声明的 provider URL(pi/zcode 有,opencode/omp 没有)。即 #1409 注释描述的「mix custom providers with zen」人群,其自定义 host 仍会盲隧。不同根因(#1405 修「无配置可扫」,#1411 是「有配置没被扫」,且涉及 configFilePaths 缓存清单缺 opencode/omp 文件),故未混入本 PR。

结论:代码方向正确、实现干净、测试有牙、行为变更披露充分。合并前需要 rebase 到当前 master(其 head 落后 ~30 提交;我已本地验证 rebase 零冲突且 rebased head 全绿——CI 会对新 head 再跑一遍)。rebase 后即可由人工合并(我不执行 merge)。


中文一句话:审了 PR#1409(opencode.ai 进 omp/opencode lane MITM 白名单):方案与先例一致、回归面干净(seed 实为无条件但与 qoder/trae/aider 同类且已披露)、测试有牙;3 个测试失败系 stale-base 而非 pre-existing,rebase 到当前 master 后本地全套 2790 绿;另发现 opencode/omp 显式 provider URL 从未被自动发现的相邻缺口已立 #1411;rebase 后可合并。

ranxianglei pushed a commit that referenced this pull request Sep 26, 2026
…covery and config-files order note

- tests/discover.test.ts: the union of #1409 (zen seed) + #1413 (declared
  hosts) dropped the closing '});' of the #1411 partial-configs test —
  restore it (tsc TS1005 at EOF).
- CONFIGURATION.md + zh-CN: one sentence on opencode/omp declared-provider
  MITM discovery (#1411) next to the existing bili opencode line.
- src/client-config.ts: note that opencodeConfigFiles order is irrelevant
  (first parse wins per key).
@ranxianglei
ranxianglei force-pushed the 2026-09-26_opencode-zen-mitm branch from 82b4817 to c030b56 Compare September 26, 2026 12:19
@ranxianglei

Copy link
Copy Markdown
Owner Author

#1417 深审 + rebase 交付(详表见追踪板)。这两个 PR 是栈式的,必须 #1409 先合、#1413 后合(同文件:client-config.ts / discover.ts / discover.test.ts)。

#1409 是什么:给 omp/opencode 车道种入 zen 网关默认域 opencode.ai(及其登录子域)到 MITM 白名单——OPENCODE_DEFAULT_MODEL_HOSTS 常量 + 部分配置(空 opencode/omp 块)安全回退到种子 + MITM 路径 e2e。动机:零配置 opencode 用户(走官方网关)MITM 模式下连接被拒。

行为影响:feat(白名单扩容,不是纯机械)——默认多信任一个上游域。空配置 opencode/omp 从"MITM 不拦截任何域"变为"拦截 opencode.ai"。这是安全面扩张,按仓库纪律保持人工合并。

深审修复:cherry-pick 到当前 master(c030b56,原分支 228 behind)零冲突重放,head=642ed4a。定向 30/30+typecheck 0 错(全量交给远程 CI)。

非阻塞:与 #1413 的测试断言冲突已在 #1413 侧按 union 解(其 partial-configs 测试断言从 [] 改为 OPENCODE_DEFAULT_MODEL_HOSTS)。

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.

[enhancement] opencode zen 网关 (opencode.ai) 应进 omp/opencode lane 的默认 MITM 白名单 — 现状是静默盲隧、零压缩

1 participant