Repository navigation
feat: expose compress.priceProfile {w,r,q} for cache-economics reports - #1285
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1285Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1285.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 On it — pulling branch |
[bot] 🏷 Review complete — verified, can be merged. I pulled ① Original issue (#1279) — direction check. Confirmed the reported defect is real and the fix hits the root cause, not a symptom: pre-PR ② Regression surface — existing behaviors the diff touches, each judged:
③ Code. Clean and minimal (+237/-19 across 9 files). The trust-boundary guard on ④ Tests — real teeth. ⑤ Diff cleanliness. Every line serves the PR; the single cosmetic hunk is disclosed. No lockfile/generated churn, no unrelated files. Evidence:
Out-of-scope findings: both filed correctly with proper 来源 markers, one distinct problem each — #1286 (incremental ledger caps k at 1 via Auto-merge gate note: this is a 合并前唯一待办:人工 merge(agent 不合并)。结论:修复了缓存报告损益判定被硬编码为 Anthropic 价格权重的问题(#1279),新增可选 |
…ofile (#1279 follow-up) When no level sets compress.priceProfile, the session stamp now falls back to the request model's models.dev price row (absolute $\/Mtok: w = cost.input, r = cost.cache_read ?? 0.1*input, q = cost.output ?? 1.5*input). Known-provider hosts get their own listing; unknown relays take the first matching listing with a one-time conflict warning. Live catalog.json wins when reachable, bundled snapshot is the offline floor (snapshot rebuilt to carry 7126 cost rows). User config at any level still wins wholesale; unresolvable models keep the kernel relative defaults.
a9ebb77 to
f1c5933
Compare
…lback to kernel 4x, legacy-disk price fallthrough, e2e teardown hygiene (review round 2)
|
Round-2 review of the registry-cost follow-up commits (44f1bf5 / 7175e84 / f1c5933) — complete. One major fixed on-branch, head Verified correct
Fixed on-branch (0aa9945 + 2c1767f)
Noted for follow-up (not merge-blocking)
Gates on-branch: typecheck clean; targeted 43/43 (registry + price-profile suites). Ready to merge after CI. |
[bot] 🏷 Independent cross-check of the round-2 state (head Claim-by-claim verification:
Gates re-run by me on head One note on master drift: the branch base has moved (master picked up release v0.1.158 plus #1399/#1357/#1411 work since the PR's original base). Of those, only Follow-ups dispositioned:
结论:第二轮新增的 models.dev 定价接线(含 w=cache_write 重大修正、q=4×w 回退、遗留磁盘缓存价格黑洞修复、e2e 收尾卫生)已逐条对照内核公式与快照数据核实无误,本地全量测试 0 失败、CI 13/13 全绿,可以合并;dashscope/comfly 主机映射缺陷已另行立项 #1434。 |
Closes #1279
What changed
#800's approved design made the price profile optional ("价格档 (w,r,q) 可选配置;不配置则只给纯 token 单位"), but the implementation hardcoded it:
buildSessionCacheReportemittedprofile: { w: 1.0, r: 0.1, q: 4.0 }and calledcomputeFoldEconomics(...)without a price argument, so every fold's P&L verdict was priced at Anthropic-ratio weights regardless of upstream.This PR ships in two layers: (1) the optional
compress.priceProfileconfig, and (2) — per the #1417 review follow-up — wiring models.dev pricing as the default source when no level configures one.Layer 1 —
compress.priceProfileconfigcompress.priceProfile: { w?, r?, q? }— normalized multipliers over the input-token unit (p_in = 1):w= cacheWrite/input,r= cacheRead/input,q= output/input. Validated inparseCompressSettings(finite numbers >= 0; unknown subkeys ignored; malformed value rejects the whole block like every sibling). Merged sub-field-wise across the three levels (global -> provider -> model), same pattern asabsorb/ccr/reasoningGuard.session.metadata.cachePriceProfilewherecsalready resolves inrunPrepare(deleted when unset, latest-wins — mirrors theactivePackstamp).buildSessionCacheReportreads it with a small trust-boundary guard (persisted metadata is user-editable JSON), passes it tocomputeFoldEconomics, and emits the effective profile into the report'sprofilefield. Zero signature changes: every report face (acp_cachetool,/acp-cachecommand on all hosts,GET /__bili/cache-report) picks up the last request's config automatically.computeFoldEconomics(f, price?)andbuildCacheReport(samples, folds, opts.priceProfile)already accept the profile (acp-kernel 0.0.86 pin unchanged).Layer 2 — models.dev pricing as the default source (#1417 follow-up)
When no level sets
compress.priceProfile, the stamp site now falls back to the request model's models.dev price row instead of the bare kernel defaults.scripts/update-registry-snapshot.mjsnow pullshttps://models.dev/catalog.json(notmodels.json) and flattens the nestedproviders.<host>.models.<id>.costrows into a top-levelcostsmap keyed${host}/${id}, written alongsidemodelsin the snapshot. The offline floor therefore carries prices. Snapshot rebuilt: 428 models, 7126 cost rows.peekRegistryPriceProfile(model, host?)resolves a model to aPriceProfileusing the same root/variant/suffix mechanics aspeekRegistryContext(窗口溢出报错 #736). Known-provider hosts get their own listing (${provider}/${name}); unknown relays take the first matching listing across hosts (one-time warning on conflicts). Derivation:w = cost.input,r = cost.cache_read ?? 0.1 * input,q = cost.output ?? 1.5 * input; missing/non-positiveinput->undefined(never half-invent a profile). Derived multipliers are normalized to kill binary float noise (they print verbatim in the report header).runPreparestamps the registry profile only whencs.priceProfile === undefined; otherwise user config wins wholesale. Unresolvable models leave no stamp (kernel relative defaults apply downstream).models.jsonitself carries zero pricing — the live probe found 0costkeys across all 427 entries. Pricing lives exclusively incatalog.json's nested provider sections (7757 cost-bearing rows of 8181). That is why the builder switched endpoints.Docs
CONFIGURATION.md + CONFIGURATION.zh-CN.md
priceProfilesection now document both unit conventions (user config = normalized ratios p_in=1; registry default = absolute $/Mtok) plus the derivation, fallbacks, and override semantics. README.md/acp-cacheseam paragraph updated.Behavior change flag (report-only)
The profile never touches compression triggers, cadence, or any wire behavior — pure report surface. But the numbers in the report change, in two distinct ways:
compress.priceProfile, P&L fields and the reportprofilefield use it; each unset field falls back to the kernel default (w=1, r=0.1, q=4).{w:1, r:0.1, q:4}(Anthropic-ratio guess), byte-identical for every upstream. New: when the request model resolves in the models.dev registry, folds are priced at that model's absolute $/Mtok row (w=cost.input,r=cache_read ?? 0.1*input,q=output ?? 1.5*input); only unresolvable models keep the kernel relative defaults. Consequence: for a listed model the P&L magnitudes and breakeven/PAID BACK verdicts will differ from before — that is the intended fix (out-of-box reports now reflect the upstream's actual economics rather than an Anthropic assumption). The report header prints the active profile (@ w=.. r=.. q=..), so the unit convention in force is always visible.Note the two conventions coexist by design: a normalized user profile yields P&L in input-token-equivalent units; a registry-derived profile yields P&L in $/Mtok-weighted units. Both flow through the same kernel math; the header disambiguates.
Tests
tests/compress-settings.test.ts: three-level sub-field merge (deepest wins), absent-all-levels -> undefined, parse valid/partial/malformed (rejects strings/negatives/NaN/arrays/scalars).tests/cache-ledger.test.ts: unstamped session keeps{1, 0.1, 4}with pinned economics; stamped DeepSeek-class{1, 0.1, 1.5}shifts the verdicts in the rendered ledger header AND matches the kernel batch path field-for-field; partial{q:2}per-field fallback; corrupt persisted stamps fall back to defaults.tests/price-profile-stamp.test.ts: real-server e2e — provider-level config stamps the session, an unstamped lane clears it (latest-wins); plus the registry-fallback cases: listed model + no config -> stamped with the derived absolute profile, unlisted model -> no stamp, user config at any level -> wins wholesale over the registry row.tests/registry-price-profile.test.ts:priceProfileFromRowfull/partial/unusable rows;peekRegistryPriceProfileknown-host exact match, unknown-relay suffix scan (first-listing-wins, conflict warning), unlisted -> undefined, cold cache -> undefined (no fetch); bundled-snapshot sanity (>=1 anthropic/* key carries a usable cost row).Pre-flight on rebased head (master @ 4b5c045):
npm run typecheckcleannpm test: 2850 tests, 2838 pass, 0 fail, 12 skippednpm run buildsuccessOut-of-scope findings (filed separately, see issue thread)
While verifying incremental-vs-batch parity I found two distinct problems, both tracked in their own issues rather than bundled here:
turnsToNextFold(k) at 1 —consumedFoldSeqdouble-duty inrecordCacheSample— sopaidBackverdicts are systematically wrong for ALL providers (not just non-Anthropic).acp_cachetool has the same hardcoded-profile class (callsbuildCacheReportwithout a profile option; its config surface would need an equivalent key).