Skip to content

feat(tui): [v2] show cache hit rate in sidebar - #42503

Open
heimoshuiyu wants to merge 1 commit into
anomalyco:v2from
heimoshuiyu:cache-hit-rate
Open

feat(tui): [v2] show cache hit rate in sidebar#42503
heimoshuiyu wants to merge 1 commit into
anomalyco:v2from
heimoshuiyu:cache-hit-rate

Conversation

@heimoshuiyu

@heimoshuiyu heimoshuiyu commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a cache hit rate to the sidebar so people can see how good OpenCode V2's caching really is.

How did you verify your code works?

It simply works.

Screenshots / recordings

image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found potential duplicates related to cache hit rate and TUI sidebar displays:

  1. PR feat(opencode): display cached token count inline in TUI #23111 - feat(opencode): display cached token count inline in TUI

    • Shows cached token metrics in the TUI, similar feature to displaying cache information
  2. PR feat(tui): display input/cache tokens with cache percentage in context panel #33933 - feat(tui): display input/cache tokens with cache percentage in context panel

    • Directly displays cache percentage in the TUI context panel, very similar functionality to your cache hit rate feature
  3. PR feat(tui): show subagent cost rollup in sidebar and task history #25712 - feat(tui): show subagent cost rollup in sidebar and task history

    • Adds metrics display to the TUI sidebar, similar pattern of showing additional information in the sidebar

These PRs may already address or partially address the cache hit rate display feature. PR #33933 in particular seems to have overlapping functionality for showing cache metrics in the UI.

@heimoshuiyu heimoshuiyu changed the title feat(tui): show cache hit rate in sidebar feat(tui): [v2] show cache hit rate in sidebar Aug 14, 2026
@heimoshuiyu
heimoshuiyu marked this pull request as ready for review August 14, 2026 04:08
@Enough1122

Copy link
Copy Markdown

Thanks for the PR! The cacheRate memo is a nice addition and the zero-division guard (totalInput === 0 → undefined) is handled correctly.

A couple of suggestions:

  1. Defensive access to tokens: cacheRate() assumes current.tokens (and current.tokens.cache) always exist once a session is present. If older/persisted sessions can lack this field, this would throw inside the memo — consider current.tokens?.cache.read ?? 0 style access for safety.
  2. Label vs. title: the PR says "cache hit rate" but the UI renders "N% cache ratio". Worth aligning on one term so docs/UI stay consistent.
  3. Test coverage: the fixture was extended with tokens, but there's no assertion that the new "% cache ratio" text actually renders — a small test case (session with non-zero cache.read → line visible; all-zero input → hidden) would lock in the behavior.

Otherwise looks good — the <Show> gating keeps the sidebar clean when there's nothing to display.

@heimoshuiyu

Copy link
Copy Markdown
Contributor Author

@Enough1122

  1. Session.Info.token is not optional
  2. "cache ratio" is 1 word shorter than "cache hit ratio"
  3. no comment

@Enough1122

Copy link
Copy Markdown

AI code review - automated review for reference; please use your judgment.

  • packages/tui/src/feature-plugins/sidebar/context.tsx:19-24 - current.tokens is dereferenced without a guard (only current is checked); if older sessions or providers report no token block this throws during render. Add current.tokens?. or confirm the schema makes it required.
  • packages/tui/src/feature-plugins/sidebar/context.tsx:21 - denominator excludes cache.write; that is a defensible "read hit rate" definition, but the label just says "cache ratio" - consider naming it more precisely or documenting the formula since users may expect write inclusion.
  • Test updated for the new shape but does not assert the rendered percentage; add an assertion for e.g. input=25/read=75 -> 75% to lock the formula.

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.

2 participants