Skip to content

feat(ui): display cache hit rate with one decimal place#967

Merged
Astro-Han merged 2 commits into
devfrom
pawwork/cache-hit-rate-decimal
May 28, 2026
Merged

feat(ui): display cache hit rate with one decimal place#967
Astro-Han merged 2 commits into
devfrom
pawwork/cache-hit-rate-decimal

Conversation

@Astro-Han

@Astro-Han Astro-Han commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

Round cache hit rate in session context panel to one decimal place instead of integer. Add optional fractionDigits parameter to percent() formatter so other percentage displays (e.g. context usage) remain unchanged. No related issue — this is a small self-contained enhancement.

Why

The current integer display loses precision on small hit rates (e.g. 7.1% shows as 7%). One decimal place gives a meaningful improvement without visual noise.

Related Issue

None.

Human Review Status

Approved by @Astro-Han

Review Focus

  • The percent() formatter now takes an optional second argument; verify only cache hit rate passes it (line 197 in tab.tsx), not the usage stat (line 238).
  • The formatter uses toLocaleString(locale, { minimumFractionDigits, maximumFractionDigits }) instead of toFixed to preserve locale-aware decimal separators.

Risk Notes

None. The change is backward-compatible: percent(value) without the second argument behaves identically to before.

How To Verify

bun test src/components/session/session-context-metrics.test.ts
  9 pass, 0 fail

bun x tsc --noEmit
  clean, no errors

PLAYWRIGHT_SNAP=1 bun run test:e2e:local -- e2e/snap/session-context-cache.snap.ts
  1 passed

Screenshots or Recordings

E2E snap grid generated at docs/design/preview/screenshots/session-context-cache.png — visually confirmed by @Astro-Han: cache hit rate displays 90.0% with one decimal place.

Checklist

  • Type label — this PR carries exactly one of bug, enhancement, task, documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.
  • Routing labels — this PR carries at least one of app, ui, platform, harness, ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.
  • Priority label — this PR carries exactly one of P0, P1, P2, P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.
  • Human Review Status above is set to Pending, Approved by @<reviewer>, or Not required: <reason> (default is Pending; "not required" is restricted to bot-authored low-risk PRs).
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed, with screenshots or recordings. Leave unticked only if no visible UI or copy changed.
  • (conditional) I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes. Leave unticked only if no platform/packaging surface was touched.
  • (conditional) I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant. Leave unticked only if none of those surfaces was touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

Summary by CodeRabbit

Release Notes

  • Improvements
    • Cache hit rate metric now displays with one decimal place for improved precision (e.g., "90.0%" instead of "90%").
    • Enhanced cache hit rate calculation algorithm for more granular percentage accuracy in reporting.

Review Change Stack

Round cache hit rate to one decimal instead of integer, and add optional
fractionDigits parameter to the percent formatter so other percentage
displays are unaffected.
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1bff8f05-07da-41ac-80c5-9cdafa278338

📥 Commits

Reviewing files that changed from the base of the PR and between a72c2cb and 49690dd.

📒 Files selected for processing (5)
  • packages/app/e2e/snap/session-context-cache.snap.ts
  • packages/app/src/components/session/session-context-format.ts
  • packages/app/src/components/session/session-context-metrics.test.ts
  • packages/app/src/components/session/session-context-metrics.ts
  • packages/app/src/components/session/session-context-tab.tsx

📝 Walkthrough

Walkthrough

Cache hit rate display across the session context is refined to show decimal precision. The metric calculation rounds to finer granularity, the percent formatter gains optional fraction-digit control, and the tab display calls it with one decimal place; e2e and unit tests update their assertions.

Changes

Cache Hit Rate Decimal Precision

Layer / File(s) Summary
Cache hit rate calculation rounding adjustment
packages/app/src/components/session/session-context-metrics.ts
Cache hit rate rounding changes from multiplying by 100 to multiplying by 1000 then dividing by 10, enabling finer decimal precision.
Percent formatter with configurable precision
packages/app/src/components/session/session-context-format.ts
The percent formatter in createSessionContextFormatter accepts an optional fractionDigits parameter to control minimum and maximum fraction digits when formatting percentages.
Cache hit rate display and validation
packages/app/src/components/session/session-context-tab.tsx, packages/app/src/components/session/session-context-metrics.test.ts, packages/app/e2e/snap/session-context-cache.snap.ts
Session context tab calls percent(value, 1) to display cache hit rate with one decimal place; unit and e2e test assertions update to expect the new decimal values (7.1 and 90.0% respectively).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Astro-Han/pawwork#910: This PR's cache-hit-rate rounding and percent formatting refinements directly extend the session context cache hit rate display feature introduced in that PR.

Poem

🐰 A percentage blooms with decimal flair,
From coarse rounding to one digit's care.
Ninety point oh—not ninety flat—
The formatter dances; tests applaud at that! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: displaying cache hit rate with one decimal place precision.
Description check ✅ Passed The PR description follows the template and provides all required sections: Summary, Why, Related Issue, Human Review Status, Review Focus, Risk Notes, How To Verify, Screenshots, and a complete Checklist.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pawwork/cache-hit-rate-decimal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added app Application behavior and product flows ui Design system and user interface P2 Medium priority labels May 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested priority: P2 (includes user-path files (packages/app/src/components/session/session-context-format.ts, packages/app/src/components/session/session-context-metrics.test.ts, packages/app/src/components/session/session-context-metrics.ts, packages/app/src/components/session/session-context-tab.tsx)).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@Astro-Han Astro-Han added the enhancement New feature or request label May 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the cache hit rate calculation and formatting to display with one decimal place (e.g., "90.0%" instead of "90%"). Feedback was provided regarding the cache hit rate calculation, pointing out that returning null when there are no cache reads but there are cache writes incorrectly hides the cache hit rate (showing "—" instead of "0.0%"). A suggestion was made to only return null when both reads and writes are zero or less.

Comment thread packages/app/src/components/session/session-context-metrics.ts
@github-actions

Copy link
Copy Markdown

Perf delta summary

Comparator: pass

Profile / Scenario interaction median interaction worst long task max tbt frame gap p95 frame gap max jank count cls status
default / homepage-cold 24 -> 24 (0) 56 -> 32 (-24) 74 -> 70 (-4) 24 -> 20 (-4) 33.4 -> 16.8 (-16.6) 116.7 -> 116.7 (0) 3 -> 4 (+1) 0 -> 0 (0) pass
default / long-session-input-lag 40 -> 48 (+8) 48 -> 48 (0) 0 -> 0 (0) 0 -> 0 (0) 16.8 -> 16.7 (-0.1) 16.8 -> 16.8 (0) 0 -> 0 (0) 0 -> 0 (0) pass
default / session-streaming-long 40 -> 32 (-8) 72 -> 56 (-16) 0 -> 0 (0) 0 -> 0 (0) 16.8 -> 16.8 (0) 16.8 -> 16.8 (0) 0 -> 0 (0) 0 -> 0 (0) pass
default / tool-call-expand 24 -> 24 (0) 24 -> 40 (+16) 0 -> 0 (0) 0 -> 0 (0) 16.7 -> 16.8 (+0.1) 16.7 -> 16.8 (+0.1) 0 -> 0 (0) 0 -> 0 (0) pass
default / terminal-side-panel-open 40 -> 48 (+8) 48 -> 48 (0) 0 -> 0 (0) 0 -> 0 (0) 33.3 -> 33.3 (0) 33.3 -> 33.3 (0) 0 -> 0 (0) 0 -> 0 (0) pass
default / session-scroll-reading 16 -> 16 (0) 32 -> 16 (-16) 0 -> 0 (0) 0 -> 0 (0) 33.4 -> 16.7 (-16.7) 33.4 -> 16.7 (-16.7) 0 -> 0 (0) 0 -> 0 (0) pass

@Astro-Han Astro-Han merged commit d0fe7f2 into dev May 28, 2026
30 of 32 checks passed
@Astro-Han Astro-Han deleted the pawwork/cache-hit-rate-decimal branch May 28, 2026 07:09
Astro-Han added a commit that referenced this pull request May 28, 2026
Bump PawWork desktop release version to 2026.5.29.

Changes since v2026.5.28:
- feat(settings): move Connections to Integrations + global toast monitor (#975)
- feat(ui): display cache hit rate with one decimal place (#967)
- fix: stabilize session opening state (#969)
- fix(session): repair stale paginated question blockers (#962)
- fix(ui): refit read-file icon into 0-20 viewBox (#964)
- fix: allow running tools to expand
- fix: add run lifecycle diagnostics
- fix: harden Electron repair fallback
- refactor: remove legacy theme choices
- ci: stabilize e2e Playwright install and PR triage paths

Verification: diff scope matches prior release bump (#958) — only the version string in packages/desktop-electron/package.json and the workspace entry in bun.lock. All CI checks green (e2e-artifacts required a rerun due to Playwright browser install flake unrelated to this change).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app Application behavior and product flows enhancement New feature or request P2 Medium priority ui Design system and user interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant