Skip to content

fix: discover opencode/omp declared provider hosts for the MITM whitelist (#1411) - #1413

Merged
ranxianglei merged 4 commits into
masterfrom
2026-09-26_opencode-omp-provider-discovery
Sep 26, 2026
Merged

ranxianglei merged 4 commits into
masterfrom
2026-09-26_opencode-omp-provider-discovery

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #1411

Problem

opencode/omp lanes ride the HTTPS_PROXY cert-MITM path, so the auto-discovered host whitelist (discoverMitmDomains) is the only mechanism whitelisting their provider relays. But extractHttpsHosts had no opencode/omp branch — even though loadClientConfig already parses OpencodeProvider.baseURL and OmpProvider.baseUrl (bili uses them for context windows) — and the discovery mtime-cache watchlist contained no opencode config file nor omp's models.yml. Result: a custom provider declared in config was blindly tunnelled (BLIND TUNNEL WARNING, zero compression) despite bili having read the very same config; and because the unlisted files never invalidated the cache, even a one-time discovery would go stale on edit.

Changes

Commit 1 — discover opencode/omp declared provider hosts (#1411)

  • src/discover.ts: extractHttpsHosts now pushes config.opencode.providers[*].baseURL and config.omp.providers[*].baseUrl (pi/zcode-style, https-only, lowercased hostname).
  • src/client-config.ts: new exported opencodeConfigFiles(env) returning exactly what readOpencodeConfigRoot reads: <XDG_CONFIG_HOME|~/.config>/opencode/{opencode.jsonc,opencode.json,config.json} plus $OPENCODE_CONFIG when set.
  • src/discover.ts: configFilePaths() now watches those files + <omp home>/models.yml, so mid-run config edits invalidate the mtime cache. Both halves of root cause 2 ship together — adding only the push branches would make discovery return stale results forever after the first TTL cycle.

Commit 2 — same root cause, aider instance (labeled bonus fix)

  • The .aider.conf.yml candidates (home > git-root > cwd, feeding config.aider.baseUrls) were equally absent from the watchlist: first discovery happened to read them, later edits went stale. The candidate walk is extracted as aiderConfFiles() from readAiderConfUrls and added to the watchlist. Per owner policy 2026-09-25 (one issue per root cause, all instances fixed in the SAME PR), this ships here rather than as a separate issue.

Behavior change (flagged per policy)

  • Old: custom opencode/omp provider hosts declared in config were never in the MITM whitelist → blind tunnel, zero compression for those relays; aider conf edits after first scan stayed stale in the whitelist.
  • New: such hosts are auto-discovered and cert-MITM'd like pi/zcode/codex etc.; edited aider conf is picked up within one TTL cycle (~2 s). Intentional expansion of the MITM surface — it IS the fix — bounded to hosts the user explicitly declared in client configs bili already reads.
  • Negligible side effect: the mtime watchlist stats ~5 extra paths per rescan.

Coordination with #1409 (open)

#1409 seeds the static zen host (opencode.ai) into the same function. Independent changes; either merge order works and a conflict would be a trivial union (keep both blocks). This PR builds on master without #1409, so its coexistence test asserts cross-lane discovery rather than the zen host.

Tests

6 new tests in tests/discover.test.ts: unit (opencode+omp extraction incl. http-dropped/lowercasing/coexistence with other lanes; partial configs safe) + integration (opencode.json custom provider discovered & coexists with another lane; omp models.yml discovered; $OPENCODE_CONFIG discovered; opencode.json edit invalidates cache after TTL; .aider.conf.yml edit invalidates cache after TTL). withTempHome hardened to pin XDG_CONFIG_HOME and drop ambient OPENCODE_CONFIG.

Pre-flight (final head)

  • npm run typecheck ✓
  • npm test: 2807 tests, 2795 pass, 0 fail, 12 skipped (gated e2e)
  • npm run build ✓

E2E codex suite not run: diff touches none of the request-pipeline hot files listed in AGENTS.md §3 (no server/loop/adapter/stream/persist/agent changes).

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-26_opencode-omp-provider-discovery (ecd496a)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1413

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1413.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] 🏷 Reviewed #1413 end-to-end — pulled head 0571f373, read all three changed files at source level, and cross-checked each claim against loadClientConfig. Verdict: mergeable. Correct root-cause fix, clean scope, strong regression tests. Only outstanding item: 3 CI test jobs still in_progress on the head (windows-22 / ubuntu-22 / windows-24); everything else is already green.

① Direction (issue #1411) — spot on. Two root causes, both fixed at the source rather than masked:

  • RC1: extractHttpsHosts had no opencode/omp branch even though bili already parses those providers → added push for config.opencode.providers[*].baseURL and config.omp.providers[*].baseUrl (src/discover.ts:48-53), https-only / lowercased / deduped like pi/zcode.
  • RC2: the mtime-cache watchlist never contained the opencode config files nor omp's models.yml, so even a one-time discovery went stale. Both halves ship together, as the issue requires.

② Regression — purely additive, no existing behavior touched:

  • extractHttpsHosts: two new loops inserted between zcode and codebuddy; every pre-existing lane (claude/codex/pi/zcode/codebuddy/qoder/trae/aider) unchanged. Ordering is irrelevant (Set-based whitelist).
  • configFilePaths: three new entries appended; existing paths untouched. Cost = ~5–7 extra statSync per post-TTL rescan (negligible, you flagged it).
  • client-config.ts: opencodeConfigFiles is a new export; the readAiderConfUrls split into aiderConfFiles is a behavior-preserving extraction — the only delta is the returned candidate list is now [...new Set(...)]-deduped, which cannot change readAiderConfUrls output (first-match-wins, order-preserving) and is exactly what the watchlist wants.

Completeness: after this PR, every file-backed source feeding extractHttpsHosts (claude/codex/pi/zcode/opencode/omp/codebuddy/qoder/trae/aider-conf) is in the watchlist — the read-but-unwatched class is fully closed, not just the reported instance.

Subtle win worth calling out: opencodeConfigFiles mirrors readOpencodeConfigRoot (all three globals config.json/opencode.json/opencode.jsonc + $OPENCODE_CONFIG), not the singular resolveOpencodeConfigFile (default opencode.jsonc only). Mirroring all three is what makes an edit to opencode.json invalidate the cache — the exact bug. Correct choice.

③ Code — the mirror holds on the resolution logic: opencodeConfigFiles uses the same XDG_CONFIG_HOME|~/.config + /opencode dir + same filenames + same $OPENCODE_CONFIG guard as readOpencodeConfigRoot (client-config.ts:1219 vs :1272). Omp source confirmed: readOmpConfig reads <resolveOmpHome>/models.yml (:1098) = exactly what the watchlist adds (discover.ts:102). Field names confirmed (OpencodeProvider.baseURL :83, OmpProvider.baseUrl :74). And discoverMitmDomains passes the same process.cwd() to both configFilePaths and loadClientConfig (discover.ts:103 / :145), so the aider/opencode watchlist always matches what's actually read. mtimesEqual handles added/removed files via its size check. No issues found.

④ Test validity — good teeth, and they reproduce the real defects (would fail on master):

  • Unit #1411 tests cover http-dropped, lowercasing, cross-lane coexistence, and partial-config safety.
  • Integration tests drive the real file→parse→discover pipeline (not just extractHttpsHosts in isolation) for opencode.json, omp models.yml, and $OPENCODE_CONFIG.
  • The two cache-invalidation tests (opencode.json edit, .aider.conf.yml edit) are the key ones: write v1 → discover → edit to v2 + mtime bump → within-TTL still cached (asserts same-array identity) → after 2.1 s (>2 s TTL) v2 present & v1 gone. These fail on master precisely because those files weren't watched — direct regression coverage for RC2.
  • Determinism handled: withTempHome pins HOME/XDG_CONFIG_HOME/CODEX_HOME/etc and drops ambient OPENCODE_CONFIG; fs.utimesSync forces distinct mtimes (guards against same-resolution writes). Minor: the two TTL tests are timing-based (2.1 s > 2.0 s, 100 ms margin) — acceptable, standard practice.

⑤ Diff cleanliness — 3 files, +151/-4, every line on-purpose. The .aider.conf.yml fix is labeled a bonus but is the same root cause (read-but-unwatched file) as RC2, shipped in the same PR per the 2026-09-25 granularity policy — correct call, not scope creep.

Behavior change (confirming your flag): old → declared opencode/omp provider hosts were never whitelisted (blind tunnel, zero compression) and edited aider conf stayed stale; new → those hosts are cert-MITM'd like pi/zcode/codex and edited aider conf is picked up within one ~2 s TTL. Bounded to hosts the user explicitly declared in configs bili already reads. Intended and appropriate.

Coordination note stands: independent of open #1409 (static zen host opencode.ai); trivial union in either merge order.

CI on head 0571f373: 3 test jobs still in_progress; all other checks green (codex e2e, hermetic registry e2e, real opencode/pi/dsh lanes, version-guard, CODEX_HOME overlay). Base is current master (0 commits behind). Merge once those flip green.

中文摘要:修复了 opencode/omp(及顺带同根因的 aider)自定义 provider 主机从未进入 MITM 白名单、且其配置文件编辑后 mtime 缓存不失效导致盲区隧道的问题——按根因补上了发现分支与监听清单,并加了能在 master 上复现原缺陷的回归测试;代码与测试均正确、diff 干净,可合并(待 CI 剩余 3 个测试 job 转绿)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Follow-up — added local execution evidence on head 0571f373 (clean worktree): npm ci ✓ · npm run typecheck ✓ (tsc clean) · targeted tests/discover.test.ts → 28/28 pass, including both #1411 cache-invalidation tests (each ~2.1 s, so the TTL re-scan path actually executes). So the changed behavior is verified locally end-to-end, independent of the 3 still-running CI test jobs. Verdict unchanged: mergeable once those flip green.

ework-agent and others added 4 commits September 26, 2026 20:15
opencode's built-in zen gateway (opencode auth login) resolves its baseURL
from the models.dev catalog, so it lands in no local config file and
discovery never sees it — traffic blind-tunnelled with zero compression.
Seed OPENCODE_DEFAULT_MODEL_HOSTS in extractHttpsHosts for the opencode/omp
lanes, following the qoder/trae/aider stock-gateway precedent. Explicit
provider base URLs coexist (union, not replace).

Fixes #1405
…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

Copy link
Copy Markdown
Owner Author

#1417 深审 + rebase + union 交付(详表见追踪板)。栈序:#1409 先合,本 PR 后合。head=ecd496a(force 重放到当前 master)。

#1413 是什么:① 发现 opencode/omp 配置里已声明的 provider 上游域(opencode.json 的 providers[].baseURL、models.json 的 provider baseUrl)进 MITM 白名单——自定义中继用户不再需要手配;② .aider.conf.yml 加入发现源并监听 mtime;③ https-only、去重、小写、解 /bili/ 包装,与其他车道共存。动机:#1411(自定义 provider 域默认不被发现→MITM 拒连)。

行为影响:feat(MITM 白名单来源扩容)——声明即信任:用户自己写进客户端配置的 https 域现在自动进白名单。宿主匹配 h===d||endsWith("."+d) 无过匹配;http:// 一律丢弃。安全语义=信任用户自己的配置文件,与既有 aide/qoder/trae 车道同型。

rebase 冲突(与 #1409 同文件):union 解——本 PR 的 partial-configs 测试断言 extractHttpsHosts({opencode:{}}) 从 [] 改为 OPENCODE_DEFAULT_MODEL_HOSTS(#1405 种子落地后两者本就该一致);cherry-pick 边界曾截断 #1411 测试块的 });(tsc TS1005),已补闭合。union 树定向 30/30 + typecheck 0 错。

顺带三处小修:① CONFIGURATION.md/zh-CN 补一句声明式发现(挂在既有 bili opencode 行旁);② client-config.ts 补 opencodeConfigFiles 顺序无关注释;③ TTL 测试的 2×2.1s sleep 留作注记未改(非阻塞)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Re-verified the rebased head ecd496a (not rubber-stamping my earlier 0571f373 verdict — the diff grew and a behavior-relevant assertion changed, so I re-pulled and re-read it). Union is coherent, tree is green.

Stack state (confirmed via git): ecd496a = master c030b566 → 642ed4a3 (#1409 zen-seed) → aec938c2 (#1413 core) → cbb585c7 (#1413 aider) → ecd496a5 (union-fix + docs). So #1413 currently carries #1409's commit stacked on master — self-contained, base is a clean ancestor, mergeable_state: clean. Your "#1409 先合、本 PR 后合" plan holds: once #1409 lands, rebase #1413 to drop the now-duplicate 642ed4a3; as-is it is independently mergeable and CI-green.

Union coherence (what actually changed): verified the two halves coexist without conflict —

  • Coexistence test passes: {opencode:{custom provider}, claude} → opencode.ai + custom host + claude host all present together (zen default does not suppress declared providers).
  • Dedup confirmed: {opencode:{}, omp:{}} → a single opencode.ai (both lane-triggers seed the same host; push() dedupes).
  • The declared-provider branches + mtime watchlist (opencodeConfigFiles / <ompHome>/models.yml / aiderConfFiles) are byte-for-byte the same logic I signed off before.

Behavior change — stated precisely for the record: extractHttpsHosts({opencode:{}}) now → OPENCODE_DEFAULT_MODEL_HOSTS (["opencode.ai"]) instead of []. Because loadClientConfig assigns config.opencode/config.omp unconditionally (client-config.ts:1519-1520, like qoder/trae/aider at :1524-1530), the if (config.opencode || config.omp) gate is effectively always-true → opencode.ai enters every user's whitelist, not just opencode/omp users'. This is intentional and tested (your #1405 test "seeds opencode zen gateway host even with no client configs") and consistent with how the qoder/trae/aider stock gateways already behave (also always-on). The guard is a harmless no-op documenting intent. Security: low-risk — single well-known public domain, exact-or-subdomain match (no over-match), http:// dropped, same trust model as the existing lanes you cited. No regression.

One non-blocking doc nit (CONFIGURATION.md + .zh-CN.md): the omp row points at ~/.omp/omp.json with providers[].baseURL, but the code reads <resolveOmpHome>/models.yml = ~/.omp/agent/models.yml by default (or $PI_CODING_AGENT_DIR/models.yml), field baseUrl (lowercase). Suggested wording: omp providers come from ~/.omp/agent/models.yml (providers.<name>.baseUrl). Happy to push a one-line doc-fix commit if you want, or fold it in yourself — I didn't amend your branch unasked given the active force-push/stack management.

Evidence (head ecd496a): npm run typecheck ✓ · tests/discover.test.ts 30/30 locally (matches your "30/30 + typecheck 0 错") · CI 12/12 green.

Verdict unchanged: mergeable. Only open item is the trivial omp-path doc string.

中文摘要:rebase+union 后的新 head ecd496a 已重新核验——#1411 声明式 provider 发现与 #1405 zen 默认播种共存无冲突(共存/去重/缓存失效测试均通过),{opencode:{}}→opencode.ai 的默认播种是有意的、与 qoder/trae/aider 既有"始终在线"模式一致且已被测试显式锁定,非回归;typecheck 干净、定向 30/30、CI 12/12 全绿,可合并;唯一遗留是一处文档小误(omp 配置路径应写作 ~/.omp/agent/models.yml 而非 ~/.omp/omp.json),不阻塞合并。

@ranxianglei
ranxianglei merged commit 5011b25 into master Sep 26, 2026
12 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-26_opencode-omp-provider-discovery branch October 15, 2026 05:32
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/omp 显式声明的 provider baseURL 从未被 extractHttpsHosts 自动发现(与 #1405 前提不符)

1 participant