feat(desktop): show cache hit% and session $ on statusbar context chip - #69408
feat(desktop): show cache hit% and session $ on statusbar context chip#69408theone139344 wants to merge 2 commits into
Conversation
Wire estimate_usage_cost into the usage snapshot so Desktop/TUI clients can render session spend on the status bar.
formatStatusCost prefixes ~ when cost_status is estimated. Optional cost fields are narrowed for the zero-usage union type.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for wiring the Desktop chip through the gateway and adding formatter coverage. This needs a product-contract pass before it can be safely salvaged.
Problems
fd2a35b169deliberately removed cache-hit and cost reporting from every UI surface because provider cache reporting can be incomplete. This patch restores that exact surface without a replacement reliability/visibility contract; the related #67834 discussion identifies that decision as unresolved.tui_gateway/server.py:3735(PR) substitutes cumulativesession_cache_read_tokensfor a per-call value, thenapps/desktop/src/lib/statusbar.tsx:94-97divides it by the current prompt size. Those scopes differ and can fabricate a hit percentage.agent/usage_pricing.py:1320returnsunknownfor unavailable pricing, whileagent/conversation_loop.py:3210overwrites the session status per call.formatStatusCostmarks onlyestimated, so a retained nonzero total can render as an unqualified dollar figure after an unknown-status call.- The stated
display.show_costmanual test has no corresponding gate in the changed Desktop status-item path.
Suggested changes
- First settle a shared, provenance-aware cost/cache display contract.
- If approved, omit unavailable per-call cache metrics, gate the display explicitly, and add gateway-to-Desktop tests for unknown, estimated, included, and missing data.
Automated hermes-sweeper review.
| "cost_status": getattr(agent, "session_cost_status", None) or "unknown", | ||
| } | ||
| if not usage["cache_read"]: | ||
| usage["cache_read"] = int(getattr(agent, "session_cache_read_tokens", 0) or 0) |
There was a problem hiding this comment.
This fallback mixes cumulative session cache reads with the current request's last_prompt denominator in formatCacheFresh, so a restored/missing per-call counter can produce a fabricated or clamped hit rate. Omit the percentage unless both values are from the same request.
| body = `$${usd.toFixed(2)}` | ||
| } else { | ||
| body = `$${Number(usd.toFixed(3))}` | ||
| } |
There was a problem hiding this comment.
Only estimated is marked approximate. estimate_usage_cost() can return unknown, and the session loop overwrites the status each call while retaining prior accumulated spend, so an unknown-provenance nonzero total would render as an unqualified dollar amount.
| // Prefer bar+%; cache/cost ride on detail when backend provides them. | ||
| detail: | ||
| [contextBar || undefined, cacheLabel || undefined, costLabel || undefined].filter(Boolean).join(' · ') || | ||
| undefined, |
There was a problem hiding this comment.
The PR body says this is enabled with display.show_cost, but this path surfaces every nonempty costLabel and the patch does not wire a configuration predicate. Please either implement the stated gate through the Desktop backend contract or remove that configuration claim after the product decision.
Summary
cost_usd+cost_statusfromestimate_usage_cost.~whencost_status=estimated).statusbar-cache-cost.test.ts.Depends on
Works best with pricing PR for xAI/Kimi/Z.AI so non-OpenAI sessions are non-zero. UI still handles missing cost gracefully (empty string).
Test plan
cd apps/desktop && npm test -- --run src/lib/statusbar-cache-cost.test.tsdisplay.show_cost: true, run a turn, confirm context chip shows$/~$