Repository navigation
fix: count projected thinking mass in the host estimator so k̂ calibration stays caliber-honest (#2407) - #2418
Conversation
…ation stays caliber-honest (#2407) estimateCoreMessages counted only m.text, so the k̂ calibration denominator (prepare sites) divided a bill that includes restored thinking tokens by an estimate that excludes them — thinking-heavy routes learned an inflated factor (up to the 4× clamp) and over-triggered compression. Route the estimator through the kernel's countMessageTokens (text + thinkingTokens), the same caliber the kernel's own meters use; acp_status's est-view total follows so the BILLED/est ratio stays honest on thinking routes. Fixes #2407
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2616-pr.2418.7befb92This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2418.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 审查完成。结论:可合(CI 27/27 全绿、mergeStateStatus clean;本地定向验证全绿;回归 pin 已验证在 unpatched master 上确实失败)。合并留给人工——此 PR 跨 3 个模块触碰热文件(preflight/server/budget 消费面),按 §7.4 不属于 auto-merge 档。 审查证据
结构化结论(八问)1. 是什么问题:k̂ 校准分子是上游实际计费输入(含 restored thinking),分母 2. 什么原因导致的:分子/分母口径不对称(根因层),不是采样逻辑错。膨胀是 composition-stable 的(thinking share 稳定时比值恒定),因此穿过全部证据门(band [0.2,5]、x2 一致性、≥2 样本、route+model keying)被发布——这正是 #2407 的核心判断,本 PR 的 pin 3/4 数值(1.05 vs 1.75、≈0.95 vs 3.5)与此吻合。 3. 影响范围与严重程度:仅 extended-thinking(Claude signature block)且 thinking share 稳定的路由;受 4× clamp 与 usage baseline floor 双限界。Medium——是 #1933 损伤类(过度触发/fold churn)在 thinking 路由上的可达通道;非 thinking 会话字节级不变。 4. 怎么修复的:在源头统一口径,而不是逐调用点打补丁——host 估计器改走 kernel 自己的 5. 是否有回归问题:逐点审过既有行为,结论如下——①非 thinking 会话: 6. 是否破坏缓存:不涉及。prefix cache/重试/去重键均未触碰;校准 ring 是会话内内存态,键(origin+model)不变,仅 thinking 路由的值语义变化,window=3 在升级后 ≤3 个 turn 内自愈,无需迁移。 7. 是否改了设计方向:没有转向,是回正:k̂ 回到 #1933 F1 原始意图(纯 tokenizer 偏差因子),host 侧估计器与 kernel 计量收敛到单一口径源,消除双轨。 8. 是否引入了新的配置:无。无新 env/config/默认值,无 kernel 改动(
|
[bot] 🏷 收到系统提醒。审查结论已在本 issue 4 楼完整发布(comment id 25616):PR #2418 可合——CI 27/27 全绿、本地定向验证 134/134、回归 pin 1/2 已实测在 unpatched master 上失败(有牙)、13 处消费点口径逐点核对无回归;含结构化八问与行为变更披露(估计器口径 text-only → text + projected thinking mass)。本条仅为提醒确认,无新增内容。唯一待办:人工 merge(https://github.com/ranxianglei/billion-context/pull/2418),合入后 #2407 可关。 |
prepare-google.ts was the only one of the four protocol lanes never writing stats.lastLocalTextEstimate, so Gemini-native routes could never learn the calibration factor — settleUsageReport found no pending pair and every downstream gate stayed raw-estimate caliber. Mirror the anthropic/openai/responses write (same estimateCoreMessages caliber, title-gen side requests skipped like the #532 rows above).
|
Addendum (小问题直接修): Google 车道补上 k̂ 分母。 排查 #2407 时发现 新测试 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.143-master.c296fb4 # this exact build
npm install -g billion-context@master # always the newest merged build
|
What
Follow-up to #2369, fixes #2407.
estimateCoreMessages(src/preflight.ts) counted onlym.text. Signature-only thinking blocks (#1320) bill upstream but project as empty text; the residual is attributed toCoreMessage.thinkingTokens— so the k̂ calibration denominator (the prepare sites) divided a bill that includes restored thinking tokens by an estimate that excludes them. Thinking-heavy routes learned an inflated factor (composition-stable, passes all evidence gates, bounded only by the 4× clamp) and over-triggered compression.Change
estimateCoreMessagesnow goes through the kernel'scountMessageTokens(m, defaultCountTokens)(text +thinkingTokens), the same caliber the kernel's own meters (recommend/receipts/status) already use. Every consumer — k̂ denominator at the prepare sites, preflight fit/round budgets (preflight.ts:1088/:1195), fit gates (server.ts:4697/:4735/:4753), output clamp (budget.ts:48), image-costtextSide(loop/core.ts:399, server.ts:5104) — now carries billed-caliber mass. This also closes a latent inconsistency: the kernel counted thinking mass in its recommendations while the host fit gate ignored it.est-view totalline follows, soBILLED INPUT · est-view · ratiostays honest on thinking routes (same caliber as the kernel-rendered per-message breakdown).lastLocalTextEstimateupdated.Why this is safe
thinkingTokensonly ever exists afterprojectThinkingMassran (Anthropic lane, real usage report present) — every other lane/session is byte-identical (+0).Tests
New
tests/issue2407-thinking-caliber.test.ts(4 pins):estimateCoreMessagescountsthinkingTokens(exactly thecountMessageTokenscaliber);estimateCoreMessages(msgs) + overhead == measured(the residual is absorbed exactly);Local: typecheck clean, all estimation-relevant suites green. Full-suite local run's only failures are the environmental attach-mode/installer class that clean master also fails locally (CI passes them) — CI is the gate.
Not config / not kernel
No config surface change, no
kernel/change — pure host-side estimator caliber.