fix: drop hostUsageCredit — report provider-measured usage only (#660) - #691
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-691Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr691.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 Reviewing now. Confirmed shape: a single clean commit ( I'm independently re-running the pre-flight ( |
[bot] 🏷 Review complete — mergeable, with one narrow backward-compat edge worth your sign-off. Independent pre-flight (re-ran on
Diff cleanliness (first gate): single commit straight on top of current master ( Correctness checks I ran beyond reading the diff:
Findings (none blocking):
I did not push anything — no changes to the branch. Happy to land the #2 clarifying comment (and optionally the #1 map seed) directly on the branch if you want them in before merge. 中文摘要:PR #691 已独立复验(typecheck 干净、测试 1319 通过、构建成功,diff 干净无杂项),核心改动正确且「信用仅用于展示、内部账本恒为折叠后值」这一不变量成立,可以合并;唯一需你拍板的是遗留 |
) Flip the #408 host-usage backfill default from baseline to post-fold: the usage reported to every host is now the actually-forwarded (folded) request — the tokens the model really receives — which is sane for any display and fixes the >100% drift that hit pi/omp/codex/ZCode when shown the uncompressed baseline. config: hostUsageCredit values are now postfold|baseline (default postfold); legacy auto->baseline and off->postfold still parse so existing configs keep their chosen behavior. server: armHostUsageCredit resolves via resolveHostUsagePolicy (a per-host map keyed on the announced agent type, falling back to the global switch) instead of a hard-coded pi/omp/codex exemption chain. Adding a host = one map entry, not a new if. opencode (a plain proxy client that never registers) now gets post-fold by default, closing the gap noted in #660. tests: wire-level regression for the default-postfold path (plain client) plus baseline opt-in controls; parser unit test. docs: CONFIGURATION.md BILI_HOST_USAGE_CREDIT row updated. Fixes #660
The opt-in baseline backfill remained a bug after every gate existed: a virtual number the model never receives (model sees ~4K, host sees 36K), drifting turn-to-turn as the kernel re-stacks blocks, able to exceed the context window (repro 1315 > 950K), and contradicting our own [acp-usage] ledger line. Post-fold provider measurement is already correct on every backend (sglang / OpenAI / anthropic) because the provider counts the exact folded body — so the entire baseline machinery is deleted: config switch + env var + web UI field, backfillHostUsage + estimateTokensOfMessagesFromWire + buildUncompressedContextEstimate, the credit field and both session counters, and all four suppression gates (#590/#623 pluginAgent, ledger ([acp-usage]) is untouched. Net -379 lines; docs rewritten (README/AGENTS/exit-matrix/CHANGELOG note); tests renamed to host-usage-postfold and re-pointed at the verbatim-forwarding contract (pi/omp/zcode/codex e2e flipped from "suppressed" to "the rule"). Pre-flight: npm run typecheck ✓; full suite 985 pass / 0 fail (incl. 5 e2e clusters); npm run build ✓.
The option no longer exists after a49270d deleted the mechanism; CONFIGURATION.md still described it (stale since 8c9367c) and CONFIGURATION.zh-CN.md never got a counterpart row (#648 documented the option in English only). Both tables now carry the removal note. Legacy values in env/file config are ignored (config parser only reads known keys).
c9ead44 to
ef8967f
Compare
What
Implements issue #660: the post-fold provider measurement is now the only usage reported to any host — the
hostUsageCreditoption (and the entire baseline-backfill machinery behind it) is deleted.Two commits:
8c9367c— originally flipped the default to postfold and made the baseline opt-in.a49270d— after review (m00045+ thread on Redesign #408 host-usage backfill: post-fold by default, baseline opt-in (opencode gap + whack-a-mole exemptions) #660) the opt-in was judged a bug, not a preference: removed the switch entirely (config.tskey/env/web field,backfillHostUsage, the four suppression gates for pi/omp/codex/plain-client, session credit fields + counters). Net -379 lines.Why delete instead of flip the default
The backfill number is a virtual cumulative estimate the model never receives:
[acp-usage]ledger line (input = the provider-measured post-fold value).Provider-side counting after the fold is exact by construction (sglang / OpenAI / anthropic all count the folded bytes that actually went out), which is why #589/#644/#649 all converge on "forward the provider number as-is".
The internal stats ledger (
session.stats/[acp-usage]) is untouched — that path was always verbatim.Docs & tests
README, AGENTS.md, exit-matrix doc, CHANGELOG note rewritten.
tests/host-usage-backfill.test.tsrenamed →tests/host-usage-postfold.test.ts, re-pointed at the verbatim-forwarding contract (unit: strip/pipe passthrough + split semantics retained; e2e: pi/omp/zcode/codex clusters flipped from "suppressed" to "the rule"; openai-chat prepareOpenai assertion flipped). Issue#589 test suite updated to raw-frame forwarding.Pre-flight
npm run typecheck✓npm test: 985 pass / 0 fail (incl. all 5 e2e clusters)npm run build✓git grep) ✓hostUsageCredit为什么被整体删除(写给未来)#408 的 baseline backfill 不是「默认值选错」,而是设计之初就错——backfill 的本意就是展示一个模型永远收不到的数字。每次 prepare 请求时计算
credit = max(0, est(originalMessages) − est(processedMessages))(原始历史 token 估计 − 折叠后转发视图),写入session.hostCreditTokens,下轮请求开头清零,宿主可见 usage =total + credit。后续所有修复都只是在这一个 arm 调用前多加一条 early-return 豁免,没有一次质疑过机制本身:06e7fb1+80a9f89(#408 实现)12d62b6(#590)armHostUsageCredit(),函数首行加if (pluginAgent === "pi") return;(症状:pi 页脚 302.7%;pi 插件模式压缩由宿主本地执行,baseline 不驱动任何东西)b71f6e8(#623)"pi" || "omp"return(症状:omp 205%,同类 MCP/plugin 会话)6bc8eaa+941d0b2(#645)pluginAgent:"mcp"(与 claude 撞车,agent 类型门会误伤 claude)→ 改按 UA 检测:if (isCodexClient(headers)) return;,并把req.headers穿线到全部调用点;941d0b2补"codex"宽松子串兜底防新变体漏检2858db0+6fba944(#648)hostUsageCredit: "auto"|"off"(envBILI_HOST_USAGE_CREDIT),函数首行if (hostUsageCredit === "off") return;,想拿真值的用户自己 opt-out8c9367c(本 PR v1)resolveHostUsagePolicymap 替换 if 链,默认翻转为 postfold,opencode 入表a49270d旁证(可复现):ZCode 用户症状链 —— 上下文条 4%→37% 虚高、纯追加轮 11→14 跳涨且非单调、模型侧实际只有 ~4K —— 逐条对应
est(original)−est(processed)语义 + 内核块重组导致的漂移;bili 自己的[acp-usage] input=行一直记录真实转发值,两个数字必然有一个是谎话。识别「虚拟数字」的三个判据(全中就该删,而不是做成可选项):
教训:当一个数字错了,先问「这个数字的来源是否在我们系统的真值集合里」,而不是先问「哪些客户端会看到它」。provider 侧计量天然在真值集合内(它数的是折叠后真正发出的字节)。豁免名单只会单调增长(pi → omp → codex → ZCode 写不出 → 开关兜底),每新增一个宿主变体都可能漏一格;开关出现的那一刻就是豁免法失败的证明——默认值仍在对未知的未来客户端撒谎。一个配置选项的保留成本由未来所有 bug 持续支付,删除成本是一次性的。