Skip to content

feat: opt-in for non-http(s) baseUrl providers to ride bili (#1392) - #1437

Closed
ranxianglei wants to merge 2 commits into
masterfrom
2026-09-26_non-http-providers-optin
Closed

ranxianglei wants to merge 2 commits into
masterfrom
2026-09-26_non-http-providers-optin

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Phase 1 of #1392: an explicit opt-in that lets a non-http(s) baseUrl provider (e.g. pi-claude-bridge's literal "claude-bridge") claim compaction ownership when its traffic actually flows through bili — narrowing the #1383 stopgap veto from "never cancel non-http(s)" to "never cancel unless opted in, and even then only on carriage evidence."

What changed

  • Config key plugin.nonHttpProviders: {"<providerId>": true} (config file) and env mirror BILI_NON_HTTP_PROVIDERS (comma-separated). The launcher resolves both (resolveNonHttpProviders) and mirrors them to the client env, exactly like mitm.domains / BILI_MITM_HOSTS.
  • Veto narrowing (src/agent/pi.ts → ownsCompaction): a non-http(s) baseUrl now vetoes compaction ownership only when its provider is not opted in. An opted-in provider falls through to the same evidence gate as every other provider.
  • Docs: the pi/omp compaction-ownership bullet updated in both CONFIGURATION.md and CONFIGURATION.zh-CN.md.

Behavior change (old → new) — please read

Not included (per owner decision on #1392)

Phase 2 — how a bridge user actually routes their traffic through bili (Path B, base URL) — stays docs-only and demand-gated. No launcher flag or plugin-set-env is added until a real user asks.

Verification

  • npm run typecheck — clean
  • npm test — 2854 tests, 2842 pass, 0 fail, 12 skipped (gated e2e)
  • npm run build — success
  • New regression tests cover: veto narrowing (opted-in + carried → cancel; opted-in + unrouted → no cancel; unopted-in → still vetoed even when the proxy confirms carriage; mismatched allowlist id → still vetoed), buildPiEnv exporting BILI_NON_HTTP_PROVIDERS only when listed, and resolveNonHttpProviders strict-true file keys ∪ env list (deduped).

Part of #1392 (Phase 1). Whether to close #1392 is left to the owner — Phase 2 remains demand-gated per the decision recorded there.

Narrow the #1383 stopgap veto so an explicitly opted-in non-http(s) baseUrl
provider (e.g. pi-claude-bridge's literal "claude-bridge") can claim compaction
ownership when its traffic actually flows through bili.

Opt-in (either mechanism): config file plugin.nonHttpProviders
({"<providerId>": true}) or env BILI_NON_HTTP_PROVIDERS (comma-separated).
The launcher resolves both and mirrors them to the client env.

Safety property preserved (#1382): opt-in only widens the candidate set. An
opted-in non-http provider still passes the SAME carriage-evidence gate
(carriedSids local stamp / /__bili/plugin/status probe), so unrouted traffic
never cancels and native compaction keeps working.

No behavior change unless opted in: with no opt-in configured, non-http(s)
providers are never cancelled - byte-for-byte the prior stopgap behavior.
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-26_non-http-providers-optin (b4f78b3)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1437

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1437.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 PR #1437 (branch 2026-09-26_non-http-providers-optin, head 3e08e08f, single commit, based on current master — 0 behind). Verdict up front: code is mergeable; the one red CI cell is an unrelated Windows-N22 runner flake — re-run that job, then merge at your discretion (merge stays human-only).

Duplicate screening: no duplicate — this PR is the implementation of the owner decision recorded in #1392 floor 4 (generic allowlist key shape, veto narrowing with evidence gate intact, Phase 2 docs-only/demand-gated). It implements exactly that approved scope and nothing more; #1382/#1383 are correctly referenced as the invariant/stopgap it refines.

① Original issue (direction): correct layer. The change touches the decision point (ownsCompaction's first veto in src/agent/pi.ts), not a symptom surface — an opted-in provider falls through to the same unchanged carriage-evidence chain (carriedSids / omp identityAt / /__bili/plugin/status probe). The #1392 investigation's backwards-compat proof holds by construction: no opt-in → byte-for-byte today's stopgap; opt-in without routing → no evidence → no cancel. Root cause addressed, not masked.

② Regression audit — existing behaviors on touched paths, each verdict:

  • ownsCompaction non-http(s) veto (src/agent/pi.ts): preserved by default. No opt-in → identical return false; the sid === undefined → return true early-return, both evidence tiers, and the probe-failure→defer path are untouched. pi handler (threshold/overflow) and omp handler (autoPending) unchanged.
  • buildPiEnv (src/launcher.ts): new optional param defaults to []; BILI_NON_HTTP_PROVIDERS emitted only when non-empty → client env byte-identical for everyone who doesn't configure it. Only pi/omp launch paths pass it.
  • resolveNonHttpProviders + FileConfig plugin? field (src/config.ts): purely additive. Verified loadConfigFile() casts the whole parsed JSON (no field whitelist to update — no fix: resolve issues #150 #151 #152 #154 (24h issue batch) #155-class silent-drop risk), and configFile() honors BILI_CONFIG_FILE via src/paths.ts:33, so the test's env override is legitimate.
  • Launcher env sourcing: extNonHttpProviders = resolveNonHttpProviders(process.env) vs resolveMitmDomains(childMitmEnv) — verified this asymmetry is intentional, not a bug: MITM hosts must mirror the proxy child's exact decryption whitelist ([Bug] bili omp 扩展 stampPromptCacheKey 无条件注入顶层 prompt_cache_key —— 严格 schema 上游(opencode zen anthropic 端点)全量 400 #1403), while the non-http allowlist is an extension-side candidate gate that correctly sources from user config/env.
  • Docs: en/zh bullets updated in sync, same semantics.
  • No wire-shape, persistence-version, src/update.ts, kernel-pin, or security changes. The one behavior change (opted-in providers can now be cancelled on carriage evidence) is explicitly disclosed old→new in the PR body, default unchanged.

③ Code: nonHttpProvidersFromEnv trims/skips-empty and deliberately does NOT lowercase (provider ids are identifiers, unlike mitm hostnames — documented); file keys require strict === true ("yes"/1/false rejected — pinned by test); id matching is exact, so a typo can't accidentally opt a provider in; undefined/empty ctx.model.provider stays vetoed (safe direction).

④ Tests have teeth. The four facets each catch a different regression: (A) unopted-in + proxy confirms carriage → still no cancel [pins default invariance]; (B) opted-in + unrouted → no cancel [pins the #1382 invariant — the load-bearing safety property]; (C) opted-in + carried → cancel [pins the feature]; (D) mismatched allowlist id → no cancel [pins exact-match]. Real fake-proxy HTTP probes, deterministic tmpdir/env handling. Resolver + env-export tests pin strict-true/union/dedup. The only coverage gap I looked for — omp lane through the narrowed veto — turned out already covered: the changed line is shared pre-branch code, and the omp lane's auto_compaction_start mechanics are exercised by the existing #535/#851 test. No commit needed.

⑤ Diff cleanliness: 8 files, +136/−7, every line on-purpose, no whitespace/lockfile/generated churn, linear single commit. Clean.

CI status (head 3e08e08f): 12/13 green — all e2e lanes (codex/opencode/pi/dsh/registry hermetic), ubuntu 22+24, windows 24, build-artifact, version-guard. One red: test (windows-latest, 22) — tests\issue539-loop-reasoning.test.ts crashed at file level (ERR_TEST_FAILURE, 68 ms early exit, no assertion diagnostics in the log). Investigation: that file is untouched by this PR; its imports (acp-kernel, src/session.ts, src/loop/index.ts, src/compress-tool.ts) have zero overlap with the PR's files; the identical commit passed that file on ubuntu-22/ubuntu-24/windows-24; recent master runs are all green. Local targeted re-run on the PR head (worktree + npm ci): plugin-agent + launcher + issue539-loop-reasoning = 296/296 pass, plus npm run typecheck clean. Conclusion: environment-specific flake on that runner cell (consistent with this repo's known Windows-flakiness class, cf. #360), not a product of this PR.

Action requested: re-run the failed test (windows-latest, 22) job; if it goes green like its three sibling cells, nothing stands in the way of merging. No code changes made or required.

中文摘要:审查了 #1392 第一阶段 PR(非 http(s) baseUrl provider 白名单放行)——实现与 owner 拍板的设计完全一致,默认行为逐字节不变、#1382 安全属性(代理存在≠证据)由证据链保持,回归清点全部通过、diff 干净、新测试四向都有牙;CI 唯一红点是 windows/node22 上一个与本 PR 零代码交集的测试文件早期崩溃(本地复跑 296/296 全绿),判定为跑手环境抖动而非本 PR 引入——重跑该 job 后即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Deep-review complete — Approve with fixes applied on-branch (new head rebased onto current master + one commit).

Verified

  • Phase A semantics exact: opt-in (plugin.nonHttpProviders / BILI_NON_HTTP_PROVIDERS) relaxes ONLY the ownsCompaction veto (src/agent/pi.ts:410-418); the carriage-evidence gate (carriedSids / omp identity / /__bili/plugin/status probe) still decides — unrouted traffic never cancels, so Pi plugin cancels Pi's auto-compaction for conversations the proxy never sees (breaks pi-claude-bridge) #1382 cannot recur for a newly-opted-in class. Zero exec surface: bili never spawns or parses the stdio spec; allowlist comes from user config/env only, compared against host-supplied ctx.model.provider — no model-controlled input.
  • No MITM/wire widening by construction: the flag's only consumer is pi.ts:417 (grep-verified); proxyBaseFromUrl requires http(s) and opaque schemes fail URL parse, so non-http baseUrls structurally stay outside /bili/ rewrites, stamped cache keys, and MITM candidacy (注入零文件化:废除 overlay/临时目录机制(#531 设计返工) #535 drop test untouched, passing).
  • fix: cancel pi/omp auto-compaction only on evidence the proxy carries the conversation (#1382) #1383 default intact: master's veto sub-cases pass; new case (A) re-asserts with the env deliberately unset; withEnv deletes on undefined so no leakage.
  • Lanes share the one gate: omp/native reuse createBiliPlugin, launcher exports for both bases; runTestPi omission is consistent (--no-extensions).
  • Gates on-branch: typecheck clean, plugin-agent 62/62 (incl. all four new cases), launcher 231/231.

Fixed on-branch

  1. Stale #1382 comment block (pi.ts ownsCompaction preamble) still claimed non-http "vetoes outright … cannot reach the proxy by construction" — contradicted the opt-in 12 lines below. Reworded to veto-by-default + opt-in-widens-candidates.
  2. Added case (E) regression guard: opted-in non-http baseUrl must stay outside destinationRoutedThroughProxy — pins the routing non-wiring so Phase B can't accidentally wire the flag into stamp eligibility.

Non-blocking notes

  • Provider-id matching is case-sensitive and fails closed (veto holds) — documented in-comment; acceptable.
  • Rebased +12 commits onto current master before merge (per §7.2); no semantic conflicts (drift regions are far from the PR's).

One decision to note: Phase B (actually riding traffic for stdio transports) remains future work — this PR deliberately ships only the veto relaxation. Fixes the #1392 Phase A scope.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Verified your review claims against the repo state — substance all checks out, but the fixed head is not on the remote: PR #1437's head and branch 2026-09-26_non-http-providers-optin are still 3e08e08f, byte-identical to what I reviewed before your comment.

Verified true on remote head 3e08e08f:

  • Only behavioral consumer of the flag is src/agent/pi.ts:417 (grep across src/: shared.ts:76 defines the parser, config.ts:902/909 + launcher.ts:809/839 are pure config→env plumbing, nothing else reads it).
  • destinationRoutedThroughProxy (src/agent/shared.ts:90, consumed only at pi.ts:148 stamp eligibility) never references the flag: non-http(s) protocols bail (url.protocol !== "http:" && !== "https:" → false), unparseable opaque baseUrls hit the try/catch → false. No MITM/wire widening possible via this flag.
  • Master is indeed exactly +12 commits ahead of the PR base — matches your "+12" figure.

Not present on the remote (both "Fixed on-branch" items):

  1. The stale comment is still at src/agent/pi.ts:397 — "vetoes outright: such providers' traffic cannot reach the proxy by construction" — still contradicting the opt-in fall-through ~20 lines below.
  2. No test references destinationRoutedThroughProxy anywhere in tests/ on the branch. Note: the (E) at tests/plugin-agent.test.ts:408 is the pre-existing Pi plugin cancels Pi's auto-compaction for conversations the proxy never sees (breaks pi-claude-bridge) #1382-test case label ("Local stamp fast path"), not the new routing-non-wiring guard you described.

Scanned all open PRs and branches — no candidate carrying the rebased/fixed head. So the rebase + two fixes appear to live locally (or the push didn't land). Please push the fixed head to ranxianglei/billion-context:2026-09-26_non-http-providers-optin — merging the current remote head would ship without both fixes and 12 commits behind master. Once pushed I'll immediately re-verify (final diff vs master, targeted tests, CI incl. the win22 cell — whose flake class is separately addressed in #1447).

One heads-up for the rebase: src/launcher.ts is currently hot — open PRs #1450 (buildXxxEnv convergence) and #1451 (runLaunch cert-MITM env dedup) touch the exact regions adjacent to this PR's changes; expect a semantic (not textual) conflict there if they land first (§7.2). Merge itself stays human-only either way.

中文摘要:已逐项核实你的深度评审结论——「flag 唯一行为消费点是 pi.ts:417」「非 http(s) 结构性留在路由/stamp/MITM 之外」「master 确实领先 12 个提交」均与远端代码一致;但远端 PR 分支仍停在旧 head 3e08e08,你所说的两处分支内修改(pi.ts:397 过时注释改写、destinationRoutedThroughProxy 回归测试)都不在远端(408 行的 (E) 是既有 #1382 测试的标签,不是新用例)——请把 rebase 后的新 head 推到 PR 分支,我随即复检 diff、定向测试与 CI;另提醒 launcher.ts 正被 #1450/#1451 同时改动,rebase 时留意语义冲突。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Owner decision applied (head 50fa4b5): the plugin section is gone — opt-in folded into the existing providers table

The owner rejected a new top-level plugin.nonHttpProviders section (config surface sprawl). The opt-in now lives where users already look:

{
  "providers": {
    "https://api.anthropic.com": { "models": { ... } },
    "claude-bridge": { "compactionOptIn": true }
  }
}
  • Key = provider id. A non-URL key is inert for routing (longest-prefix matching never hits it; verified against loadRoutes/parseRouteEntry — unknown fields ignored, no URL validation on keys).
  • compactionOptIn: true (strict boolean) opts the provider id in; false/"yes"/absent are ignored. Env mirror BILI_NON_HTTP_PROVIDERS unchanged (union with file, deduped).
  • Semantics identical to the previous shape: opt-in only widens the compaction-ownership candidate set — carriage evidence (session stamp / /__bili/plugin/status) still decides; wire-side routing, MITM, stamp eligibility all unaffected (Phase-A guard test E keeps pinning that).
  • Docs: compactionOptIn field reference added to the Providers section (CONFIGURATION.md + zh), launcher prose updated, FileConfig.plugin type removed.

Gates: typecheck ✓ · launcher+plugin-agent 293/293 · config suites 34/34.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Verified 50fa4b5 end-to-end — but first, one blocking logistics problem:

⚠️ The remote branch does not point at this work

The PR branch ref currently points at b4f78b37 ("Merge branch 'master' into …"), a merge commit built on top of the OLD head 3e08e08f. It contains neither the round-2 fixes nor the owner-decided config shape — on that tip compactionOptIn appears nowhere and the rejected plugin.nonHttpProviders section is still at src/config.ts:930/982. Merging the PR as it stands would ship the design you just rejected.

Good news: nothing is lost. GitHub still serves 50fa4b5 (I fetched it directly by SHA — full lineage c1d2f498 → 50fa4b5 is intact and locally available here). It was simply orphaned when the stale-state master merge got pushed on top of the old head.

Suggested action: restore the branch to the linear two-commit lineage rebased onto current master (c1d2f498 fixes → 50fa4b5 refactor), replacing the merge commit. Two reasons this is needed regardless of the ref mix-up:

  1. The base is stale anyway — it was cut from pre-feat: expose compress.priceProfile {w,r,q} for cache-economics reports #1285-rewrite master and is 12 commits behind now; after a clean rebase the diff collapses back to the real ~8-file change (the current raw diff stat of +1696/−72 is mostly stale-base noise from rewritten feat: expose compress.priceProfile {w,r,q} for cache-economics reports #1285 commits).
  2. §7.2: one linear commit, clean diff — a merge commit in the PR history buries the real change.

I have the whole lineage locally and can do the rebase + push to your branch immediately if you confirm — otherwise push from your side. Once the real head is up, I'll do the final diff check and give the closing verdict. (CI on the current wrong head is 13/13 green including windows-22 — the flake class didn't recur there, but that green run doesn't count for the actual code.)

Verification of 50fa4b5 itself — all claims hold

Fetched the commit, read the code, ran the gates locally (worktree @ 50fa4b5, removed after):

  • resolveNonHttpProviders (src/config.ts:~923): strict compactionOptIn === true; non-object values skipped; keys trimmed, empty dropped; Set-union with BILI_NON_HTTP_PROVIDERS env list, deduped ✓
  • Non-URL keys inert for routing — independently verified beyond loadRoutes/parseRouteEntry: normalizeUrlKey is a pure trailing-slash strip (never throws on "claude-bridge"); rejectLegacyRoute fires only on string values; matching is upstreamUrl === key || upstreamUrl.startsWith(key + "/") (src/config.ts:512) against request URLs already validated as http(s) (src/server.ts:174) — a non-URL key can never match. Checked the other loadRoutes consumers too (server opts/warnings config.ts:791, launcher budget-alignment window launcher.ts:3233, web API web/api.ts:44): { compactionOptIn: true } parses as an empty route (no models/proxy/compress) → inert everywhere. The Phase-A guard test pins the extension side (tests/plugin-agent.test.ts:539-543: destinationRoutedThroughProxy("claude-bridge") === false).
  • Round-2 fixes carried through: the pi.ts preamble now reads correctly ("A non-http(s) baseUrl vetoes by default (opt-in … only widens the candidate set; carriage evidence still decides)") and guard test E is present.
  • FileConfig.plugin fully removed — grep shows only the expected plumbing left (shared.ts parser, pi.ts consumer, launcher env mirror).
  • Docs: both CONFIGURATION.md/.zh-CN.md gained the ### compactionOptIn field reference in the Providers section plus the updated pi/omp bullet.
  • Local gates: typecheck clean; node --import tsx --test tests/launcher.test.ts tests/plugin-agent.test.ts tests/configured-window-outranks-registry.test.ts = 295/295 pass, 0 fail (consistent with your reported 293/293 + config split).
  • Edge case checked: compactionOptIn: true on a URL key (e.g. https://api.anthropic.com) is accepted but harmless — http(s) providers never hit the veto path; your test at tests/launcher.test.ts:2250 documents exactly that. No behavior change beyond what's already disclosed.

Semantics vs the previously-disclosed version: unchanged — opt-in widens the candidate set only, default stays byte-for-byte identical, #1382 property preserved.

Merge stays human-only, as always.


中文摘要:50fa4b5 的实现已逐条核实无误(严格布尔、非 URL 键对路由完全惰性、round-2 两项修复都在、本地 295/295 全绿),但远程分支当前指向的是旧代码上的一个 master 合并提交(b4f78b37),既不含新配置形状也不含上一轮修复——现在合并会发错版本;请把分支恢复为 rebase 到最新 master 的线性两提交(c1d2f498→50fa4b5),我这边已持有完整提交链,确认后可立即代为 rebase+push。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Closed without merging (owner decision). The line consolidates into the one-shot design in #1469, which includes the compactionOptIn field natively — landing it here first would recreate exactly the intermediate state the owner rejected (#1466's lesson).

Nothing user-facing is lost by closing:

When #1469 is implemented (or Path B wins and the surface dissolves), the wiring lands there in one piece. Branch stays available for salvage.

ranxianglei pushed a commit that referenced this pull request Nov 20, 2026
…efault off)

⚠️ MODEL-FACING TEXT CHANGE — the success compress receipt changes what the
model reads: with the new default (compress.postComPressTail off, the
pre-existing behavior is NOT the default), the receipt no longer re-advises
the remaining foldable ranges after every successful fold, and no longer
emits the 'Uncovered history remains' audit note. With it on (explicit opt-in),
the range list is restored and the uncovered note fires at most once per
nudge-injection cycle (fresh injection re-opens it). The verbatim
context-minimum stop signal is unchanged in both modes.

Consumption-chain reasoning (#6855 discipline): the removed text carried the
only forward-pointing refs the model propagated into its NEXT compress call
(startId/endId copied from the 'Current compressible ranges' list). Removing
it removes the propagation anchor entirely — no phantom-value class possible.
Nothing else in the receipt is altered byte-wise; the stop-signal sentence
(#1387) is preserved verbatim, so models that key on it see identical text.
The per-turn growth nudge (KDD #8) is a separate channel and untouched.

Why: per-receipt re-recommendation drove models into endless fold loops
against explicit user stop requests (#7318: 200+ folds in one night on a
0.1.216 build; #6522 '不要连续推荐' and #5872 are the same family — the
receipt footer drives single-message retry folds). Each fold rewrites the
context prefix and re-bills the prompt cache.

config surface (#1437 discipline, owner decision in-thread 2026-11-20):
adds compress.postComPressTail (boolean, default off) to the existing three-
level compress hierarchy (global/provider/model via mergeCompress); boolean
only (non-boolean rejects the whole block like the sibling requireNudge /
requireRecommendation); no new env var (knob goes through the existing
compress file hierarchy, env-discipline #2030). Docs: config-reference seed
entry + regenerated configuration.md en/zh/ja + website.

Plumbing: the flag is stamped per round on session.transient next to the
existing nudge gate (src/unprompted-gate.ts) and read at the tail decision
point in src/stream.ts — off by default when a session has no stamp
(defensive: never recommend on an unknown posture). The #6522 at-most-once
latch rides on an in-memory Session field (uncoveredReceiptNoted), re-opened
only by an actual nudge injection.

Fixes #7318 (design: default off); implements #6526's at-most-once note (that
PR is superseded — its change was unconditional, this one is gated).
Supersedes: #6526
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.

[investigation] Non-http baseUrl providers (pi-claude-bridge etc.): an opt-in path to ride bili — beyond the #1383 stopgap veto

1 participant