fix(antigravity): align subscription tier detection with Antigravity Manager#2496
Conversation
…Manager Extract paid/current/restricted tiers from loadCodeAssist (shared module), fix invalid LINUX metadata on Docker, refresh tier on quota update without re-auth, and persist tier fields back to connections. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request refactors Antigravity subscription and plan label extraction logic to align with Antigravity Manager, introducing a centralized extraction service and a synchronization mechanism to persist live subscription data during quota refreshes. It also simplifies metadata headers and improves error handling within the usage service. Feedback from the review focuses on simplifying the tier ID extraction logic to remove redundant checks and optimizing the usage service to avoid duplicate cached data lookups during error scenarios.
| if (!isIneligible(subscription)) { | ||
| const currentId = pickTierField(subscription.currentTier, "id"); | ||
| if (currentId) return currentId; | ||
| } else { | ||
| const defaultTier = findDefaultAllowedTier(subscription); | ||
| const defaultId = defaultTier ? pickTierField(defaultTier, "id") : null; | ||
| if (defaultId) return defaultId; | ||
| } | ||
|
|
||
| if (Array.isArray(subscription.allowedTiers)) { | ||
| for (const tierValue of subscription.allowedTiers) { | ||
| const tier = toRecord(tierValue); | ||
| if (tier.isDefault) { | ||
| const id = pickTierField(tier, "id"); | ||
| if (id) return id; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const currentId = pickTierField(subscription.currentTier, "id"); | ||
| if (currentId) return currentId; | ||
|
|
||
| return "legacy-tier"; |
There was a problem hiding this comment.
The logic for extracting the tier ID can be simplified. The loop over allowedTiers (lines 79-87) is redundant because it performs the same check as findDefaultAllowedTier (called at line 74). Additionally, the fallback to currentTier at line 89 can be unified with the initial check to improve readability and maintainability.
if (!isIneligible(subscription)) {
const currentId = pickTierField(subscription.currentTier, "id");
if (currentId) return currentId;
}
const defaultTier = findDefaultAllowedTier(subscription);
const defaultId = defaultTier ? pickTierField(defaultTier, "id") : null;
if (defaultId) return defaultId;
const currentId = pickTierField(subscription.currentTier, "id");
if (currentId) return currentId;
return "legacy-tier";| let subscriptionInfo: unknown = null; | ||
| try { | ||
| subscriptionInfo = await getAntigravitySubscriptionInfoCached( | ||
| accessToken, | ||
| providerSpecificData, | ||
| options | ||
| ); | ||
| } catch { | ||
| subscriptionInfo = null; | ||
| } |
There was a problem hiding this comment.
This block performs a redundant call to getAntigravitySubscriptionInfoCached. Since this function was already called at the beginning of the getAntigravityUsage function (line 1813), you can reuse the result by declaring subscriptionInfo outside the try block. This avoids unnecessary overhead and potential duplicate network requests in error scenarios, especially when forceRefresh is enabled, as it would trigger another network attempt if the first one failed.
… cache Simplify onboard tier ID fallback and reuse subscription lookup in error path. Co-authored-by: Cursor <cursoragent@cursor.com>
| */ | ||
| function getAntigravityPlanLabel(subscriptionInfo: unknown, fallbackInfo?: unknown): string { | ||
| const plan = mapCodeAssistSubscriptionToPlanLabel(subscriptionInfo); | ||
| if (plan !== "Free") return plan; |
There was a problem hiding this comment.
SUGGESTION: getAntigravityPlanLabel returns immediately when live plan is not "Free", skipping the fallback to providerSpecificData. If the live subscription produces an unrecognized non-"Free" tier (e.g., a new tier type not yet in the mapping), the fallback to persisted data is never tried. This aligns with the PR goal to prefer live data, but could miss a better tier label when live data returns an unmapped value like a raw tier ID. Consider checking whether the mapped plan is a known tier before deciding to skip the fallback.
| if (tierId === "legacy-tier") return ""; | ||
| const upper = tierId.toUpperCase(); | ||
| if (mapCodeAssistTierIdToLabel(upper)) return upper; | ||
| return upper; |
There was a problem hiding this comment.
SUGGESTION: extractCodeAssistTierId returns upper even when mapCodeAssistTierIdToLabel(upper) returns null, meaning it can return arbitrary uppercase strings like "TIER_UNKNOWN_CUSTOM". While the caller (mapCodeAssistSubscriptionToPlanLabel) handles this by re-checking against mapCodeAssistTierIdToLabel, the function name suggests it extracts a valid tier ID rather than an uppercased raw value. Consider returning "" or null when no known mapping exists, to make the contract clearer.
Code Review SummaryStatus: 2 SUGGESTIONs Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Other Observations (not in diff)Issues found in unchanged code that cannot receive inline comments:
Files Reviewed (10 files)
Reviewed by qwen3.6-plus · 616,050 tokens |
Prefer persisted tier when live subscription maps to an unknown label, and only return mapped tier IDs from extractCodeAssistTierId. Add regression test for fallback from providerSpecificData. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Kilo Code Review could not run — your account is out of credits. Add credits or switch to a free model to enable reviews on this change. |
7cbb51d
into
diegosouzapw:release/v3.8.2
|
Thank you for this contribution! 🎉 Your fix has been integrated into the release/v3.8.2 branch via local merge (conflicts resolved). Will ship with v3.8.2. |
Summary
loadCodeAssisttier extraction (paidTier→currentTier→ restrictedallowedTiersdefault), matching Antigravity Manager.loadCodeAssistmetadata on Linux/Docker: send only{ ideType: "ANTIGRAVITY" }(Google rejectsplatform: "LINUX").tier/subscriptionTier/planback to connections.Test plan
tests/unit/code-assist-subscription.test.tstests/unit/antigravity-headers.test.tstests/unit/oauth-providers-config.test.ts(Antigravity OAuth)tests/unit/usage-service-hardening.test.ts(Antigravity plan labels + refresh cache)