Repository navigation
fix(ca): merge OS trust store into combined-ca.pem (#1807) - #1808
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1791-pr.1808.651e126This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1808.tgz
npm install -g packageInstall instructions are refreshed on each push. |
The SSL_CERT_FILE bundle is consumed with REPLACEMENT semantics by some launched clients (codex's rustls HTTP stack trusts exactly the file contents, no native roots merged). On Windows the bundle previously held only Node's static Mozilla snapshot plus the MITM root, so any direct, non-proxied connection of such a client could fail whenever the OS store diverged from that snapshot. Merge the OS trust store (Windows cert stores via PowerShell, macOS keychains via security(1); Linux already reads the filesystem bundle) with per-certificate fingerprint dedup, and bound the rebuild (PowerShell spawn cost) to once per 24h per machine via an mtime + CA-fingerprint staleness gate.
Review fix for the #1807 feature: one failing source must not discard certificates already collected from the others. - Windows: a Root store that fails to open (LocalMachine or CurrentUser) is skipped via a per-store catch instead of aborting the whole script under $ErrorActionPreference='Stop'. - macOS: a failing keychain (e.g. a locked login keychain) no longer drops the System keychain certs collected before it; only total failure throws and logs, as before.
The previous assertion expected collectOsStorePems([]) for win32 and darwin on EVERY host, which fails on real Windows/macOS machines (the CI matrix includes windows-latest) where the tools exist and export real certificates. Assert [] only where the tooling is absent, and exercise the production export path end-to-end when running on a native host.
The OS-store merge was developed during the #1802 diagnosis before the dedicated issue existed. Cite the dedicated tracker (#1807) in code comments, test names, and the en/zh config docs so grep-ability matches the repo convention; the PR body carries the 来源 link back to #1802. Also rename the local logger binding to loggerLog to match every other server-side module (no behavior change).
80a6ce7 to
8f568e5
Compare
…ge stays out of the 20s bring-up budget (#1807)
[bot] 🏷 ## Review 结论 — PR #1808(fix(ca): merge OS trust store into combined-ca.pem) 方向判定:正确,修的是根因。 原 issue #1807 的因果链成立:替换语义客户端(codex rustls Review 中发现并处理的一个回归(重要):
次要观察(不阻塞): darwin 侧 结构化七问
Pre-flight 证据:rebased head 本地全套 3483 tests / 3464 pass / 0 fail / 19 skip,typecheck+build 绿;CI(793a0ac 推送前一个 head):ubuntu 22/24 + build-artifact + version-guard + 全部 e2e lane(pi/codex/dsh/opencode/registry/codex-overlay)绿,windows 22/24 仅上述单一测试红。793a0ac 已推送,CI 重跑中,Windows 转绿即可合并;若再红我继续追。 |
[bot] 🏷 CI 全绿,收工判定:可合并。 head 793a0ac(含 review 补的测试修复 commit)上 12/12 check 全过:ubuntu-latest 22/24、windows-latest 22/24、build-artifact、version-guard、全部 e2e lane(pi/codex/dsh/opencode/registry/codex-overlay)。Windows 日志逐项核实:此前确定性失败的 合并动作按仓库规则由人来执行(https://github.com/ranxianglei/billion-context/pull/1808)。遗留跟进:issue #1813(真机首启 CA 初始化 vs hook 20s 预算的残留窗口,三个选项待你拍板,不阻塞本 PR)。 |
What & why
Some launched clients consume
SSL_CERT_FILEwith replacement semantics: codex's rustls HTTP stack (codex-rs/http-client/src/custom_ca.rs, verified at rust-v0.159.3) registers exactly the file's certificates as its root store and merges no native roots. On Windows, bili'scombined-ca.pemheld only Node's static Mozilla snapshot (~121 certs, frozen per Node version) plus the MITM root — so any DIRECT (non-proxied) connection by such a client could fail whenever the Windows Root store diverged from that snapshot, while a bare client using the OS store worked fine. macOS has the same shape for user-added roots (/etc/ssl/cert.pemexcludes login/System keychain certs); Linux is unaffected (its filesystem bundle IS the OS store). Filed from #1802's diagnosis as an independent latent gap (that issue's actual cause was the.envproxy override — PR #1806).Fix
src/ca.tsnow makes the bundle a true superset of the OS trust store:collectOsStorePems(): win32 → PowerShell export of the Root stores (LocalMachine + CurrentUser, PS 5.1-compatible script, output decoded as UTF-8 or UTF-16LE); darwin →security find-certificate -a -pover System + login keychains; linux → no-op (the filesystem bundle is already read). Best-effort, per source: one failing store/keychain degrades without discarding certificates collected from the others; only total failure throws and is warn-logged — startup never breaks.Branch history
Original fix commit written during the #1802 diagnosis (80a6ce7). This head is rebased onto current master (b785c43, v0.1.177) plus three review fixes:
fix(ca): degrade OS-store merge per source instead of all-or-nothing— the PowerShell script aborted the whole export if either store failed to open ($ErrorActionPreference='Stop'); macOS had the same shape via a single throw around both keychains. Now each source degrades independently.test(ca): make OS-store degradation test deterministic on win/mac hosts— the original test assertedcollectOsStorePems([])for win32/darwin on EVERY host, which fails on windows-latest CI (the tooling exists there and exports real certs — §7.2 deterministic-tests violation). Now asserts[]only where tooling is absent, and exercises the production export path end-to-end on a native host.docs(ca): cite #1807 ...— cites the dedicated tracker in code comments, test names, en/zh docs (branch was developed under the bili codex 报错 MCP client for codex_apps failed to start 仍然存在 #1802 context before this issue existed); aligns the logger import alias with sibling modules. No behavior change.fix(claude-native): pre-warm CA in the bootstrap so first-run init stays out of the 20s bring-up budget(#1813) — the commit above moved first-run/stale-bundle CA cost into every spawned proxy's startup, where the claude-native hook lane has a hard 20 s health window (SPAWN_WAIT_MS): RSA keygen + the Windows PowerShell Root-store export (~8 s measured on loaded runners, 30 s cap) exceeded it deterministically on windows-latest CI (fresh temp HOME per run ⇒ guaranteed rebuild). The SessionStart bootstrap (src/claude-native-bootstrap.ts) now callsensureRootCA()itself BEFORE spawning — its runtime budget is Claude Code's hook timeout, not the child's 20 s window — so after a successful prewarm the child always hits the 24 h freshness gate and starts fast; steady state costs a sub-millisecond stat+read. Prewarm failure is log-only (the hook must never fail claude; the child re-runs its own init exactly as before). The test-only manual win32 pre-warm from item 3's sibling commit (793a0ac) is removed, so the hook e2e exercises the real cold-start shape end-to-end again.Behavior changes (explicit)
proxy did not become healthy within 20000ms+ misleading port advice on slow Windows machinesLinux output is semantically unchanged (its filesystem bundle already IS the OS store; block-split normalization may reorder identical certs). The server-side secure context is unaffected (it uses
rootCertPemdirectly, not the bundle). Consumers in the normal MITM flow are unaffected — the change only ADDS trust material; nothing existing is removed.Config surface
None. No new config field, env var, or CLI flag.
COMBINED_MAX_AGE_MS(24 h) is an internal constant, deliberately not exposed — expressing a rebuild interval would require inventing a new config section (owner-gated territory).Security note
Touches CA/MITM code (
src/ca.ts) → human merge required (§7.4). Degradation path: any failure reading the OS store logs a warning and falls back to the previous bundle composition — proxy startup never breaks because of it.Tests & pre-flight (head
e1b12b18, rebased ontoorigin/masterb785c43 = v0.1.177)tests/ca-combined.test.ts(fingerprint cross-wrapping dedup, NDJSON/UTF-16LE parsing, PowerShell script shape, graceful degradation, staleness-gate reuse/rebuild/CA-missing-rebuild) — all passnpm run typecheck— passnpm test— 3478 tests, 3459 pass, 0 fail, 19 skipped (gated e2e)npm run build— passsrc/ca.tsis not a request-pipeline hot file, so the CI gates decide.#1813 commit (e1b12b1) pre-flight
npm run typecheck— pass;npm run build— pass (dist-import-annotations OK)node --import tsx --test tests/claude-native.test.ts tests/ca-combined.test.ts— 54 pass / 0 fail / 8 skipped (live-gated)ACP_TEST_CLAUDE_NATIVE=1:hook e2e: dist script spawns a proxy on the stable port, second run attachespasses WITHOUT the manual pre-warm (fresh temp HOME ⇒ real cold-start shape: bootstrap prewarms CA, child attaches fresh bundle) — this is the exact test that failed 4/4 on windows-latest 22+24 since 80a6ce7resolveClaudeHostPid: live ps walk…,watchdog tracks the claude host…,shared proxy survives…) fail in the agent sandbox identically on the pristine tree (verified via stash) — environmental (fake-claude-host spawning in this container), not caused by this PR; CI runners are the arbiter.Fixes #1807
Closes #1813