fix #648: add hostUsageCredit switch to opt out of #408 host-usage backfill - #649
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-649Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr649.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 PR #649 审核完成 ✅ 结论:技术正确、预检通过、无重复;按当前 审核(在 PR head 上逐项重验)1. 代码正确性
2. 预检(我在 PR head 重跑)
3. 重复判定 — 与在飞的 #647(codex UA 豁免,fix #645)互补而非重复:#647 按 UA 豁免 codex(其 待你拍板的一点(我给出明确建议)建议:保持
你定。若拍板保持 小项
|
|
解决冲突 |
…ckfill Plain proxy clients (ZCode on the anthropic wire, no plugin header, no special UA) fell through every #408 backfill exemption (pi/omp by pluginAgent, codex by UA) and got the full uncompressed-baseline backfill armed. Their UI then showed a cumulative, drifting baseline (real folded value + per-compression backfill) instead of the actually-forwarded context — overstates real pressure, and the per-round est drift makes it non-monotonic on pure-append turns. Add a hostUsageCredit config option (auto|off, default auto = current behavior). 'off' disables the backfill entirely so the host sees the folded request's own usage, matching [acp-usage] input=. Documented in CONFIGURATION.md (BILI_HOST_USAGE_CREDIT). Regression tests cover both sides of the gate on the anthropic wire.
1fd8806 to
6fba944
Compare
[bot] 🏷 ✅ 冲突已解决,PR 现在 冲突点(很小)master 从 v0.1.95( 解决方式
预检(rebased head 重跑)
现状
可以安排 review/合并了。 |
What
Plain proxy clients (ZCode on the anthropic wire — base-url → proxy, no
x-bili-pluginheader, no special UA) fell through every #408 backfill exemption (pi/omp bypluginAgent, codex by UA in the in-flight #647) and got the full uncompressed-baseline backfill armed. Their UI then showed a cumulative, drifting baseline (real folded value + per-compression backfill) instead of the actually-forwarded context: it overstates real pressure, and the per-round est drift makes it non-monotonic on pure-append turns.Add a
hostUsageCreditconfig option (auto|off, defaultauto= current behavior).offdisables the #408 backfill entirely so the usage reported to the host is the actually-forwarded (folded) request, matching[acp-usage] input=.Changes
src/config.ts:hostUsageCredit: "auto" | "off"onProxyOptions+FileConfig,parseHostUsageCredit(), wired inloadOptionsfromBILI_HOST_USAGE_CREDITenv /hostUsageCreditfile key.src/server.ts:armHostUsageCredit()takes the mode and returns early on"off"(before the pi/omp pluginAgent check); all three call sites (prepareAnthropic/prepareOpenai/prepareResponses) passopts.hostUsageCredit.tests/host-usage-backfill.test.ts: two anthropic-wire regression tests with a real kernel fold (relay emits acompresstool_use) —offreports the folded request's own usage (no backfill), and theautocontrol still gets the 代理压缩不上报改写量,宿主上下文会计塌缩至 ~0(omps recordAnchoredHistoryRewrite 零调用);且持久化 lastInputTokens 恢复无钳制,旧版负值升级后复活 #408 backfill.CONFIGURATION.md: documentBILI_HOST_USAGE_CREDIT.Why a switch (not a hard exemption)
The #408 backfill exists to keep a host's native auto-compact alive by showing the uncompressed baseline. Whether that helps or hurts depends on the host: pi/omp cancel it (exempted), codex keys off
total_tokenswhich the backfill never touches (exempted in #647). For plain proxy clients like ZCode the value is host-specific and not knowable from the proxy — so an explicit switch (the issue's recommended primary mechanism) is the safe default rather than guessing.autokeeps today's behavior for everyone; ZCode users sethostUsageCredit: "off"(orBILI_HOST_USAGE_CREDIT=off) to get the actually-forwarded value.Pre-flight
npm run typecheck— cleannpm test— 1241/1242 pass; the single failure (launcher.test.tsresolveClientCommand: codex/claude resolve to themselves) is a pre-existing environment issue (this box hascodexat/usr/bin/codex) and fails identically on the base commit5836f78— unrelated to this change. All 23 host-usage-backfill tests pass, including the 2 new ones and the existing pi plugin 模式宿主 usage 回填未压缩基线:footer 显示 302.7%/1M 与实际请求(折叠后 ~57K)不符 #590/omp 插件会话原生压缩被扩展全部取消后仍收 #408 usage 回填: omp footer 只增不减 (205%/1M) #623 pi/omp tests.npm run build— successFixes #648