Repository navigation
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
|
| Layer / File(s) | Summary |
|---|---|
Resolve Copilot identity src/lib/usage-limits.js |
Plaintext and database auth resolution now return the token with the account login. Copilot limit requests use the combined auth result, and 401/403 errors receive an authentication-expired marker. |
Persist and use cached quota windows src/lib/usage-limits.js, test/copilot-limits-cache-fallback.test.js |
Successful quota results are cached by identity. Eligible failures use matching cached windows after expired windows are removed. Tests cover persistence, fallback, authentication errors, account changes, window expiry, cache age, and missing identity. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant fetchCopilotLimits
participant readCopilotAuthAsync
participant CopilotAPI
participant CopilotDiskCache
participant usageAggregation
fetchCopilotLimits->>readCopilotAuthAsync: Resolve token and identity
readCopilotAuthAsync-->>fetchCopilotLimits: Return token and identity
fetchCopilotLimits->>CopilotAPI: Request quota windows
CopilotAPI-->>fetchCopilotLimits: Return quota result
alt Successful quota result
fetchCopilotLimits->>CopilotDiskCache: Store windows for identity
else Eligible provider failure
fetchCopilotLimits->>CopilotDiskCache: Read matching cached windows
CopilotDiskCache-->>fetchCopilotLimits: Return unexpired windows
end
fetchCopilotLimits->>usageAggregation: Provide result without internal markers
Possibly related issues
- Issue 941: The issue lists Copilot as part of the last-good disk-cache fallback rollout. This change adds Copilot stale fallback and cache safeguards.
Suggested labels: cli, tests
Merge Risk: 
Low · previous review 60e35
-
Copilot cache fallback can briefly stall the embedded server when it re-reads account identity. Address the blocking path before merge if responsive polling is required; otherwise this is a bounded risk to accept.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 34.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 23 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Copilot item of #941 (Cursor landed in #985). The remaining providers (Gemini/Kimi/Kiro/Grok/Devin) will follow as separate per-provider PRs.
What
The GitHub Copilot usage-limits card previously flashed "fetch failed" (or blanked) on any timeout / 5xx from
api.github.com/copilot_internal/user, until the next poll succeeded. Now every successful live read is persisted to disk, and a failed poll serves the last-good windows withstale: true+ originalcached_at— both UIs already render that provenance, no UI change.~/.tokentracker/tracker/copilot-usage-limits-cache.json(never shared), atomic tmp+rename+0600 write, mirroring the codex / claude / opencode-go / cursor caches.Red lines kept
AUTH_EXPIREDcode (message text unchanged: "GitHub Copilot token rejected. Re-authenticate via GitHub Copilot CLI/extension.") and the assembly never covers it with stale cache (opencode-goauth_errorprecedent).reset_atbuilt from the monthlyquota_reset_date; cached windows whose reset has already passed are dropped and never served as current (windows are per-snapshot, so a partially-rolled entry serves only the surviving window).COPILOT_LIMITS_CACHE_MAX_AGE_MS, codex precedent).hosts.json/apps.jsonentry'suserfield, or theauth.dbrow'suser_login(zcode login-identity precedent). The identity always comes from the same auth-source resolution that produced the token, so it can never point at a different account than the one being served. Reads require stored identity == current identity; writes without an identity are refused. An account switch therefore surfaces the live error instead of another account's bars.Implementation notes
readCopilotAuth/readCopilotAuthAsync(token + identity in one pass); the publicreadCopilotOauthToken[Async]shape is unchanged (still returns the bare token string), andstatus.jskeeps working untouched.fetchCopilotLimitsnow returns an internalcache_identity(andauth_error: trueon token rejection); both are stripped in the aggregate before the payload is served — payload shape unchanged, otel probe fields preserved.resolveCopilotCacheIdentity, same source priority as the token) and the fallback still lands.Tests
New
test/copilot-limits-cache-fallback.test.js— 8 aggregate-level pinning tests throughgetUsageLimits:stale:false/cached_at, writes the identity-stamped disk entry (on-disk schema pinned), later failure serves it stale withprovenance.source: "disk-cache", preservedcached_at, and intact otel fields;reset_atis dropped; a partially-rolled entry serves only the surviving window;The fixture uses the plaintext
hosts.jsonpath (token + non-secretuserlogin), so the suite runs on every engine with no sqlite/keychain dependency; the auth.db identity plumbing is pinned by the existingtest/copilot-auth-db.test.jsplus a directreadCopilotAuthassertion.Local: full root suite green (
npm test, node v24, 4609 tests; the two load-sensitive flakes seen in a saturated full run —owner-proven trial rechecktimeout, reset-bank race — pass in isolated reruns 4/4, known host-specific, untouched by this change); targeted: copilot-auth-db 15, new 8, usage-limits 229.Summary by CodeRabbit