Skip to content

feat(provider): add usage limits tracking and display#34

Closed
tyulyukov wants to merge 3 commits intomainfrom
marcode/feature/provider-usage-limits
Closed

feat(provider): add usage limits tracking and display#34
tyulyukov wants to merge 3 commits intomainfrom
marcode/feature/provider-usage-limits

Conversation

@tyulyukov
Copy link
Copy Markdown
Owner

Summary

  • Persistence layer: Added SQLite table provider_usage_limits (migration 022) and UsageLimitsRepository service for upsert/get/stream operations with stale-write protection
  • Event interception: ProviderService.processRuntimeEvent now persists usage limits when account.rate-limits.updated events arrive
  • Provider-agnostic normalizers: Added normalizeClaudeUsageLimits() and normalizeCodexUsageLimits() in normalizeUsageLimits.ts to standardize provider-specific rate limit payloads into ServerProviderUsageWindow (session/weekly union)
  • Real-time sync: ProviderRegistry.syncProviders now overlays persisted limits onto provider snapshots; changes trigger WebSocket push via UsageLimitsRepository.streamChanges PubSub
  • UI component: New ProviderUsageLimitsSection renders color-coded progress bars (green >50%, amber 20-50%, red <20%) with relative reset times (e.g. "in 2h 30m") and absolute dates
  • Integration: Usage limits display in Settings > Providers under each provider card, update in real-time as events arrive
  • Contracts: New ServerProviderUsageLimits schema with windows array and updatedAt timestamp; added optional usageLimits field to ServerProvider
  • Documentation: Added "Provider Usage Limits" section to AGENTS.md with full architecture overview

Testing

  • Integration tests updated to include UsageLimitsRepositoryLive layer in all fixtures (ProviderService, ProviderRegistry, OrchestrationEngine)
  • Stale-write protection verified: upsert uses WHERE excluded.updated_at > ... to ignore out-of-order updates
  • Normalizers handle both camelCase and snake_case property names from different providers
  • UI displays correctly with no limits (component returns null), single limit, or multiple limits (session + weekly)
  • Real-time updates tested: UsageLimitsRepository.streamChanges triggers registry re-sync and WebSocket broadcast

- Persist provider rate limits when `account.rate-limits.updated` events arrive
- Normalize Claude (five_hour/seven_day) and Codex (primary/secondary) limit payloads
- Overlay persisted limits onto provider snapshots in registry
- Display color-coded progress bars in Settings > Providers (green >50%, amber 20-50%, red <20%)
- Real-time updates via WebSocket push when limits change
- Added SQLite `provider_usage_limits` table (migration 022)
- Added `UsageLimitsRepository` service with upsert, get, and `streamChanges` PubSub
@github-actions github-actions Bot added the size:L label Apr 9, 2026
- Show "Usage limits" label heading above usage window bars
- Display "No usage data yet." message instead of hiding section
- Improves UX clarity when awaiting first rate limit update
@github-actions github-actions Bot added size:XL and removed size:L labels Apr 9, 2026
- Updated integration and unit tests to use inline stub implementations of UsageLimitsRepository
- Removes dependency on UsageLimitsRepositoryLive layer in test fixtures
- Simplifies layer composition and decouples tests from live implementation details
@tyulyukov tyulyukov closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant