fix(ui): make every cost/cache readout match its labeled scope#6096
Conversation
Four labeled-scope mismatches in cost/cache displays, bundled as the tail of the cost-display cleanup line (esengine#6075 fixed the big one): - Desktop status bar 平均命中 silently switched scope: the live value used the wire session counters (executor agent only) while the fallback used tab telemetry (all request sources). Prefer the all-sources telemetry — matching the 会话费用 tooltip's "includes main model, subagents and auxiliary calls" — with the executor-only live counters only bridging a fresh session's first turn. - CLI status line painted "turn hit 0.00%" for providers that report no prompt-cache fields, by falling back to PromptTokens as the denominator. The tag now hides when cache fields are absent; a genuine full miss (fields present, hit zero) still renders. - serve web UI "总费用" accumulated since page load across session rotations and fell back to a single request's cost. The counters now reset on /new and /resume, the single-request fallback is gone, and the card is relabeled 会话费用/Session Cost. - Desktop ContextPanel's session-cost fallback chain could render one request's usage.cost under the 会话费用 label; single-request branches removed (usage now contributes currency only).
…es scope Review catch on this PR: the panel's session cache average still preferred usage.sessionCacheHitTokens — the wire session counters the Go agent scopes to the executor only — over the all-sources telemetry, while the same panel's session cost and per-source rows (and StatusBar after this PR) already report all sources. Because the reducer keeps s.usage across context refreshes, the executor-only number would stick indefinitely. Extract contextSessionCache: panel info first, ContextInfo second, wire counters only as the pre-refresh bridge for a fresh session — and pick hit/miss as a pair from a single source so the computed rate can never mix scopes (the old per-field ?? chains could).
|
Valid catch — fixed in 72f0210. The reviewer is right on both counts: (1) ContextPanel's session cache average still preferred Fix mirrors the StatusBar preference and goes one step further: extracted Four new test cases pin the preference order and the no-data case; context-panel suite now 44 pass, |
Summary
费用显示清理线的收尾(#6075 修掉了主污染源;这个 PR 打包剩余的四个口径错位),全部是"标签声称的口径 ≠ 实际显示的数"的问题:
/new//resume后继续滚,且空值时退到单请求的lastUsage.cost。现在会话轮换时重置计数器、删除单请求兜底、卡片改标为「会话费用/Session Cost」。usage.cost渲染在「会话费用」标签下;移除单请求分支(usage 仅贡献货币符号)。Verification
TestCacheTagHiddenWhenProviderReportsNoCacheFields/TestCacheTagShowsRealZeroHit/TestCacheTagRendersHitRateAndSessionAverage(CLI);context-panel 测试新增"单请求费用不得渲染在会话标签下"与"本地累计仍渲染"两个用例。go test ./internal/cli ./internal/servegreen;frontendtsc --noEmitclean;context-panel-breakdown(40 pass)与statusbar-workspace(13 pass)测试通过;serve 内联 JS 语法解析验证通过。Cache impact
Cache-impact: none - display-layer only; no provider request, prompt, or tool schema changes.
Cache-guard: not applicable (no cache-sensitive files); UI test suites above cover the change.
System-prompt-review: N/A
Refs #5850 (关闭这条线的最后一批), #2945.