Skip to content

feat(desktop): show cache hit% and session $ on statusbar context chip - #69408

Open
theone139344 wants to merge 2 commits into
NousResearch:mainfrom
theone139344:feat/desktop-statusbar-cache-cost
Open

feat(desktop): show cache hit% and session $ on statusbar context chip#69408
theone139344 wants to merge 2 commits into
NousResearch:mainfrom
theone139344:feat/desktop-statusbar-cache-cost

Conversation

@theone139344

Copy link
Copy Markdown
Contributor

Summary

  • Gateway usage payload exposes cost_usd + cost_status from estimate_usage_cost.
  • Desktop context chip detail shows cache hit% and session $ (prefix ~ when cost_status=estimated).
  • Vitest coverage in 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.ts
  • Manual: enable display.show_cost: true, run a turn, confirm context chip shows $ / ~$

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.
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/desktop Electron desktop app (apps/desktop/*) comp/tui Terminal UI (ui-tui/ + tui_gateway/) area/billing Account usage, credit usage, billing (cross-cutting) area/usage-cost Token accounting, usage reporting, billing, cost tracking needs-decision Awaiting maintainer decision before any implementation labels Jul 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #41721 and #67834: all target Desktop status-bar usage visibility, but this PR adds upstream per-call cache and session-cost wiring. The differing display/data semantics need a maintainer consolidation decision rather than a duplicate closure.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • fd2a35b169 deliberately 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 cumulative session_cache_read_tokens for a per-call value, then apps/desktop/src/lib/statusbar.tsx:94-97 divides it by the current prompt size. Those scopes differ and can fabricate a hit percentage.
  • agent/usage_pricing.py:1320 returns unknown for unavailable pricing, while agent/conversation_loop.py:3210 overwrites the session status per call. formatStatusCost marks only estimated, so a retained nonzero total can render as an unqualified dollar figure after an unknown-status call.
  • The stated display.show_cost manual 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.

Comment thread tui_gateway/server.py
"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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))}`
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing Account usage, credit usage, billing (cross-cutting) area/sessions Session lifecycle, resume, persistence, history area/usage-cost Token accounting, usage reporting, billing, cost tracking comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/desktop Electron desktop app (apps/desktop/*) comp/tui Terminal UI (ui-tui/ + tui_gateway/) needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants