Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deep-cody) Rate Limiter Reset Logic (#6366)
FIX https://linear.app/sourcegraph/issue/CODY-4529 # Fix Deep Cody Rate Limiter Reset Logic This PR fixes an issue where users were unable to use Deep Cody even after the 24-hour cooldown period had elapsed. ## Changes - Added explicit 24-hour reset check in `DeepCodyRateLimiter.isAtLimit()` - Simplified quota replenishment logic - Improved handling of initial quota state ## Technical Details Previously, the rate limiter used a continuous time-based quota replenishment system that calculated partial quotas based on elapsed time. This led to unexpected behavior where users wouldn't get a fresh quota even after not using Deep Cody for over 24 hours. The updated implementation: 1. First checks if a full day (24 hours) has passed since last usage 2. If yes, immediately resets to full quota 3. If no, calculates remaining quota using time-based replenishment ## Test plan <!-- Required. See https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles. --> Added new test case resets quota after 24 hours of non-use that specifically tests the 24-hour reset functionality Test verifies that: - When last use was 25 hours ago (>24h) - With an empty quota (0) - The limiter resets to full quota (50) - Confirms the storage is updated with new quota and timestamp Maintained all existing test cases to ensure no regressions Uses the same test infrastructure (mocks, beforeEach setup) ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c -->
- Loading branch information