From 67bcd4def44ae3a0e0f37a870c83cc38ba460ea6 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 17 Dec 2025 09:34:32 +0900 Subject: [PATCH] fix(auth): resolve Google Antigravity OAuth 404 error by using fallback project ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When project ID fetching failed, an empty string was returned causing 404 errors on API requests. Now uses ANTIGRAVITY_DEFAULT_PROJECT_ID as fallback: - isFreeTier(): Returns true when tierId is undefined (free tier by default) - Import ANTIGRAVITY_DEFAULT_PROJECT_ID constant - Replace empty project ID returns with fallback in all code paths: - When loadCodeAssist returns null - When PAID tier is detected - When non-FREE tier without project - When onboard/managed project ID fetch fails Matches behavior of NoeFabris/opencode-antigravity-auth implementation. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) --- src/auth/antigravity/project.ts | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/auth/antigravity/project.ts b/src/auth/antigravity/project.ts index 81dd97f..150a02c 100644 --- a/src/auth/antigravity/project.ts +++ b/src/auth/antigravity/project.ts @@ -9,6 +9,7 @@ import { ANTIGRAVITY_ENDPOINT_FALLBACKS, ANTIGRAVITY_API_VERSION, ANTIGRAVITY_HEADERS, + ANTIGRAVITY_DEFAULT_PROJECT_ID, } from "./constants" import type { AntigravityProjectContext, @@ -58,7 +59,7 @@ function getDefaultTierId(allowedTiers?: AntigravityUserTier[]): string | undefi } function isFreeTier(tierId: string | undefined): boolean { - if (!tierId) return false + if (!tierId) return true // No tier = assume free tier (default behavior) const lower = tierId.toLowerCase() return lower === "free" || lower === "free-tier" || lower.startsWith("free") } @@ -209,19 +210,28 @@ export async function fetchProjectContext( } } - // No project ID from loadCodeAssist - check tier and onboard if FREE + // No project ID from loadCodeAssist - try with fallback project ID if (!loadPayload) { - debugLog(`[fetchProjectContext] loadCodeAssist returned null, returning empty`) - return { cloudaicompanionProject: "" } + debugLog(`[fetchProjectContext] loadCodeAssist returned null, trying with fallback project ID`) + const fallbackPayload = await callLoadCodeAssistAPI(accessToken, ANTIGRAVITY_DEFAULT_PROJECT_ID) + const fallbackProjectId = extractProjectId(fallbackPayload?.cloudaicompanionProject) + if (fallbackProjectId) { + const result: AntigravityProjectContext = { cloudaicompanionProject: fallbackProjectId } + projectContextCache.set(accessToken, result) + debugLog(`[fetchProjectContext] Using fallback project ID: ${fallbackProjectId}`) + return result + } + debugLog(`[fetchProjectContext] Fallback also failed, using default: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`) + return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID } } const currentTierId = loadPayload.currentTier?.id debugLog(`[fetchProjectContext] currentTier: ${currentTierId}, allowedTiers: ${JSON.stringify(loadPayload.allowedTiers)}`) if (currentTierId && !isFreeTier(currentTierId)) { - // PAID tier requires user-provided project ID - debugLog(`[fetchProjectContext] PAID tier detected, returning empty (user must provide project)`) - return { cloudaicompanionProject: "" } + // PAID tier - still use fallback if no project provided + debugLog(`[fetchProjectContext] PAID tier detected (${currentTierId}), using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`) + return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID } } const defaultTierId = getDefaultTierId(loadPayload.allowedTiers) @@ -229,8 +239,8 @@ export async function fetchProjectContext( debugLog(`[fetchProjectContext] Resolved tierId: ${tierId}`) if (!isFreeTier(tierId)) { - debugLog(`[fetchProjectContext] Non-FREE tier without project, returning empty`) - return { cloudaicompanionProject: "" } + debugLog(`[fetchProjectContext] Non-FREE tier (${tierId}) without project, using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`) + return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID } } // FREE tier - onboard to get server-assigned managed project ID @@ -246,8 +256,8 @@ export async function fetchProjectContext( return result } - debugLog(`[fetchProjectContext] Failed to get managed project ID, returning empty`) - return { cloudaicompanionProject: "" } + debugLog(`[fetchProjectContext] Failed to get managed project ID, using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`) + return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID } } export function clearProjectContextCache(accessToken?: string): void {