{"record":{"id":"e2221bd07a0b3cc7","repo":"coleam00/Archon","slug":"openai-token-operation-request-timed-out","errorCode":null,"errorMessage":"OpenAI token ${operation} request timed out.","messagePattern":"OpenAI token (.+?) request timed out\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/credentials/openai-oauth.ts","lineNumber":178,"sourceCode":"  let response: Response;\n  try {\n    response = await fetch(OPENAI_TOKEN_URL, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n      body,\n      // The 30s ceiling applies ALWAYS — combined with the caller's session\n      // signal when present. Without it, a hung token endpoint would leave a\n      // bridge login reporting `pending` for the session's full 10-minute TTL.\n      signal: signal\n        ? AbortSignal.any([signal, AbortSignal.timeout(30_000)])\n        : AbortSignal.timeout(30_000),\n    });\n  } catch (error) {\n    if (signal?.aborted) {\n      throw new Error('Login cancelled');\n    }\n    if (error instanceof Error && error.name === 'TimeoutError') {\n      throw new Error(`OpenAI token ${operation} request timed out.`);\n    }\n    throw new Error(\n      `OpenAI token ${operation} request failed: ${error instanceof Error ? error.message : String(error)}`\n    );\n  }\n  if (!response.ok) {\n    // Strip the error body down to the OAuth `error` code: this message flows\n    // into the bridge's session.detail (and on to the browser/CLI), and OpenAI\n    // error bodies can carry account identifiers. Never include the raw body.\n    const text = await response.text().catch(() => '');\n    let errorCode = '';\n    try {\n      const parsed = JSON.parse(text) as { error?: unknown };\n      if (typeof parsed.error === 'string') {\n        errorCode = parsed.error;\n      } else if (parsed.error && typeof parsed.error === 'object') {\n        const code = (parsed.error as { code?: unknown }).code;\n        if (typeof code === 'string') errorCode = code;","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/core/src/credentials/openai-oauth.ts#L160-L196","documentation":"postTokenRequest (openai-oauth.ts:178) applies a hard 30s ceiling to every call to OpenAI's token endpoint (combined with the caller's signal via AbortSignal.any). If the request itself times out (TimeoutError) it throws 'OpenAI token <exchange|refresh> request timed out.' This prevents a hung token endpoint from leaving a bridge login stuck 'pending' for the full 10-minute session TTL.","triggerScenarios":"The POST to OPENAI_TOKEN_URL does not respond within 30 seconds — network stalls, a hanging proxy, or an unresponsive auth.openai.com endpoint — during either the authorization-code exchange or refresh flow.","commonSituations":"Corporate proxy buffering/hanging connections; OpenAI auth outage or degraded performance; flaky mobile/VPN network during login; firewall silently dropping long-lived connections.","solutions":["Retry the login (exchange) or wait and retry the refresh — the timeout is transient-safe by design.","Check network/proxy reachability to the OpenAI token endpoint (curl/openssl to auth.openai.com).","Bypass or fix a hung corporate proxy, or add the endpoint to proxy allowlists.","Check OpenAI status pages for an ongoing auth incident before deeper debugging."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check token endpoint reachability/latency\nconst start = Date.now();\nconst res = await fetch('https://auth.openai.com/.well-known/openid-configuration', { signal: AbortSignal.timeout(5000) }).catch(() => null);\nif (!res) throw new Error('OpenAI auth endpoint unreachable; fix network before login.');","typeGuard":null,"tryCatchPattern":"try {\n  await refreshToken(refreshToken);\n} catch (e) {\n  if (e instanceof Error && /timed out$/.test(e.message)) {\n    await sleep(2000);\n    return refreshToken(refreshToken); // bounded retry with backoff\n  }\n  throw e;\n}","preventionTips":["Ensure the host has low-latency egress to auth.openai.com.","Allowlist the OpenAI auth endpoints on corporate proxies to avoid stalls.","Monitor OpenAI status during incident windows.","Keep the 30s ceiling; don't remove it — it prevents stuck pending logins."],"tags":["network","timeout","oauth","openai"],"backgroundTag":"request-timeout","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}