{"record":{"id":"5b2674dc7f7375f2","repo":"can1357/oh-my-pi","slug":"smithery-auth-polling-failed-response-status","errorCode":null,"errorMessage":"Smithery auth polling failed: ${response.status} ${response.statusText}","messagePattern":"Smithery auth polling failed: (.+?) (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/mcp/smithery-auth.ts","lineNumber":63,"sourceCode":"\t});\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to create Smithery auth session: ${response.status} ${response.statusText}`);\n\t}\n\treturn (await response.json()) as SmitheryCliAuthSession;\n}\n\nexport async function pollSmitheryCliAuthSession(\n\tsessionId: string,\n\tsignal?: AbortSignal,\n): Promise<SmitheryCliPollResponse> {\n\tconst response = await fetch(`${SMITHERY_URL}/api/auth/cli/poll/${sessionId}`, {\n\t\tsignal: withTimeoutSignal(SMITHERY_POLL_TIMEOUT_MS, signal),\n\t});\n\tif (!response.ok) {\n\t\tif (response.status === 404 || response.status === 410) {\n\t\t\tthrow new Error(\"Smithery login session expired. Please try again.\");\n\t\t}\n\t\tthrow new Error(`Smithery auth polling failed: ${response.status} ${response.statusText}`);\n\t}\n\treturn (await response.json()) as SmitheryCliPollResponse;\n}\n\nexport async function getSmitheryApiKey(): Promise<string | undefined> {\n\tconst envKey = normalizeApiKey(process.env.SMITHERY_API_KEY);\n\tif (envKey) return envKey;\n\n\tconst authPath = getSmitheryAuthPath();\n\ttry {\n\t\tconst payload = (await Bun.file(authPath).json()) as SmitheryAuthPayload;\n\t\treturn normalizeApiKey(payload.apiKey);\n\t} catch (error) {\n\t\tif (isEnoent(error)) return undefined;\n\t\tlogger.warn(\"Failed to read Smithery auth file, treating as missing\", { path: authPath, error });\n\t\treturn undefined;\n\t}\n}","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/mcp/smithery-auth.ts#L45-L81","documentation":"Generic failure thrown by pollSmitheryCliAuthSession when the poll endpoint returns a non-OK status other than 404/410 (those are reported as session-expired instead). Includes status code and statusText, e.g. 500 on a Smithery server error or 429 when rate limited.","triggerScenarios":"Calling pollSmitheryCliAuthSession and receiving 429 (polling too aggressively), 5xx (Smithery server error), 401/403, or any other unexpected non-OK status.","commonSituations":"Smithery service outage or degradation, tight polling loops triggering rate limits, intermediary proxies returning error pages.","solutions":["Check the status in the message: 5xx means wait and retry; 429 means slow down polling","Retry the login flow after a short backoff","Check Smithery status page / network connectivity if errors persist","Fall back to manual API key entry from the Smithery dashboard"],"exampleFix":"// before: tight polling loop without backoff\nwhile (!done) await pollSmitheryCliAuthSession(id);\n// after: backoff between polls\nwhile (!done) {\n  await pollSmitheryCliAuthSession(id);\n  await Bun.sleep(pollIntervalMs);\n  pollIntervalMs = Math.min(pollIntervalMs * 2, 10000);\n}","handlingStrategy":"retry","validationCode":"// check reachability before starting the poll loop\nconst ok = await fetch(`${smitheryUrl}/api/health`, { signal: AbortSignal.timeout(5000) }).then(r => r.ok).catch(() => false);\nif (!ok) throw new Error(\"Smithery API unreachable\");","typeGuard":"function isPollFailure(err: unknown): err is Error {\n  return err instanceof Error && err.message.startsWith(\"Smithery auth polling failed:\");\n}","tryCatchPattern":"try {\n  const res = await pollSmitheryCliAuthSession(sessionId, signal);\n} catch (err) {\n  if (isPollFailure(err) && /5\\d\\d/.test(err.message)) {\n    await Bun.sleep(backoffMs);\n    return pollWithBackoff(); // retry on server errors only\n  }\n  throw err;\n}","preventionTips":["Poll with exponential backoff, not a tight loop, to avoid 429s","Only retry on 5xx/429; 4xx statuses other than expiry should surface to the user","Respect the poll interval returned by the session creation response if provided","Monitor Smithery status before automating logins in CI"],"tags":["network","http","smithery","auth"],"backgroundTag":"http-request-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}