Conversation
refresh() negative-cached every failure as limits=[] with a fresh ts, so a single timeout or keychain hiccup blanked the per-model segment for the full 5-minute backoff, even with good data seconds old. Failures now keep the previous limits and record ok_ts, the time of the last successful fetch. cached_limits() bounds the data by ok_ts (same 10-minute window as before), so one blip is invisible while a real outage still hides the segment. Retry backoff is unchanged: ts still advances on every attempt.
The data is now bounded by ok_ts, so a regression that stopped stamping it would hide the segment for good after ten minutes; nothing covered the successful fetch before. Behaviour note: after logout or token revocation the last limits stay visible up to ten minutes instead of vanishing on the first failed refresh.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughScoped usage cache refreshes now preserve prior limits when a fetch fails. Cache reads use separate timestamps for retry scheduling and successful-result freshness. Tests cover failed and successful refreshes. ChangesScoped usage cache
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to No merge-blocking risk is identified for the scoped-usage cache change; it is mergeable after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Previously fetched limits can remain visible after credential failures, but only within the existing ten-minute freshness window. Account checks and bounded freshness remain in place. No security regression was established in the examined paths; broader security coverage remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Problem
scoped_usage.refresh()records every failure aslimits=[]with a freshts, andcached_limits()trusts that for 5 minutes, so a single timeout or keychain hiccup blanks the per-model segment until the next retry, even when good data is seconds old. Repro on 3.44.0: seed a good cache 301s old, make the fetch raiseTimeoutError, callrefresh()→cached_limits()returns[].Fix
limitsand writeok_ts(last successful fetch) alongsidets.cached_limits()applies its existing 10-minute window took_tsinstead ofts.tsstill advances on every attempt). Old cache files withoutok_tsfall back tots.Tests
test_scoped_failed_refresh_keeps_last_good_limits: one failed refresh keeps the data; data pastok_ts+ 600s is hidden. Fails onmain.test_scoped_successful_refresh_stamps_ok_ts: a mocked successful fetch stampsok_tsand serves the parsed limits (fails if theok_tsstamp is dropped).Full suite: 1246 passed.
Summary by CodeRabbit