different-ai/openwork · error
The active OpenWork Cloud account changed while reconnecting
Error message
The active OpenWork Cloud account changed while reconnecting. Try again in this workspace.
What it means
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.
Source
Thrown at apps/app/src/react-app/domains/session/surface/mcp-chat-reconnect.ts:50
connectionId: string
connectionName: string
previousConnectedAt: string | null
listConnections: () => Promise<DenExternalMcpConnection[]>
isScopeCurrent: () => boolean
timeoutMs?: number
intervalMs?: number
now?: () => number
sleep?: (milliseconds: number) => Promise<void>
}): Promise<DenExternalMcpConnection> {
const timeoutMs = input.timeoutMs ?? CHAT_MCP_RECONNECT_TIMEOUT_MS
const intervalMs = input.intervalMs ?? CHAT_MCP_RECONNECT_POLL_INTERVAL_MS
const now = input.now ?? Date.now
const sleep = input.sleep ?? ((milliseconds) => new Promise((resolve) => window.setTimeout(resolve, milliseconds)))
const startedAt = now()
while (now() - startedAt < timeoutMs) {
if (!input.isScopeCurrent()) {
throw new Error("The active OpenWork Cloud account changed while reconnecting. Try again in this workspace.")
}
try {
const connections = await input.listConnections()
if (!input.isScopeCurrent()) {
throw new Error("The active OpenWork Cloud account changed while reconnecting. Try again in this workspace.")
}
const connection = connections.find((entry) => entry.id === input.connectionId)
if (connection && hasFreshMcpAuthorization(connection, input.previousConnectedAt)) return connection
} catch (error) {
if (error instanceof Error && error.message.startsWith("The active OpenWork Cloud account changed")) throw error
// A transient list failure should not turn a successful browser callback
// into a false failure. Keep polling until the bounded timeout.
}
await sleep(intervalMs)
}
throw new Error(`Authorization for ${input.connectionName} did not finish. Complete it in the browser, then try reconnecting again.`)
}View on GitHub (pinned to 2b7df46e8a)
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.
Example fix
// before
const connection = await handleMcpReconnect(input); // throws if account flips
// after
try {
const connection = await handleMcpReconnect(input);
} catch (e) {
if (e instanceof Error && e.message.includes("active OpenWork Cloud account changed")) {
showToast("Account changed — press Reconnect again");
return;
}
throw e;
} Defensive patterns
Strategy: retry
Validate before calling
if (!input.isScopeCurrent()) {
showToast("Account changed — restart the reconnect");
return;
}
await handleMcpReconnect(input); Type guard
function isScopeChangedError(e: unknown): e is Error {
return e instanceof Error && e.message.startsWith("The active OpenWork Cloud account changed");
} Try / catch
try {
await handleMcpReconnect(input);
} catch (e) {
if (isScopeChangedError(e)) {
showToast("Account changed — press Reconnect again");
return; // do not blanket-retry: scope is stale
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- MCP_OAUTH_AUTHORIZATION_CLIENT_CHANGED
- `${t("providers.no_oauth_prefix")} ${resolved}. ${t("provide
- `${t("providers.not_oauth_flow_prefix")} ${resolved}.`
- t("providers.oauth_method_required")
- OpenWork-managed MCP OAuth is currently available for local
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/46c05860981cdc58.
Report an issue: GitHub.