Skip to content

fix: revalidate usage on get#5116

Merged
kaposke merged 3 commits intomasterfrom
gui/2025-12-08/fix-revalidate-usage-on-get
Feb 2, 2026
Merged

fix: revalidate usage on get#5116
kaposke merged 3 commits intomasterfrom
gui/2025-12-08/fix-revalidate-usage-on-get

Conversation

@kaposke
Copy link
Contributor

@kaposke kaposke commented Dec 8, 2025

Ensure UsageTracker revalidates cache entries on read paths

Updates packages/account-usage/lib/usage.ts so that UsageTracker.get and UsageTracker.getAll trigger revalidate when cached values are missing or their revalidateAfter timestamp is in the past, aligning read-path behavior with the existing logic in incr. Extends packages/account-usage/lib/usage.integration.test.ts with vi spies and fake timers to cover null, stale, invalid, and fresh cache scenarios for both get and getAll, ensuring revalidation is invoked (or not) as expected.

Key Changes

• Added conditional revalidation in UsageTracker.get when entry.value is null or stale (entry.value.revalidateAfter < now)
• Mirrored the same revalidation trigger inside UsageTracker.getAll for each metric retrieved
• Expanded integration tests to spy on revalidate, simulate stale windows via fake timers, and assert invocation counts/arguments for get, getAll, and incr flows

Affected Areas

packages/account-usage/lib/usage.ts
packages/account-usage/lib/usage.integration.test.ts


This summary was automatically generated by @propel-code-bot

@kaposke kaposke requested a review from TBonnin December 8, 2025 19:27
@my-senior-dev-pr-review
Copy link

my-senior-dev-pr-review bot commented Dec 8, 2025

🤖 My Senior Dev — Analysis Complete

👤 For @kaposke

📁 Expert in packages/ (142 edits) • ⚡ 19th PR this month

View your contributor analytics →


📊 2 files reviewed • 4 need attention

⚠️ Needs Attention:

  • packages/account-usage/lib/usage.ts — The changes impact the handling of user account data, critical for maintaining data integrity and security.

🚀 Open Interactive Review →

The full interface unlocks features not available in GitHub:

  • 💬 AI Chat — Ask questions on any file, get context-aware answers
  • 🔍 Smart Hovers — See symbol definitions and usage without leaving the diff
  • 📚 Code Archeology — Understand how files evolved over time (/archeology)
  • 🎯 Learning Insights — See how this PR compares to similar changes

💬 Chat here: @my-senior-dev explain this change — or try @chaos-monkey @security-auditor @optimizer @skeptic @junior-dev

📖 View all 12 personas & slash commands

You can interact with me by mentioning @my-senior-dev in any comment:

In PR comments or on any line of code:

  • Ask questions about the code or PR
  • Request explanations of specific changes
  • Get suggestions for improvements

Slash commands:

  • /help — Show all available commands
  • /archeology — See the history and evolution of changed files
  • /profile — Performance analysis and suggestions
  • /expertise — Find who knows this code best
  • /personas — List all available AI personas

AI Personas (mention to get their perspective):

Persona Focus
@chaos-monkey 🐵 Edge cases & failure scenarios
@skeptic 🤨 Challenge assumptions
@optimizer Performance & efficiency
@security-auditor 🔒 Security vulnerabilities
@accessibility-advocate Inclusive design
@junior-dev 🌱 Simple explanations
@tech-debt-collector 💳 Code quality & shortcuts
@ux-champion 🎨 User experience
@devops-engineer 🚀 Deployment & scaling
@documentation-nazi 📚 Documentation gaps
@legacy-whisperer 🏛️ Working with existing code
@test-driven-purist Testing & TDD

For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews.

Copy link
Collaborator

@TBonnin TBonnin left a comment

Choose a reason for hiding this comment

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

can we add/modify tests to check the new behavior

@kaposke kaposke force-pushed the gui/2025-12-08/fix-revalidate-usage-on-get branch from 5d3a9b7 to dc661e9 Compare January 30, 2026 19:16
if (entry.isErr()) {
return Err(entry.error);
}
if (entry.value === null || entry.value.revalidateAfter < now.getTime()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how can value be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the first time trying to get it from the cache, when it doesn't exist yet. Down there it defaults to 0, but ideally we take the hint to revalidate.

@kaposke kaposke added this pull request to the merge queue Feb 2, 2026
Merged via the queue into master with commit 7abeef2 Feb 2, 2026
24 checks passed
@kaposke kaposke deleted the gui/2025-12-08/fix-revalidate-usage-on-get branch February 2, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants