Skip to content

[PR] fix(web): refresh cached disk summaries when prices change - #7292

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-19_refresh-disk-summary-prices
Nov 20, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-19_refresh-disk-summary-prices

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7291

Problem

Dollar fields are documented as a view of current prices, but unchanged disk files reuse a fully priced summary indefinitely. A price edit updates live sessions while disk-only sessions retain old spend estimates, fold savings, payback and displayed rates. Removing or adding registry prices has the same stale-cache behavior.

Change

Include the resolved input/output/cache-read/cache-write rates in each disk summary's cache validity. A warm refresh resolves each distinct model/origin once. Equal prices reuse the existing summary; changed prices rebuild only the affected rows. Fresh shadow-index rows continue to avoid envelope decoding. Legacy files are decoded sequentially and their full records are immediately discarded, preserving the bounded summary index. Rebuilt rows receive a fresh synchronous price stamp, so a config reload during an asynchronous file read cannot mislabel their derived amounts.

The original persisted spend ledger still wins over estimates. The cache stores only a small price key; it does not retain session payloads or ledgers. Persisted formats, configuration and model-facing wire behavior are unchanged.

Validation

  • Two regressions fail on the exact base implementation: both legacy and shadow lists retain 1.80 after prices should produce 3.45.
  • 43 targeted billing/web/storage tests pass, with no skips. The new cases cover estimated and stamped spend, savings/payback, overview rates, removal and addition of prices, registry reloads, equal replacement tables retaining the cache and unaffected models avoiding re-decoding.
  • Fresh shadow rows use zero envelope decodes through repricing. Legacy mode re-decodes only the two affected records, then returns to its warm cache.
  • The file-read regression also edits and then rolls back prices during a scan; the returned rows follow the restored rates instead of retaining a mislabelled cached amount.
  • Final TypeScript checking, the full build and git diff --check pass. Independent source review included the asynchronous price-change boundary.

Tradeoff: changing resolved rates requires one new summary extraction for affected legacy files; it does not re-read unrelated models. Warm refreshes add one synchronous price lookup per distinct model/origin.

Validated on Linux / Node.js 24.22.3, based on 04ecbb42dd38543e9c407bd40eb773ae5ec8b60b. The repository-wide regression verdict remains the upstream CI result on the published head.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 #7291 (source issue) 是本 PR 的立项单。相近条目逐一比对: #7290 (select freshest disk session summaries) 同一子系统 (sessions-data.ts disk index) 但机制不同——它修的是多文件同 session 时的 summary 选择 (byId winner vs last-visited overwrite), 本 PR 修的是 price cache invalidation; #7276/#7279/#7280 是 billing lookup 性能 (cost table 重建), 不同失败域; #7238 是 savings 用的 rate 语义 (billed avg vs list price), 不同机制。无重复, 无并行 PR 修同一问题。

Independent review (read the diff at head 04a70177, re-derived the test arithmetic, ran the suites on both base and head — not taken from the issue):

Fix mechanism. DiskEntry gains an optional priceKey; refreshIndex() now computes, per refresh, the resolved 4-tuple [input, output, cacheRead, cacheWrite] per distinct model/origin (memoized within the refresh) and includes it in the per-file cache validity: mtimeMs && size && priceKey (src/web/sessions-data.ts:555). Equal prices → warm reuse unchanged; changed prices → rebuild only affected rows. The key is stamped synchronously at extraction (shadow adoption line 562, legacy decode line 581) with a fresh (unmemoized) lookup, so a config reload landing between file read and index write cannot mislabel a derived amount. livePriceForSummary was refactored into livePriceForModel (lines 682-694) — pure extraction, identical logic, no behavior drift. The key's model/upstreamOrigin come from the exact same sources summaryOf uses for price resolution, so key and amount can't diverge.

Verification performed.

  • npm ci + npm run build + npm run typecheck clean on head.
  • tests/billing-web.test.ts: 11/11 pass on head; on base 04ecbb42 the two new tests fail with exactly price edit reaches unchanged disk files — 1.8 !== 3.45 (both legacy and shadow modes) → genuine regression tests, not tautologies.
  • Related suites all green on head: billing-web, issue3199-overview-cold-scan, issue4990-web-single-store, web-sessions, web-storage-fallback, web-blocks-tree, billing-prices — 110/110, 0 skipped.
  • Re-derived every asserted value from the canonical formulas (costUsd estimate, savedUsdFromFolds net = gross − spent, payback split, overview sum 13.45 = 3.45 + 10 stamped + 0 unpriced): all match. The stamped-spend row staying exactly 10 confirms the persisted ledger still wins over estimates.

Regression review (existing behaviors touched):

  • Warm reuse on unchanged files: preserved — and the negative gate is tested (unchanged prices AND equal-replacement price tables retain the cache; decodedTotal unchanged).
  • Steady-state scan cost: +1 in-memory price lookup per distinct model/origin per refresh — disclosed in the PR body, cheap (resolveBillingPrice is an in-memory table scan).
  • Price change: affected legacy files re-decode once (disclosed); shadow rows re-price by re-adopting SQL rows with zero envelope decodes (tested: decodedTotal stays 0).
  • Bounded summary index: preserved — only a small key string is stored, no payloads/ledgers.
  • Undecodable files (summary: null): short-circuit preserved; live rows, full-storage mode (SQL per fetch), and the detail path (per-fetch re-read, no DiskEntry) are untouched.
  • Wire / persistence format / config / model-facing text: unchanged.
  • Residual (accepted, not a blocker): the per-refresh price memo is per-refresh, so a config reload landing mid-scan can leave at most one refresh cycle of stale prices for models already memoized; it self-heals on the next refresh, and the dangerous permanent-mislabel direction is covered by the fresh synchronous stamp.

Test validity (④): both gate directions asserted, exact-value assertions, legacy+shadow parametrization covers both disk paths, and the async-boundary test has teeth (it mocks the file read to edit prices mid-decode, asserts the edit was consumed, and asserts the rollback is reflected — catches the stale-memo-stamp defect class). Deterministic: temp dirs, env saved/restored in t.after, no state leak (subsequent tests all resetState()).

Code quality (⑤b) / diff (⑤): clean naming, why-comments where the logic is non-obvious, no dead code, style-consistent, no new dependencies; 2 files, every line on-purpose. No small mechanical flaws found → no drive-by fixes needed.

CI (live-verified 2026-11-19T10:48Z, sha 04a70177): 0 failed; static gates green (version-guard, gate, unused-exports, docs-coverage, test-import-graph); test shards still pending (14). mergeable_state: blocked = CI pending, not a merge conflict.

Note: src/web/sessions-data.ts is also touched by open PR #7290 (same base 04ecbb42) — whichever merges second needs a rebase; no conflict at this head.

Labeling limitation (reported, not dropped): I attempted to apply triage labels (bug, scope/ui, p2) to this thread on pickup, but the mirror shim does not implement the labels endpoint (POST /labels → endpoint not implemented in ework shim), so labeling is pending platform support.

八问 (Chinese, for reviewers):

  1. 是什么问题: web 面板的美元字段按文档应是「当前价格的实时视图」, 但 disk-only 会话的 summary 只按 (mtime, size) 缓存, 价格编辑后这些行的 spend/savings/payback/rates 一直显示旧值, 直到文件变化或进程重启。
  2. 什么原因导致的: disk summary 索引的缓存失效键缺少价格维度——美元字段在 extraction 时一次性按当时价格算死并随 summary 缓存, 暖缓存无限期复用。
  3. 影响范围与严重程度: 仅 web 展示面 (被逐出/disk-only 会话在列表与 overview 的美元字段); live 会话、已盖章 spend、wire、持久化均不受影响。p2: 能用但显示明显错误, 无数据丢失、无缓存泄露。
  4. 怎么修复的: 把解析出的 4 档价格键 (按 model/origin 每轮 memo) 纳入每文件缓存有效性; 价格不变→复用, 变→只重建受影响行 (shadow 走 SQL 零解码重采纳, legacy 重解码受影响文件); 价格键在 extraction 时同步盖章, 异步读取中途的 config reload 无法错标。
  5. 是否有回归问题: 逐项审过——暖复用保持 (含负向门测试)、稳态成本 +1 次内存价格查询 (PR 已披露)、有界索引保持、盖章 spend 优先保持 (已测)、shadow 零解码保持 (已测)、不可解码文件短路保持、full 模式/live 行/detail 路径不变、wire/持久化/配置不变。残留: 扫描中途 config reload 最多造成一轮刷新的陈旧价格, 下轮自愈; 永久错标方向已被 fresh stamp 覆盖。无回归。
  6. 是否破坏缓存: 不。前缀缓存/wire 未触碰; disk summary 缓存的失效面只扩大 (多失效, 不会少失效), 不可能比修复前更陈旧。
  7. 是否改了设计方向: 否。同一有界 summary 索引、同一 single-flight refresh, 仅缓存键增加一个维度。
  8. 是否引入了新的配置: 否。

Verdict: mergeable — pending CI test shards go green (static gates already green, 0 failures so far). I won't merge (human-only).

@ranxianglei
ranxianglei merged commit 1f18f66 into ranxianglei:master Nov 20, 2026
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disk-only web sessions keep stale dollar estimates after pricing changes

2 participants