Skip to content

Commit 67bcd4d

Browse files
committed
fix(auth): resolve Google Antigravity OAuth 404 error by using fallback project ID
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)
1 parent 40fe65d commit 67bcd4d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/auth/antigravity/project.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ANTIGRAVITY_ENDPOINT_FALLBACKS,
1010
ANTIGRAVITY_API_VERSION,
1111
ANTIGRAVITY_HEADERS,
12+
ANTIGRAVITY_DEFAULT_PROJECT_ID,
1213
} from "./constants"
1314
import type {
1415
AntigravityProjectContext,
@@ -58,7 +59,7 @@ function getDefaultTierId(allowedTiers?: AntigravityUserTier[]): string | undefi
5859
}
5960

6061
function isFreeTier(tierId: string | undefined): boolean {
61-
if (!tierId) return false
62+
if (!tierId) return true // No tier = assume free tier (default behavior)
6263
const lower = tierId.toLowerCase()
6364
return lower === "free" || lower === "free-tier" || lower.startsWith("free")
6465
}
@@ -209,28 +210,37 @@ export async function fetchProjectContext(
209210
}
210211
}
211212

212-
// No project ID from loadCodeAssist - check tier and onboard if FREE
213+
// No project ID from loadCodeAssist - try with fallback project ID
213214
if (!loadPayload) {
214-
debugLog(`[fetchProjectContext] loadCodeAssist returned null, returning empty`)
215-
return { cloudaicompanionProject: "" }
215+
debugLog(`[fetchProjectContext] loadCodeAssist returned null, trying with fallback project ID`)
216+
const fallbackPayload = await callLoadCodeAssistAPI(accessToken, ANTIGRAVITY_DEFAULT_PROJECT_ID)
217+
const fallbackProjectId = extractProjectId(fallbackPayload?.cloudaicompanionProject)
218+
if (fallbackProjectId) {
219+
const result: AntigravityProjectContext = { cloudaicompanionProject: fallbackProjectId }
220+
projectContextCache.set(accessToken, result)
221+
debugLog(`[fetchProjectContext] Using fallback project ID: ${fallbackProjectId}`)
222+
return result
223+
}
224+
debugLog(`[fetchProjectContext] Fallback also failed, using default: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`)
225+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID }
216226
}
217227

218228
const currentTierId = loadPayload.currentTier?.id
219229
debugLog(`[fetchProjectContext] currentTier: ${currentTierId}, allowedTiers: ${JSON.stringify(loadPayload.allowedTiers)}`)
220230

221231
if (currentTierId && !isFreeTier(currentTierId)) {
222-
// PAID tier requires user-provided project ID
223-
debugLog(`[fetchProjectContext] PAID tier detected, returning empty (user must provide project)`)
224-
return { cloudaicompanionProject: "" }
232+
// PAID tier - still use fallback if no project provided
233+
debugLog(`[fetchProjectContext] PAID tier detected (${currentTierId}), using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`)
234+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID }
225235
}
226236

227237
const defaultTierId = getDefaultTierId(loadPayload.allowedTiers)
228238
const tierId = defaultTierId ?? "free-tier"
229239
debugLog(`[fetchProjectContext] Resolved tierId: ${tierId}`)
230240

231241
if (!isFreeTier(tierId)) {
232-
debugLog(`[fetchProjectContext] Non-FREE tier without project, returning empty`)
233-
return { cloudaicompanionProject: "" }
242+
debugLog(`[fetchProjectContext] Non-FREE tier (${tierId}) without project, using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`)
243+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID }
234244
}
235245

236246
// FREE tier - onboard to get server-assigned managed project ID
@@ -246,8 +256,8 @@ export async function fetchProjectContext(
246256
return result
247257
}
248258

249-
debugLog(`[fetchProjectContext] Failed to get managed project ID, returning empty`)
250-
return { cloudaicompanionProject: "" }
259+
debugLog(`[fetchProjectContext] Failed to get managed project ID, using fallback: ${ANTIGRAVITY_DEFAULT_PROJECT_ID}`)
260+
return { cloudaicompanionProject: ANTIGRAVITY_DEFAULT_PROJECT_ID }
251261
}
252262

253263
export function clearProjectContextCache(accessToken?: string): void {

0 commit comments

Comments
 (0)