{"record":{"id":"82f62dca05ab8790","repo":"can1357/oh-my-pi","slug":"failed-to-unmarshal-loadcodeassistresponse-resu","errorCode":null,"errorMessage":"failed to unmarshal LoadCodeAssistResponse: ${result.summary}","messagePattern":"failed to unmarshal LoadCodeAssistResponse: (.+?)","errorType":"exception","errorClass":"AIError.OAuthError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/registry/oauth/google-antigravity.ts","lineNumber":97,"sourceCode":"type OperationError = typeof operationErrorSchema.infer;\n\nconst onboardUserResponseSchema = type({\n\t\"@type\": \"string\",\n\t\"cloudaicompanionProject?\": \"string\",\n});\n\nconst onboardOperationSchema = type({\n\t\"name?\": \"string\",\n\t\"done?\": \"boolean\",\n\t\"error?\": operationErrorSchema.or(\"null\"),\n\t\"response?\": onboardUserResponseSchema.or(\"null\"),\n});\ntype OnboardOperation = typeof onboardOperationSchema.infer;\n\nfunction parseLoadCodeAssistResponse(payload: unknown): LoadCodeAssistResponse {\n\tconst result = loadCodeAssistResponseSchema(payload);\n\tif (result instanceof type.errors) {\n\t\tthrow new AIError.OAuthError(`failed to unmarshal LoadCodeAssistResponse: ${result.summary}`, {\n\t\t\tkind: \"provisioning\",\n\t\t\tprovider: PROVIDER,\n\t\t});\n\t}\n\treturn result;\n}\n\nfunction parseOnboardOperation(payload: unknown): OnboardOperation {\n\tconst result = onboardOperationSchema(payload);\n\tif (result instanceof type.errors) {\n\t\tthrow new AIError.OAuthError(`failed to unmarshal OnboardUser operation: ${result.summary}`, {\n\t\t\tkind: \"provisioning\",\n\t\t\tprovider: PROVIDER,\n\t\t});\n\t}\n\treturn result;\n}\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/ai/src/registry/oauth/google-antigravity.ts#L79-L115","documentation":"parseLoadCodeAssistResponse validates the body of Google Cloud Code Assist's loadCodeAssist endpoint against an ArkType-style schema (currentTier, paidTier, allowedTiers, ineligibleTiers, cloudaicompanionProject). If the payload does not conform, this provisioning OAuthError includes the schema error summary. The login flow cannot determine account tiers or project without a well-formed response.","triggerScenarios":"postLoadCodeAssist receives HTTP 200 JSON that fails loadCodeAssistResponseSchema — e.g. allowedTiers present but not an array of {id} objects, currentTier of wrong shape, an error envelope, or Google changing the v1internal response shape.","commonSituations":"Google rolling out an API shape change to the internal daily-cloudcode-pa endpoint; a proxy or captive portal returning HTML/JSON that parses but has the wrong fields; region-restricted accounts receiving an alternate payload; library version lagging behind a Google-side schema update.","solutions":["Read result.summary in the message to see exactly which field failed validation.","Update the library/package to the latest version in case Google changed the loadCodeAssist response shape.","Log the raw response payload from loadCodeAssist and compare against the expected schema fields.","Retry the login later if Google is mid-rollout; check provider status pages.","Ensure no proxy/corporate gateway is rewriting the endpoint response."],"exampleFix":"// before: assume shape, crash on drift\nconst data = await response.json();\nreturn data as LoadCodeAssistResponse;\n\n// after: surface the schema summary and raw payload for diagnosis\nconst result = loadCodeAssistResponseSchema(await response.json());\nif (result instanceof type.errors) {\n  throw new Error(`loadCodeAssist shape changed: ${result.summary}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function looksLikeLoadCodeAssist(p: unknown): boolean {\n  if (typeof p !== \"object\" || p === null) return false;\n  const o = p as Record<string, unknown>;\n  return \"allowedTiers\" in o || \"cloudaicompanionProject\" in o || \"currentTier\" in o || \"paidTier\" in o;\n}","tryCatchPattern":"try {\n  const project = await discoverProject(accessToken);\n} catch (err) {\n  if (err instanceof AIError.OAuthError && String(err.message).startsWith(\"failed to unmarshal LoadCodeAssistResponse\")) {\n    // schema mismatch — update library or inspect raw payload; retry once in case of transient drift\n    await Bun.sleep(1000);\n    const project = await discoverProject(accessToken);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Keep the package updated — Google can change the v1internal loadCodeAssist shape at any time.","Exclude the daily-cloudcode-pa.googleapis.com endpoint from response-rewriting proxies.","Log the raw 200 body (redacted) when schema validation fails to diagnose drift quickly.","Treat this as an API-contract problem, not a credentials problem — re-login won't help."],"tags":["google","oauth","schema-validation","provisioning"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}