-
-
Notifications
You must be signed in to change notification settings - Fork 317
Fix for live usage tokens not getting updated #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe update adds a call to clear the monitor cache after each fetch of the active block in the live monitoring loop. Additionally, the codebase undergoes extensive formatting changes for improved readability, particularly in error handling and rendering functions, without altering any logic or output content. Changes
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📥 CommitsReviewing files that changed from the base of the PR and between 9b76448f129add9405d2be19292fd44064dcde86 and a0f9c48. 📒 Files selected for processing (1)
🧰 Additional context used🪛 ESLintsrc/commands/_blocks.live.ts[error] 196-196: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 196-196: Unsafe call of a(n) (ts/no-unsafe-call) [error] 196-196: Unsafe member access .cyan on an (ts/no-unsafe-member-access) [error] 197-197: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 197-197: Unsafe call of a(n) (ts/no-unsafe-call) [error] 197-197: Unsafe member access .gray on an (ts/no-unsafe-member-access) [error] 219-219: Unsafe call of a(n) (ts/no-unsafe-call) [error] 219-219: Unsafe member access .bold on an (ts/no-unsafe-member-access) [error] 225-225: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 225-225: Unsafe call of a(n) (ts/no-unsafe-call) [error] 225-225: Unsafe member access .bold on an (ts/no-unsafe-member-access) [error] 226-226: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 226-226: Unsafe call of a(n) (ts/no-unsafe-call) [error] 229-229: Unsafe call of a(n) (ts/no-unsafe-call) [error] 244-244: Unsafe call of a(n) (ts/no-unsafe-call) [error] 270-270: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 270-270: Unsafe call of a(n) (ts/no-unsafe-call) [error] 271-271: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 271-271: Unsafe call of a(n) (ts/no-unsafe-call) [error] 271-271: Unsafe member access .gray on an (ts/no-unsafe-member-access) [error] 275-275: Unsafe call of a(n) (ts/no-unsafe-call) [error] 275-275: Unsafe member access .green on an (ts/no-unsafe-member-access) [error] 275-275: Unsafe call of a(n) (ts/no-unsafe-call) [error] 275-275: Unsafe member access .gray on an (ts/no-unsafe-member-access) [error] 279-286: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 282-282: Unsafe call of a(n) (ts/no-unsafe-call) [error] 282-282: Unsafe member access .red on an (ts/no-unsafe-member-access) [error] 284-284: Unsafe call of a(n) (ts/no-unsafe-call) [error] 284-284: Unsafe member access .yellow on an (ts/no-unsafe-member-access) [error] 285-285: Unsafe call of a(n) (ts/no-unsafe-call) [error] 285-285: Unsafe member access .green on an (ts/no-unsafe-member-access) [error] 289-289: Unsafe call of a(n) (ts/no-unsafe-call) [error] 289-289: Unsafe member access .bold on an (ts/no-unsafe-member-access) [error] 290-290: Unsafe call of a(n) (ts/no-unsafe-call) [error] 290-290: Unsafe member access .bold on an (ts/no-unsafe-member-access) [error] 293-293: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 293-293: Unsafe call of a(n) (ts/no-unsafe-call) [error] 293-293: Unsafe member access .bold on an (ts/no-unsafe-member-access) [error] 294-294: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 294-294: Unsafe call of a(n) (ts/no-unsafe-call) [error] 298-298: Unsafe call of a(n) (ts/no-unsafe-call) [error] 313-313: Unsafe call of a(n) (ts/no-unsafe-call) [error] 319-319: Unsafe call of a(n) (ts/no-unsafe-call) [error] 332-332: Unsafe call of a(n) (ts/no-unsafe-call) [error] 362-362: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 362-362: Unsafe call of a(n) (ts/no-unsafe-call) [error] 363-363: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 363-363: Unsafe call of a(n) (ts/no-unsafe-call) [error] 363-363: Unsafe member access .gray on an (ts/no-unsafe-member-access) [error] 367-367: Unsafe call of a(n) (ts/no-unsafe-call) [error] 367-367: Unsafe member access .green on an (ts/no-unsafe-member-access) [error] 367-367: Unsafe call of a(n) (ts/no-unsafe-call) [error] 367-367: Unsafe member access .gray on an (ts/no-unsafe-member-access) [error] 369-376: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 372-372: Unsafe call of a(n) (ts/no-unsafe-call) [error] 372-372: Unsafe member access .red on an (ts/no-unsafe-member-access) [error] 374-374: Unsafe call of a(n) (ts/no-unsafe-call) [error] 374-374: Unsafe member access .yellow on an (ts/no-unsafe-member-access) [error] 375-375: Unsafe call of a(n) (ts/no-unsafe-call) [error] 375-375: Unsafe member access .green on an (ts/no-unsafe-member-access) [error] 376-376: Unsafe call of a(n) (ts/no-unsafe-call) [error] 376-376: Unsafe member access .green on an (ts/no-unsafe-member-access) [error] 379-379: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 379-379: Unsafe call of a(n) (ts/no-unsafe-call) [error] 379-379: Unsafe member access .bold on an (ts/no-unsafe-member-access) [error] 380-380: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 380-380: Unsafe call of a(n) (ts/no-unsafe-call) [error] 384-384: Unsafe call of a(n) (ts/no-unsafe-call) [error] 399-399: Unsafe call of a(n) (ts/no-unsafe-call) [error] 405-405: Unsafe call of a(n) (ts/no-unsafe-call) [error] 420-420: Unsafe call of a(n) (ts/no-unsafe-call) [error] 432-432: Unsafe call of a(n) (ts/no-unsafe-call) [error] 469-470: Unsafe assignment of an error typed value. (ts/no-unsafe-assignment) [error] 470-470: Unsafe call of a(n) (ts/no-unsafe-call) [error] 470-470: Unsafe member access .red on an (ts/no-unsafe-member-access) [error] 470-470: Unsafe call of a(n) (ts/no-unsafe-call) [error] 470-470: Unsafe member access .yellow on an (ts/no-unsafe-member-access) [error] 470-470: Unsafe call of a(n) (ts/no-unsafe-call) [error] 470-470: Unsafe member access .green on an (ts/no-unsafe-member-access) 🔇 Additional comments (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @dalmia007, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request primarily addresses an issue where live usage tokens were not updating correctly in the monitoring display by introducing a cache-clearing step. Additionally, it includes significant code formatting improvements to enhance the readability and maintainability of the display rendering logic.
Highlights
- Core Functionality Fix: Implemented a cache-clearing mechanism in the live monitoring loop (
startLiveMonitoring) to ensure real-time updates of usage tokens, addressing the primary issue of stale data. - Code Readability & Formatting: Applied extensive formatting changes across display rendering functions (
renderLiveDisplayandrenderCompactLiveDisplay), including line breaks and indentation, to enhance code readability and maintainability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
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 aims to fix an issue where live usage tokens were not updating. The main change involves clearing the LiveMonitor's cache on each refresh loop to force a full data reload.
While this approach likely resolves the stale data problem, it introduces a significant performance issue by disabling the incremental loading feature of LiveMonitor. My review focuses on this key change, recommending an investigation into the root cause of the update failure rather than using a brute-force cache clearing. The other changes in this PR are stylistic and appear to be from a code formatter, which I have not commented on.
src/commands/_blocks.live.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change appears to fix the issue of tokens not updating, but it does so by completely disabling the incremental loading mechanism of LiveMonitor.
The LiveMonitor class is designed for efficiency by only reading new or modified files and processing new entries. Calling monitor.clearCache() on every loop iteration forces a full reload of all usage data files, which can be very inefficient, especially as the data grows. This negates the entire purpose of the LiveMonitor's caching and incremental update logic, as described in its documentation.
I recommend investigating the root cause of the stale data issue instead. It might be related to:
- How file modifications are detected (e.g., issues with
getEarliestTimestamp). - Caching logic within
LiveMonitorthat incorrectly filters out new data.
A targeted fix will be much more performant and maintainable. Please consider removing this line and debugging LiveMonitor.getActiveBlock() to find why it's not picking up new usage entries.
|
@dalmia007 This PR looks good. can you start commit message with |
|
@dalmia007 I mean your commit message |
commit: |
|
@ryoppippi its done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures live token usage is updated by clearing the cache each refresh and improves readability of the live monitoring display formatting.
- Adds
monitor.clearCache()inside the monitoring loop to force reloads - Refactors multi-line progress bar and padding logic for consistent formatting
Comments suppressed due to low confidence (2)
src/commands/_blocks.live.ts:98
- [nitpick] Consider adding a brief comment explaining why
clearCache()is needed on each loop iteration to clarify its impact on live token updates.
monitor.clearCache(); // Force reload for next refresh
src/commands/_blocks.live.ts:98
- Add or update unit tests to verify that clearing the cache correctly triggers token usage refresh in the live monitoring loop.
monitor.clearCache(); // Force reload for next refresh
src/commands/_blocks.live.ts
Outdated
| while (!abortController.signal.aborted) { | ||
| // Get active block with lightweight refresh | ||
| const activeBlock = await monitor.getActiveBlock(); | ||
| monitor.clearCache(); // Force reload for next refresh |
Copilot
AI
Jun 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearing the cache on every refresh may affect performance; consider invoking clearCache() only when token data actually changes.
| monitor.clearCache(); // Force reload for next refresh | |
| // Clear cache only if token data has changed | |
| if (activeBlock?.tokenData !== previousTokenData) { | |
| monitor.clearCache(); | |
| previousTokenData = activeBlock?.tokenData; | |
| } |
src/commands/_blocks.live.ts
Outdated
| const sessionBarStr = `${sessionLabel}${''.padEnd(Math.max(0, labelWidth - sessionLabelWidth))} ${sessionProgressBar} ${sessionPercent.toFixed(1).padStart(6)}%`; | ||
| const sessionBarPadded = sessionBarStr + ' '.repeat(Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr))); | ||
| const sessionBarPadded | ||
| = sessionBarStr + ' '.repeat(Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr))); |
Copilot
AI
Jun 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] There’s duplicated padding logic across several sections; consider extracting a helper function (e.g., padToWidth) to reduce repetition.
| = sessionBarStr + ' '.repeat(Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr))); | |
| = sessionBarStr + padToWidth('', Math.max(0, boxWidth - 3 - stringWidth(sessionBarStr))); |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| 🔵 In progress View logs |
ccusage-guide | a0f9c48 | Jun 22 2025, 07:06 PM |
|
Damm it changes styles a lot. So the change is all about |
|
Oh you mistakenly close it? I'm just reviewing your changes |
|
Please explain what is the changes and why it matters. |
|
@ryoppippi I deleted the branch in my repo and I think it closed the PR. I will open a new one. The only change I have made is adding the monitor.clearCache() after the activeBlock is defined. At the moment the activeBlock is not getting updated between refreshes. My solution my might not be the best honestly. Its more of a quick fix. |
|
ok I got it. |
|
I have created a new PR |
Summary by CodeRabbit