{"record":{"id":"9dbd0841b05af57d","repo":"nexu-io/open-design","slug":"vela-login-attempt-is-no-longer-active","errorCode":null,"errorMessage":"vela login attempt is no longer active","messagePattern":"vela login attempt is no longer active","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/daemon/src/integrations/vela.ts","lineNumber":1165,"sourceCode":"    throw new Error(`vela login failed to start: ${result.error.message}`);\n  }\n  const detail = (capture.stderr || capture.stdout).trim();\n  throw new Error(\n    detail ||\n      `vela login exited before device authorization started (code ${result.code ?? 'null'}, signal ${result.signal ?? 'null'})`,\n  );\n}\n\ninterface SpawnVelaLoginAttemptDeps extends SpawnVelaLoginDeps {\n  attempt: VelaLoginAttemptRef;\n  onLatePreActivationFailure?: () => Promise<void>;\n}\n\nasync function spawnVelaLoginAttempt(\n  deps: SpawnVelaLoginAttemptDeps,\n): Promise<SpawnedVelaLogin> {\n  const attemptState = currentVelaLoginAttempt(deps.attempt);\n  if (!attemptState) throw new Error('vela login attempt is no longer active');\n  if (hasRunningVelaLoginChild()) throw new Error('vela login already running');\n  const def = getAgentDef('amr');\n  if (!def) {\n    recordVelaAuthStage(\n      deps.attempt,\n      { stage: 'spawn_result', result: 'failed', errorKind: 'internal_error' },\n      'daemon',\n    );\n    throw new Error('AMR runtime def not registered');\n  }\n  const baseEnv = deps.baseEnv ?? process.env;\n  const configuredEnv = withDefaultVelaApiUrl(\n    deps.configuredEnv ?? {},\n    baseEnv,\n    deps.defaultApiUrl,\n  );\n  const launch = resolveAgentLaunch(def, configuredEnv);\n  const bin = launch.selectedPath;","sourceCodeStart":1147,"sourceCodeEnd":1183,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/integrations/vela.ts#L1147-L1183","documentation":"Raised at the top of spawnVelaLoginAttempt() when currentVelaLoginAttempt(deps.attempt) returns null. That helper returns null when the attempt was canceled, superseded by a newer generation, or its authAttemptId/generation no longer matches latestLoginAttempt. It is a cancellation/supersession guard, not a spawn failure.","triggerScenarios":"Between beginVelaLoginAttempt() and spawnVelaLoginAttempt(), cancelVelaLogin() ran (or a newer attempt bumped loginGeneration), so the spawn refuses to start a now-stale child. Also happens if the attempt ref was constructed manually with a wrong generation.","commonSituations":"User cancels login while the spawn is being prepared; a new login bumps the generation; proxy fallback tries to spawn after the direct attempt was canceled; test fixture passes a stale attempt ref.","solutions":["Treat this as 'login canceled' rather than a hard error — surface cancellation to the user and stop the flow.","Do not reuse an attempt ref across cancel boundaries; call beginVelaLoginAttempt() to get a fresh generation.","Before spawning, check currentVelaLoginAttempt(attempt) !== null and skip spawn if null."],"exampleFix":"// before\nconst attemptState = currentVelaLoginAttempt(deps.attempt);\nif (!attemptState) throw new Error('vela login attempt is no longer active');\n\n// after\nconst attemptState = currentVelaLoginAttempt(deps.attempt);\nif (!attemptState) {\n  return { kind: 'canceled' } as const;\n}","handlingStrategy":"validation","validationCode":"import { currentVelaLoginAttempt } from '../integrations/vela.js';\n\nfunction isAttemptStillActive(ref: VelaLoginAttemptRef): boolean {\n  return currentVelaLoginAttempt(ref) !== null;\n}\n\n// usage right before spawn\nif (!isAttemptStillActive(deps.attempt)) {\n  return { kind: 'canceled' };\n}","typeGuard":"function isLoginNoLongerActive(err: unknown): boolean {\n  return err instanceof Error && err.message === 'vela login attempt is no longer active';\n}","tryCatchPattern":"try {\n  return await spawnVelaLoginAttempt(deps);\n} catch (err) {\n  if (err instanceof Error && err.message === 'vela login attempt is no longer active') {\n    return { kind: 'canceled' };\n  }\n  throw err;\n}","preventionTips":["Never reuse an attempt ref across cancel boundaries — call beginVelaLoginAttempt() for a fresh generation.","Treat this throw as 'canceled', not a hard failure.","Avoid launching the proxy fallback after the direct attempt was canceled."],"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"}