From 0f9d08018b7b87bbe61f40b4abcdcb37be7e92dc Mon Sep 17 00:00:00 2001 From: Gemini Nexus Bot Date: Wed, 22 Apr 2026 02:33:51 -0300 Subject: [PATCH] fix: resolve startup issues with account activation, credit fetch and poll noise - GoogleAPIService: try loadCodeAssist first for AI credits since fetchCredits returns 404 for many accounts; keep fetchCredits as fallback, removing the spurious warn on every poll cycle - CloudAccountRepo: auto-activate the most-recently-used account when no account has is_active=1; downgrade noisy [DEBUG] log from info to debug level - StatusBar: increase process-status refetch interval from 10s to 30s to reduce redundant IPC calls and log noise --- src/components/StatusBar.tsx | 2 +- src/ipc/database/cloudHandler.ts | 16 ++++++--- src/services/GoogleAPIService.ts | 57 ++++++++++++++++---------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/components/StatusBar.tsx b/src/components/StatusBar.tsx index 23dbf91..727b208 100644 --- a/src/components/StatusBar.tsx +++ b/src/components/StatusBar.tsx @@ -18,7 +18,7 @@ export const StatusBar: React.FC = ({ isCollapsed = false }) => const { data: isRunning, isLoading } = useQuery({ queryKey: ['process', 'status'], queryFn: isProcessRunning, - refetchInterval: 10000, + refetchInterval: 30000, }); const startMutation = useMutation({ diff --git a/src/ipc/database/cloudHandler.ts b/src/ipc/database/cloudHandler.ts index 00228c6..cb97d69 100644 --- a/src/ipc/database/cloudHandler.ts +++ b/src/ipc/database/cloudHandler.ts @@ -521,12 +521,20 @@ export class CloudAccountRepo { try { const rows = orm.select().from(accounts).orderBy(desc(accounts.lastUsed)).all(); - // DEBUG LOGS const activeRows = rows.filter((r) => r.isActive); - logger.info( - `[DEBUG] getAccounts: Found ${rows.length} accounts, ${activeRows.length} active.`, + logger.debug( + `getAccounts: Found ${rows.length} accounts, ${activeRows.length} active.`, ); - activeRows.forEach((r) => logger.info(`[DEBUG] Active Account: ${r.email} (${r.id})`)); + + // Auto-activate the single account if none are active + if (rows.length > 0 && activeRows.length === 0) { + const targetRow = rows[0]; + logger.info( + `No active account found. Auto-activating account: ${targetRow.email} (${targetRow.id})`, + ); + orm.update(accounts).set({ isActive: 1 }).where(eq(accounts.id, targetRow.id)).run(); + targetRow.isActive = 1; + } const cloudAccounts: CloudAccount[] = []; for (const normalizedRow of rows) { diff --git a/src/services/GoogleAPIService.ts b/src/services/GoogleAPIService.ts index bf236be..e0d7606 100644 --- a/src/services/GoogleAPIService.ts +++ b/src/services/GoogleAPIService.ts @@ -848,6 +848,34 @@ export class GoogleAPIService { ): Promise<{ credits: number; expiryDate: string } | null> { try { const fetchOptions = this.getFetchOptions(proxyUrl); + + // Try loadCodeAssist first — fetchCredits returns 404 for many accounts + // and loadCodeAssist provides the same paid tier credit data. + const discoveryVersion = resolveLocalInstalledVersion() ?? FALLBACK_VERSION; + const loadAssistResponse = await fetch(URLS.DAILY_LOAD_PROJECT, { + method: 'POST', + headers: buildInternalApiHeaders(accessToken), + body: JSON.stringify({ + metadata: { + ide_type: 'ANTIGRAVITY', + ide_version: discoveryVersion, + ide_name: 'geminiNexus', + }, + }), + signal: createTimeoutSignal(REQUEST_TIMEOUT_MS), + ...fetchOptions, + }); + + if (loadAssistResponse.ok) { + const loadAssistData = (await loadAssistResponse.json()) as LoadProjectResponse; + const credits = extractAiCreditsFromProjectContext(loadAssistData); + if (credits) { + return credits; + } + } + + // Fallback to the legacy fetchCredits endpoint if loadCodeAssist + // did not return usable credit data. const response = await fetch(URLS.FETCH_CREDITS, { method: 'POST', headers: buildInternalApiHeaders(accessToken), @@ -867,34 +895,7 @@ export class GoogleAPIService { return toAiCredits(data); } - if (response.status !== 404) { - return null; - } - - // `fetchCredits` has started returning 404 for some accounts. Reuse the - // internal `loadCodeAssist` payload, which also exposes paid tier credits. - logger.warn('[GoogleAPIService] fetchCredits returned 404, falling back to loadCodeAssist'); - const discoveryVersion = resolveLocalInstalledVersion() ?? FALLBACK_VERSION; - const fallbackResponse = await fetch(URLS.DAILY_LOAD_PROJECT, { - method: 'POST', - headers: buildInternalApiHeaders(accessToken), - body: JSON.stringify({ - metadata: { - ide_type: 'ANTIGRAVITY', - ide_version: discoveryVersion, - ide_name: 'geminiNexus', - }, - }), - signal: createTimeoutSignal(REQUEST_TIMEOUT_MS), - ...fetchOptions, - }); - - if (!fallbackResponse.ok) { - return null; - } - - const fallbackData = (await fallbackResponse.json()) as LoadProjectResponse; - return extractAiCreditsFromProjectContext(fallbackData); + return null; } catch { return null; }