{"record":{"id":"46c05860981cdc58","repo":"different-ai/openwork","slug":"the-active-openwork-cloud-account-changed-while-re","errorCode":null,"errorMessage":"The active OpenWork Cloud account changed while reconnecting. Try again in this workspace.","messagePattern":"The active OpenWork Cloud account changed while reconnecting\\. Try again in this workspace\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/react-app/domains/session/surface/mcp-chat-reconnect.ts","lineNumber":50,"sourceCode":"  connectionId: string\n  connectionName: string\n  previousConnectedAt: string | null\n  listConnections: () => Promise<DenExternalMcpConnection[]>\n  isScopeCurrent: () => boolean\n  timeoutMs?: number\n  intervalMs?: number\n  now?: () => number\n  sleep?: (milliseconds: number) => Promise<void>\n}): Promise<DenExternalMcpConnection> {\n  const timeoutMs = input.timeoutMs ?? CHAT_MCP_RECONNECT_TIMEOUT_MS\n  const intervalMs = input.intervalMs ?? CHAT_MCP_RECONNECT_POLL_INTERVAL_MS\n  const now = input.now ?? Date.now\n  const sleep = input.sleep ?? ((milliseconds) => new Promise((resolve) => window.setTimeout(resolve, milliseconds)))\n  const startedAt = now()\n\n  while (now() - startedAt < timeoutMs) {\n    if (!input.isScopeCurrent()) {\n      throw new Error(\"The active OpenWork Cloud account changed while reconnecting. Try again in this workspace.\")\n    }\n    try {\n      const connections = await input.listConnections()\n      if (!input.isScopeCurrent()) {\n        throw new Error(\"The active OpenWork Cloud account changed while reconnecting. Try again in this workspace.\")\n      }\n      const connection = connections.find((entry) => entry.id === input.connectionId)\n      if (connection && hasFreshMcpAuthorization(connection, input.previousConnectedAt)) return connection\n    } catch (error) {\n      if (error instanceof Error && error.message.startsWith(\"The active OpenWork Cloud account changed\")) throw error\n      // A transient list failure should not turn a successful browser callback\n      // into a false failure. Keep polling until the bounded timeout.\n    }\n    await sleep(intervalMs)\n  }\n\n  throw new Error(`Authorization for ${input.connectionName} did not finish. Complete it in the browser, then try reconnecting again.`)\n}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/session/surface/mcp-chat-reconnect.ts#L32-L68","documentation":"waitForFreshMcpAuthorization polls for a freshly authorized MCP connection after a browser OAuth callback. Before each poll (and after the async listConnections await) it re-checks isScopeCurrent(); if the active OpenWork Cloud account changed mid-reconnect, continuing could attach the new account's connections to the old scope, so it throws immediately. This is a stale-scope guard, not an auth failure.","triggerScenarios":"During the reconnect polling loop, the user (or another tab/window) signs out or switches the active cloud account, making isScopeCurrent() false either right before a poll iteration or after the awaited listConnections call resolves.","commonSituations":"User switches accounts in another tab while waiting for the OAuth browser flow; session restored in a different profile; automated account switching during long-running reconnects.","solutions":["Retry the reconnect from scratch in the (now current) workspace, as the message advises — the poll state is bound to the previous account.","Ensure only one cloud account session is active, or complete the OAuth flow without switching accounts mid-way.","If this happens without any user action, check for multiple tabs/windows sharing the account store and triggering account refreshes."],"exampleFix":"// before\nconst connection = await handleMcpReconnect(input); // throws if account flips\n// after\ntry {\n  const connection = await handleMcpReconnect(input);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"active OpenWork Cloud account changed\")) {\n    showToast(\"Account changed — press Reconnect again\");\n    return;\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"if (!input.isScopeCurrent()) {\n  showToast(\"Account changed — restart the reconnect\");\n  return;\n}\nawait handleMcpReconnect(input);","typeGuard":"function isScopeChangedError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith(\"The active OpenWork Cloud account changed\");\n}","tryCatchPattern":"try {\n  await handleMcpReconnect(input);\n} catch (e) {\n  if (isScopeChangedError(e)) {\n    showToast(\"Account changed — press Reconnect again\");\n    return; // do not blanket-retry: scope is stale\n  }\n  throw e;\n}","preventionTips":["Don't switch or sign out of cloud accounts while an OAuth reconnect is pending.","Close duplicate tabs that share the account store during auth flows.","Treat this error as restart-the-flow, not retry-in-place — the poller's scope is permanently stale."],"tags":["oauth","race-condition","account-scope"],"backgroundTag":"oauth-scope-changed-mid-flow","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}