Repository navigation
[PR] fix: price compression savings at the session's billed average, not the last model's list price - #7238
[PR] fix: price compression savings at the session's billed average, not the last model's list price#7238ranxianglei wants to merge 2 commits into
Conversation
…he last model's list price The web 用量统计 panel's 压缩节省 (savings) card priced the whole historical fold ledger at metadata.lastModel's live list price, while the 花费 (spend) card accumulates per-request at each request's stamped price. In a multi-model session, a single request to a cheaper model re-priced the entire fold history by orders of magnitude, so the two cards contradicted each other (e.g. spend $170.16 vs savings $6.35 where the session's actual billed average implied ~$370). Fix: when the session has a persisted spend ledger (stats.costUsd), calibrate the live price profile's LEVEL to the session's actual billed average (cu.cacheRead/cachedTokens, cu.output/outputTokens) before pricing the folds, keeping the live model's w:r:q SHAPE. A single-model session's billed average ≈ its list price, so behavior is unchanged there; ledger-less sessions fall back to the raw live tiers as before. Closes #7237
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.10918-pr.7238.dd06891This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7238.tgz
npm install -g packageInstall instructions are refreshed on each push. |
The parenthetical 'spend/miss mirrors use livePrice — same tiers whenever both' predates this PR: once a session's spend ledger exists, usdProf is calibrated to the billed average and can differ from the raw livePrice tiers. Restate what the two surfaces actually use.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。检索 open PR/issue:#2482(savings 展示功能,引入方,不同方向)、#3193(dryRun 预览,不同机制)均与本 PR 无关;无其他在途 PR 修 #7237。 标签: bug, p2, scope/ui(统计面板数值缺陷,面板域;数值错但核心功能可用,未达 p1) CI(审查时实测): head 7d64301 的 119 项 check run = 12 success / 15 skipped / 3 in_progress,无红。我补了一个 comment-only commit(见下)后 CI 在新 head 重跑中。 结构化八问
测试有效性
顺手修src/web/sessions-data.ts:955 注释 "spend/miss mirrors use livePrice — same tiers whenever both" 在校准后与代码事实不符(usdProf 与 livePrice 可以不同)——已当场修正,commit 判定: 可合(等新 head CI 全绿)。 |
是什么问题
Web 用量统计面板的「压缩节省」卡片用最后一个请求所用模型的实时列表价(
metadata.lastModel)去给整段历史 fold 账本定价,而「花费」卡片是按每个请求各自盖戳的价格逐请求累加的(跨模型精确)。多模型会话里,只要有一次请求切到更便宜的模型,就会把整段历史按新价重算,两张卡片因此互相矛盾:例如花费 $170.16(正确)对节省 $6.35(被便宜的 deepseek-flash cacheRead 0.003/Mtok 重定价),而按该会话实际计费均价应约 $370。根因
billInputUsage/billOutputUsage(src/billing.ts:199/212)按每请求盖戳价累加进session.stats.costUsd(stampBillingPrice最新优先,src/billing.ts:157)——跨模型正确。livePriceForSummary(src/web/sessions-data.ts:664)只从metadata.lastModel解析价格;lastModel在每个入站请求都被写(src/server/handle.ts:3083);savedUsdProfileForSummary在有 live 价时原样返回{w:live.cacheWrite, r:live.cacheRead, q:live.output};savedUsdFromFolds(src/billing.ts:229)用该 profile 给整段历史 fold 定价。修法
当会话有持久化花费账本(
stats.costUsd)时,把 live 价格 profile 的价位校准到会话实际计费均价(cu.cacheRead/cachedTokens、cu.output/outputTokens),再给历史 fold 定价;保留 live 模型的 w:r:q 形状(只重锚价位)。单模型会话计费均价≈列表价,行为不变;无账本会话回退到原 live 价(与之前一致)。测试
新增两条回归测试(tests/billing-web.test.ts):
已验证:无修复时多模型测试失败(savedUsd −0.0019),加修复后 21/21 全绿;typecheck + build 通过。
Closes #7237