{"record":{"id":"1caaa1bcd0258ca5","repo":"jackwener/OpenCLI","slug":"http-result-httpstatus-from-api-auth-session-1caaa1","errorCode":null,"errorMessage":"HTTP ${result.httpStatus} from /api/auth/session","messagePattern":"HTTP (.+?) from /api/auth/session","errorType":"http","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/grok/auth.js","lineNumber":33,"sourceCode":"  const result = await page.evaluate(`(async () => {\n    try {\n      const res = await fetch('/api/auth/session', { credentials: 'include', headers: { 'Accept': 'application/json' } });\n      if (res.status === 401 || res.status === 403) {\n        return { kind: 'auth', detail: 'Grok /api/auth/session HTTP ' + res.status };\n      }\n      if (!res.ok) return { kind: 'http', httpStatus: res.status };\n      const d = await res.json();\n      const user = d && d.user;\n      if (!user || !user.id) {\n        return { kind: 'auth', detail: 'Grok /api/auth/session has no user — anonymous' };\n      }\n      return { ok: true, user_id: String(user.id), name: String(user.name || '') };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (result?.kind === 'auth') throw new AuthRequiredError('grok.com', result.detail);\n  if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /api/auth/session`);\n  if (result?.kind === 'exception') throw new CommandExecutionError(`Grok whoami failed: ${result.detail}`);\n  if (!result?.ok) throw new CommandExecutionError(`Unexpected Grok probe: ${JSON.stringify(result)}`);\n  return { user_id: result.user_id, name: result.name };\n}\n\nregisterSiteAuthCommands({\n  site: 'grok',\n  domain: 'grok.com',\n  loginUrl: 'https://grok.com/auth/sign-in',\n  columns: ['user_id', 'name'],\n  quickCheck: hasGrokSessionCookie,\n  verify: verifyGrokIdentity,\n  poll: async (page) => {\n    if (!await hasGrokSessionCookie(page)) {\n      throw new AuthRequiredError('grok.com', 'Waiting for Grok session cookie');\n    }\n    return verifyGrokIdentity(page);\n  },","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/grok/auth.js#L15-L51","documentation":"verifyGrokIdentity() throws CommandExecutionError(`HTTP <status> from /api/auth/session`) when the in-page probe gets a non-OK response from Grok's NextAuth session endpoint that is not an auth status (i.e. anything other than 200/401/403 — e.g. 429, 5xx, 502/503). This is not a login problem: the session endpoint itself failed or is rate-limiting/throttling, so the identity check cannot complete. It is distinguished from AuthRequiredError precisely so users do not needlessly re-login.","triggerScenarios":"Running the grok auth verify/whoami flow when the fetch('/api/auth/session') inside page.evaluate returns a status like 429 (rate limited), 500/502/503/504 (server error), or any other non-OK, non-401/403 code — e.g. grok.com is having an outage, is throttling the IP, or a gateway/CDN in front of it errors.","commonSituations":"grok.com server-side incident or maintenance window; IP-level rate limiting after many automated requests; CDN/proxy (Cloudflare) 5xx responses; transient network errors at the edge during peak load; retry storms from multiple concurrent CLI runs hammering the endpoint.","solutions":["Wait briefly and retry the verify/whoami command — 429/5xx are usually transient; back off exponentially if rate-limited.","Check grok.com status in a normal browser (or status page) to see if it's an outage before troubleshooting locally.","If 429, reduce request frequency / avoid running multiple grok commands concurrently from the same IP.","If 5xx persist, try a different network/IP to rule out edge or proxy-level blocking.","Do NOT re-login for this error — the session cookie is not the problem; re-auth will not fix a server-side failure."],"exampleFix":"// before: immediate verify during an outage\nconst who = await grokWhoami(); // CommandExecutionError: HTTP 503 from /api/auth/session\n// after: retry with backoff\nasync function whoamiWithRetry() {\n  for (let attempt = 0; attempt < 4; attempt++) {\n    try { return await grokWhoami(); }\n    catch (e) {\n      if (!/HTTP \\d+ from \\/api\\/auth\\/session/.test(e.message) || attempt === 3) throw e;\n      await new Promise(r => setTimeout(r, 2 ** attempt * 2000));\n    }\n  }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const who = await run('grok', 'whoami');\n} catch (e) {\n  const m = /HTTP (\\d{3}) from \\/api\\/auth\\/session/.exec(e.message ?? '');\n  if (m && Number(m[1]) !== 401 && Number(m[1]) !== 403) {\n    // server-side issue: back off and retry, do NOT re-login\n    await new Promise(r => setTimeout(r, 5000));\n    return await run('grok', 'whoami');\n  }\n  throw e;\n}","preventionTips":["Add exponential-backoff retries around grok verify/whoami calls for 429/5xx statuses.","Serialize grok commands instead of running many concurrently from one IP.","Check grok.com availability (browser or status page) before blaming local configuration.","Distinguish HTTP-status errors from AuthRequiredError — only the latter warrants re-login.","Route automated traffic through a stable, non-throttled network path."],"tags":["http","server-error","rate-limit","grok","network"],"backgroundTag":"http-5xx-server-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}