{"record":{"id":"964fe5e97430e965","repo":"different-ai/openwork","slug":"failed-to-sign-in-to-openwork-cloud","errorCode":null,"errorMessage":"Failed to sign in to OpenWork Cloud.","messagePattern":"Failed to sign in to OpenWork Cloud\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/app/lib/den-handoff.ts","lineNumber":80,"sourceCode":"  grant: string,\n  options: ExchangeHandoffOptions,\n): Promise<ExchangeHandoffResult> {\n  const fallback = options.fallbackErrorMessage ?? \"Failed to sign in to OpenWork Cloud.\";\n  const storedSettings = readDenSettings();\n  const apiBaseUrl = options.apiBaseUrl ?? (\n    storedSettings.baseUrl === resolveDenBaseUrls(options.baseUrl).baseUrl\n      ? storedSettings.apiBaseUrl\n      : undefined\n  );\n  const client = options.client ?? createDenClient({\n    baseUrl: options.baseUrl,\n    apiBaseUrl,\n  });\n\n  try {\n    const exchange = await client.exchangeDesktopHandoff(grant);\n    if (!exchange.token) {\n      throw new Error(fallback);\n    }\n\n    if (typeof window !== \"undefined\") {\n      try {\n        window.sessionStorage.setItem(DEN_HANDOFF_AUTO_CONTINUE_KEY, String(Date.now()));\n      } catch {}\n    }\n    const desktopInitiated = options.desktopInitiated ?? hasActiveDesktopSignInIntent();\n    clearDesktopSignInIntent();\n    const plan = resolveHandoffOrgPlan({\n      explicitActiveOrg: options.activeOrg ?? null,\n      exchangeOrganization: exchange.organization ?? null,\n      desktopInitiated,\n    });\n    if (plan.kind === \"await-user-selection\") {\n      // Desktop-initiated sign-in: hold the org choice for the onboarding\n      // step. The exchange-reported org is only the chooser's default;\n      // single-org accounts still auto-select there without a visible stop.","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/den-handoff.ts#L62-L98","documentation":"exchangeHandoffAndSignIn exchanges a one-time desktop handoff grant for a Den session. After the exchange succeeds, it requires the result to contain a session token; if exchange.token is falsy it throws the fallback Error \"Failed to sign in to OpenWork Cloud.\". This is the generic sign-in failure surfaced when no more specific error message was provided or produced.","triggerScenarios":"client.exchangeDesktopHandoff(grant) resolves successfully but the returned DenDesktopHandoffExchange has no token — e.g. the server accepted the request but did not issue a session.","commonSituations":"A stale or already-consumed handoff grant that the server resolves without a token, a misconfigured Den server returning an unexpected payload shape, or testing with a mock client that omits token.","solutions":["Verify the handoff grant is fresh and single-use; restart the sign-in flow to mint a new grant","Check the Den server is healthy and returns a token in the desktop-handoff exchange response","Provide options.fallbackErrorMessage for a more specific message and inspect the original cause in logs","Retry the whole handoff (deep link or paste) from the browser flow"],"exampleFix":"// before\nconst result = await exchangeHandoffAndSignIn(consumedGrant, { baseUrl });\n// after\nconst result = await exchangeHandoffAndSignIn(consumedGrant, { baseUrl, fallbackErrorMessage: `Cloud sign-in failed (grant ${consumedGrant.slice(0, 6)}…)` });\nif (!result.ok) console.error(result.error);","handlingStrategy":"try-catch","validationCode":"if (typeof grant !== \"string\" || grant.length === 0) throw new Error(\"A handoff grant is required before sign-in\");","typeGuard":"const hasSessionToken = (x: DenDesktopHandoffExchange): x is DenDesktopHandoffExchange & { token: string } =>\n  typeof x.token === \"string\" && x.token.length > 0;","tryCatchPattern":"const result = await exchangeHandoffAndSignIn(grant, { baseUrl });\nif (!result.ok) {\n  console.error(\"Cloud sign-in failed:\", result.error);\n  showSignInRetryDialog(result.error);\n}","preventionTips":["Always use a freshly minted handoff grant; never reuse a consumed one","Handle the { ok: false, error } result instead of assuming success","Keep the browser sign-in window open until the exchange completes","Provide fallbackErrorMessage for context in logs"],"tags":["auth","sign-in","handoff","den-cloud"],"backgroundTag":"cloud-sign-in-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}