{"record":{"id":"9f79eb304b23aac9","repo":"can1357/oh-my-pi","slug":"smithery-login-session-expired-please-try-again","errorCode":null,"errorMessage":"Smithery login session expired. Please try again.","messagePattern":"Smithery login session expired\\. Please try again\\.","errorType":"exception","errorClass":"Error","httpStatus":404,"severity":"error","filePath":"packages/coding-agent/src/mcp/smithery-auth.ts","lineNumber":61,"sourceCode":"\t\tmethod: \"POST\",\n\t\tsignal: withTimeoutSignal(SMITHERY_AUTH_TIMEOUT_MS),\n\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;","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/mcp/smithery-auth.ts#L43-L79","documentation":"Thrown by pollSmitheryCliAuthSession when the poll endpoint answers 404 or 410, meaning the CLI login session no longer exists on the server — it expired or was consumed. The user must restart the login flow from scratch; retrying the poll will keep failing.","triggerScenarios":"Polling a Smithery CLI auth session whose sessionId the server no longer recognizes: session TTL elapsed before the user completed browser login, or the session was already finalized.","commonSituations":"User took too long to approve the login in the browser (past the session TTL), user completed login in a different window and the session was consumed, machine slept during the login wait.","solutions":["Restart the Smithery login command to get a fresh session and complete the browser step promptly","Complete the browser approval quickly after starting login — sessions are short-lived","Avoid suspending/sleeping the machine during the login flow","If it keeps happening immediately, check clock skew (system clock far off can invalidate sessions)"],"exampleFix":"// before: retrying the same expired session\nawait pollSmitheryCliAuthSession(sessionId); // keeps throwing\n// after: start a new session on expiry\ntry {\n  await pollSmitheryCliAuthSession(sessionId);\n} catch (e) {\n  if (String(e.message).includes(\"expired\")) await restartSmitheryLogin();\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":"// track session age and abandon before polling an obviously expired session\nconst sessionAge = Date.now() - session.createdAt;\nif (sessionAge > SESSION_TTL_MS) {\n  session = await createSmitheryCliAuthSession(); // fresh session instead of stale poll\n}","typeGuard":"function isSessionExpired(err: unknown): boolean {\n  return err instanceof Error && err.message.includes(\"Smithery login session expired\");\n}","tryCatchPattern":"try {\n  const res = await pollSmitheryCliAuthSession(sessionId, signal);\n} catch (err) {\n  if (isSessionExpired(err)) {\n    sessionId = (await createSmitheryCliAuthSession()).sessionId; // restart login\n  } else throw err;\n}","preventionTips":["Complete the browser approval promptly after starting login","Keep the machine awake during interactive login flows","Wrap the whole login (session creation + polling) in one retryable operation so expiry restarts cleanly","Check NTP/clock sync if sessions seem to expire instantly"],"tags":["smithery","auth","session-expired","timeout"],"backgroundTag":"auth-session-expired","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}