Repository navigation
fix: separate calibrated context display from the safety bound; add model provenance to k̂ (#2117) - #2142
Conversation
…odel provenance to k̂ (#2117)
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2291-pr.2142.e66dfb2This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2142.tgz
npm install -g packageInstall instructions are refreshed on each push. |
… B x #2129) Merged-tree CI red: #2129's restart e2e 502s on this branch's head. The restore whitelist drops ring.model / calibratedEstimateModel (#2141 gap), so after a restart the first usage settle saw a model-less ring vs a known settle model, treated it as a cross-model switch, reset the ring, and the insufficient-samples branch deleted the just-restored k̂ — reintroducing the #2122/#2129 incident shape (over-raw resend folds instead of forwarding). The factor gate (currentCalibrationFactor) already follows "missing info never invalidates"; the ring condition now does too: a model-less ring continues and adopts the first known model; a known-vs-known mismatch still starts a fresh ring. Provenance stamps from the ring key so an unknown-model settle cannot blank an established one. Tests: re-pinned the two B-ring cases that asserted discard; the #2129 e2e (forward-without-folds after restart) is the regression pin — green on the merged tree again (68/68 targeted).
[bot] 🏷 Review 完成:发现并修复一处跨分支语义回归(已推 additive commit),其余通过。合并判定见文末。 审查范围(不止读 diff):
结构化七问
测试有效性:新文件 8 个测试断言有牙(gate 三态、legacy≡ 四协议、选择器阶梯七例、环键控含切回/legacy/未知模型、边界清理、hermetic e2e 走 startServer 真链路);#2129 e2e 是本回归的兜底钉(forward-without-folds 全链路)。作者定向清单遗漏 #2129 文件的根因是基线陈旧(§7.5 重灾区 1),不是测试质量问题。diff 整洁度:9 文件全部与本 PR 目的相关,无跑题/空白噪声 ✓。 遗留事项:#2141(加载白名单不恢复 k̂/环/锚点字段族)仍在独立处理中——补修后即使白名单未补齐,重启后 k̂ 也能存活(环采纳模型并重发布);#2141 落地后 model provenance 也完整往返,届时本 PR 的注释引用自然闭环。floor 4 你问的"平滑过渡"按 floor 6 的结论执行(立即失效、基线地板兜底),实现与之一致 ✓。 判定:代码质量与方向均达标;跨分支回归已由我在 PR 分支修复( |
|
冲突 |
# Conflicts: # src/web/sessions-data.ts
[bot] 🏷 冲突已解决,CI 21/21 全绿(head 一、冲突原因与解决master 期间合入的 #1937(bounded web sessions index) 重写了
二、顺带发现:master 自 #2152 起就是红的(非本 PR 引入)冲突后第一次 CI:4 个 test job 全部挂在同一个测试
行为变更披露(旧值→新值):全新安装(或持久化从未写过任何会话)时 三、结构化七问
已知非阻塞边角(记录不改):display anchor 不按 route 隔离——切到从不报 usage 的新 route 时,飞行中会短暂显示带「估算·未校准」标签的 billing-caliber 值(决策路径不受影响,标签如实)。遗留 #2141(persist 白名单不恢复 k̂/环,每次重启丢校准)仍单独挂着。 判定:可合并——冲突已解、master-red 已修、CI 21/21 绿( |
|
又冲突 |
[bot] 🏷 收到,正在查 master 新进的冲突提交并解决,完成后报告。 |
# Conflicts: # src/web/sessions-data.ts # tests/web-sessions.test.ts
[bot] 🏷 第二次冲突已解决,CI 24/24 全绿(head 冲突原因master 这批新进的提交里,#2180( 对比后 master 的 #2180 方案更严谨,我直接采用它的实现、放弃我这版:
我的版本会把「用户显式配错 行为变更披露(相对我上一轮回复):上一轮我说「缺目录无快照 → 空索引」,经 #2180 细化为——仅 pristine 默认布局(真·全新安装)返回空索引;显式 验证
分支现在共 4 个增量 commit: 判定:可合并——两轮冲突均已解决且全部向更优的 master 实现对齐,无残留回归,等人工合并。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.61-master.9268d7c # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2117
What
The admin page rendered the char-count upper bound of the last outbound send on the same progress bar as upstream-measured usage, with no provenance distinction — a mid-request refresh could read "206K / 204K(估算)" while the settled usage of that request was 98K (~2.1× gap from counting every character as one token). Separately, the learned estimator scale k̂ (#1933 F1) was keyed by route only, so a mid-session model switch kept applying another model's billing scale.
Changes
A — display caliber separation (display-only; decision paths byte-identical)
forward()additionally publishesstats.contextEstimateTokens/contextEstimateCalibrated: the billing-caliber estimate of THIS send — preflight's own formula (CJK-awareestimateCoreMessages+ wire overhead), k̂-scaled only where the factor's route+model provenance matches (DSH: 切换模型后,preflight 在窗口远未满时提前触发压缩 #1933 F1 / below), plus the image reserve. The char-count bound stays published exactly as before (localInputEstimate/contextTokens, sourceestimate) — unchanged values, still the fail-closed caliber for never-reporting upstreams (fork 会话 lastInputTokens=0 时 preflight 退化为字符估算,大载荷被低估后不压缩直接裸转上游 #553/[Bug] 上游从不报告 usage 时 nudge 永不触发——上下文无界增长直到超窗(ChatGPT 登录态后端) #728/[Bug]Preflight compression uses raw-history estimate instead of compressed-payload size — 42–203s stall per request, saves ~1K tokens #1493).displayContextBest()selector (src/session.ts, same precedent as fix(#2029): status readers share provenance-aware input baseline #2056'sstatusInputBaseline): usage > anchored calibrated estimate > labeled upper bound. A never-reporting upstream has no anchor → keeps the fail-closed upper-bound display (no optimistic rate without evidence). Legacy sessions without the new field render exactly as today.outboundContextEstimates()returns both calibers in ONE projection pass; legacyoutboundContextEstimate()is now a thin wrapper returning.upperBound(issue2078 suite pins it green).B — k̂ model dimension
calibrationRing.model, newcalibratedEstimateModel); publish/clear carry the model; all read sites (preflight gate ×2) go through newcurrentCalibrationFactor(), which treats a cross-model factor as ABSENT (raw estimate) while keeping factors whose model is unknown on either side — missing information never invalidates, legacy factors retire through normal ring rollover.Behavior changes (disclosure)
Config surface
NONE. No new config keys, env vars, or CLI flags. Internal
session.statsfields only; the web JSON API is additive (optionalcontextBest,contextUpperTokens,lastInputTokensOrigin,contextMeasuredAt,estimateCalibration). Session-file format: new optional stats fields are saved via the existing whole-stats spread and simply absent on load (existing loader-whitelist behavior — see #2141 for the drift this exposes).Tests
tests/issue2117-context-estimate-provenance.test.ts(8 tests): gate semantics (invalid/cross-model/missing-info), both calibers ≡ legacy across all 4 protocols, ASCII over-count gap, display-selector provenance ladder (usage / anchored±calibrated / unanchored / empty), B-ring model keying incl. switch-back discard & legacy-ring restart & unknown-model continuity, compaction-boundary cleanup, hermetic e2e through startServer (usage settle → k̂ published with model provenance → next send shows calibrated estimate < bound/2).Found while working → filed separately
#2141 — persist.ts load whitelist does not restore k̂/ring/localInputEstimate/lastUsageGradeTokens despite session.ts comments claiming persistence (every restart silently loses calibration). Distinct failure domain (persistence fidelity), NOT bundled here.