{"record":{"id":"58aff60e5916360a","repo":"decolua/9router","slug":"loadcodeassist-failed-http-response-status-e","errorCode":null,"errorMessage":"loadCodeAssist failed: HTTP ${response.status} ${errorText.slice(0, 200)}","messagePattern":"loadCodeAssist failed: HTTP (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"open-sse/services/projectId.js","lineNumber":170,"sourceCode":" * Falls back to onboardUser when loadCodeAssist returns no project.\n *\n * @param {string}      accessToken\n * @param {AbortSignal} signal\n * @returns {Promise<string|null>}\n */\nasync function fetchProjectId(accessToken, signal, provider) {\n    const endpoints = CLOUD_CODE_API[provider] || CLOUD_CODE_API[\"gemini-cli\"];\n    const headers = provider === \"antigravity\" ? ANTIGRAVITY_LOAD_CODE_ASSIST_HEADERS : LOAD_CODE_ASSIST_HEADERS;\n    const response = await fetch(endpoints.loadCodeAssist, {\n        method: \"POST\",\n        headers: { ...headers, \"Authorization\": `Bearer ${accessToken}` },\n        body: JSON.stringify({ metadata: LOAD_CODE_ASSIST_METADATA }),\n        signal\n    });\n\n    if (!response.ok) {\n        const errorText = await response.text().catch(() => \"\");\n        throw new Error(`loadCodeAssist failed: HTTP ${response.status} ${errorText.slice(0, 200)}`);\n    }\n\n    const data = await response.json();\n    const projectId = extractProjectId(data);\n    if (projectId) return projectId;\n\n    // Determine the tier to use for onboarding\n    let tierID = \"legacy-tier\";\n    if (Array.isArray(data.allowedTiers)) {\n        for (const tier of data.allowedTiers) {\n            if (tier && typeof tier === \"object\" && tier.isDefault === true) {\n                if (tier.id && typeof tier.id === \"string\" && tier.id.trim()) {\n                    tierID = tier.id.trim();\n                    break;\n                }\n            }\n        }\n    }","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/open-sse/services/projectId.js#L152-L188","documentation":"fetchProjectId calls Google's Cloud Code loadCodeAssist endpoint to resolve the real GCP project ID bound to the authenticated account. When the HTTP response is not OK, it throws with the status code plus the first 200 chars of the error body. This means Google rejected the loadCodeAssist call itself, before any project ID could be extracted.","triggerScenarios":"The POST to the cloudcode-pa.googleapis.com loadCodeAssist endpoint returns a non-2xx status — typically 401/403 from an expired/revoked OAuth access token, 429 from rate limiting, or 5xx from a Google-side outage.","commonSituations":"Stale OAuth credentials after the account was re-authorized elsewhere; Google Cloud Code API unavailable or region-restricted; proxy misconfiguration routing requests through a blocked egress; account flagged by Google anti-abuse.","solutions":["Refresh the connection's OAuth access token (re-run the token refresh / re-authorize the Gemini/Antigravity account) and retry","Inspect the error body in the message (first 200 chars) for the actual Google error reason (e.g. UNAUTHENTICATED, PERMISSION_DENIED)","Check proxy settings — ensure the request can reach cloudcode-pa.googleapis.com","Retry later on 429/5xx; the fetch is deduplicated and cached for 1 hour, so a retry after the transient issue is cheap"],"exampleFix":"// before\nconst projectId = await fetchProjectId(accessToken, proxyOptions);\n// after\nlet projectId;\ntry {\n  projectId = await fetchProjectId(accessToken, proxyOptions);\n} catch (e) {\n  if (/HTTP 401|HTTP 403/.test(e.message)) {\n    accessToken = await refreshToken(connection);\n    projectId = await fetchProjectId(accessToken, proxyOptions);\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":"// before calling fetchProjectId\nif (!accessToken || accessToken.split('.').length !== 3) {\n  throw new Error('Gemini connection has no valid access token; re-authorize first.');\n}","typeGuard":"function hasToken(t) { return typeof t === 'string' && t.length > 20 && t.includes('.'); }","tryCatchPattern":"try {\n  projectId = await fetchProjectId(accessToken, proxyOptions);\n} catch (e) {\n  if (/HTTP (401|403)/.test(e.message)) {\n    accessToken = await refreshToken(conn); // re-auth then retry once\n    projectId = await fetchProjectId(accessToken, proxyOptions);\n  } else if (/HTTP (429|5\\d\\d)/.test(e.message)) {\n    await backoff(); // retry later\n  } else throw e;\n}","preventionTips":["Keep OAuth refresh scheduled before token expiry so loadCodeAssist never sees a stale token","Trust the 1-hour project ID cache; avoid forcing refetches that multiply upstream calls","Check the 200-char error body in the message first — it names the Google error reason","Verify proxy egress to cloudcode-pa.googleapis.com during setup"],"tags":["network","http","oauth","google-cloud"],"backgroundTag":"http-error-response","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}