{"record":{"id":"a119c4fbed009412","repo":"nexu-io/open-design","slug":"vela-login-already-running","errorCode":null,"errorMessage":"vela login already running","messagePattern":"vela login already running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/daemon/src/integrations/vela.ts","lineNumber":1011,"sourceCode":"  if (!input || typeof input !== 'object' || Array.isArray(input)) return null;\n  const value = (input as { authAttemptId?: unknown }).authAttemptId;\n  return isCanonicalAmrAuthAttemptId(value) ? value : null;\n}\n\nexport function parseVelaAuthRequestId(input: unknown): string | null {\n  if (!input || typeof input !== 'object' || Array.isArray(input)) return null;\n  const value = (input as { authRequestId?: unknown }).authRequestId;\n  return typeof value === 'string'\n    && /^pending-amr-auth-[a-z0-9]+-[a-z0-9]+$/.test(value)\n    ? value\n    : null;\n}\n\nfunction beginVelaLoginAttempt(\n  authAttemptId?: string | null,\n  authRequestId?: string | null,\n): VelaLoginAttemptRef {\n  if (isVelaLoginInFlight()) throw new Error('vela login already running');\n  const attempt: VelaLoginAttemptState = {\n    authAttemptId: isCanonicalAmrAuthAttemptId(authAttemptId)\n      ? authAttemptId\n      : randomUUID(),\n    ...(authRequestId ? { authRequestId } : {}),\n    generation: ++loginGeneration,\n    canceled: false,\n    fallbackPending: false,\n    fallbackStarted: false,\n    currentPid: null,\n    route: 'direct',\n    fallbackUsed: false,\n    stages: [],\n  };\n  latestLoginAttempt = attempt;\n  recordVelaAuthStage(\n    attempt,\n    { stage: 'attempt_started', result: 'started' },","sourceCodeStart":993,"sourceCodeEnd":1029,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/integrations/vela.ts#L993-L1029","documentation":"Single-flight guard in beginVelaLoginAttempt(): it refuses to start a new login if isVelaLoginInFlight() is true, i.e. there is a running login child process or a pending non-canceled fallback. The vela login flow is designed around one supervised attempt at a time keyed by an authAttemptId/generation pair.","triggerScenarios":"A second login request arrives while the first is still spawning/running or while its proxy fallback is pending. Common from double-clicks on the login button, two browser tabs, or a retry that did not wait for cancelVelaLogin to settle.","commonSituations":"UI 'Sign in' clicked twice; concurrent tabs/clients both driving /api login; a previous login hung on a transparent-proxy network and the user retried without cancelling; test that starts a second attempt without resetting the supervisor.","solutions":["Call cancelVelaLogin() (with the expected attempt ids) and wait until isVelaLoginSupervisorSettled() before starting a new attempt.","Disable the login button while isVelaLoginInFlight() is true.","Reuse the in-flight attempt's authAttemptId/authRequestId via readVelaLoginAttemptSnapshot() instead of starting a duplicate."],"exampleFix":"// before\nconst attempt = beginVelaLoginAttempt(authAttemptId, authRequestId);\n\n// after\nif (isVelaLoginInFlight()) {\n  cancelVelaLogin();\n  await waitFor(() => isVelaLoginSupervisorSettled());\n}\nconst attempt = beginVelaLoginAttempt(authAttemptId, authRequestId);","handlingStrategy":"validation","validationCode":"import { isVelaLoginInFlight, isVelaLoginSupervisorSettled, cancelVelaLogin } from '../integrations/vela.js';\n\nasync function ensureIdleBeforeLogin(): Promise<void> {\n  if (!isVelaLoginInFlight()) return;\n  cancelVelaLogin();\n  // wait for the supervisor to settle (no pending fallback, all children closed)\n  while (!isVelaLoginSupervisorSettled()) {\n    await new Promise((r) => setTimeout(r, 20));\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return beginVelaLoginAttempt(authAttemptId, authRequestId);\n} catch (err) {\n  if (err instanceof Error && err.message === 'vela login already running') {\n    return { kind: 'already_running', snapshot: readVelaLoginAttemptSnapshot() };\n  }\n  throw err;\n}","preventionTips":["Disable the login button while isVelaLoginInFlight() is true.","Call cancelVelaLogin() and wait for isVelaLoginSupervisorSettled() before retrying.","Reuse the in-flight attempt's snapshot instead of starting a duplicate."],"tags":["concurrency","login","integration","vela"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}