Cannot cancel the browser OAuth wait on the MCP connect modal
Summary
On the MCP connect modal (ConnectAuthModal), after starting browser OAuth ("Sign in with browser"), there is no way to cancel — the modal is stuck in "Waiting for sign-in…" until the poll times out, ~3 minutes later.
Problem
The browser-OAuth flow polls /oauth/mcp/callback for up to 3 minutes via a recursive setTimeout. During that wait the modal is busy, and every dismissal path — the Cancel button, and the backdrop click — is gated on busy. So a user who starts the sign-in and then abandons it in the browser (closes the tab, changes their mind, picks the wrong account) is trapped in the modal with no way out until the 180s timeout fires.
Starting the browser sign-in is not a committed action — it can be abandoned — so the wait should be abortable.
- Platform: desktop.
- File:
app/src/components/channels/mcp/ConnectAuthModal.tsx.
Solution (optional)
Make the wait abortable: track the pending poll setTimeout and a "cancelled" flag so Cancel / backdrop can stop the pending tick and bail any in-flight request, reset busy/waiting, and drop the timer on unmount. Enable Cancel and backdrop-dismiss during the wait.
Acceptance criteria
- [ ] Cancel (and backdrop click) close the modal while it is waiting on the OAuth sign-in
- [ ] The pending poll stops and does not fire state updates after close/unmount
- [ ] Idle-state dismissal behavior is unchanged
- [ ] Diff coverage ≥ 80% — the fix meets the changed-lines coverage gate (Vitest, enforced by
.github/workflows/ci-lite.yml).
Related
Fix is ready on the same fork branch as the custom-servers feature; the PR closes both.
Implementation Plan
Triage Assessment
- Valid bug: users are trapped in the MCP OAuth modal for up to 3 minutes after starting browser sign-in with no way to abort. The Cancel button and backdrop click are both disabled during the wait.
- Medium user impact: the MCP connection flow has a poor UX failure mode — starting browser OAuth is reversible/abandonable but the UI does not reflect that.
- Not a duplicate: no other open issue describes this specific UX bug. The fix is ready in PR #5033 (same branch as the custom MCP servers feature) and addresses the problem by making the poll abortable.
Proposed Scope
- Single React component:
app/src/components/channels/mcp/ConnectAuthModal.tsx. - Core behavior: make the recursive
setTimeoutpoll abortable via a cancellation flag + timer ref; enable Cancel button and backdrop-dismiss during the OAuth wait; drop timer on unmount.
Implementation Steps
- Add a
useReffor the pending pollsetTimeoutand acancelledreactive flag inConnectAuthModal.tsx. - Guard each poll tick to check the cancelled flag before proceeding; clear the timer on cancellation.
- Remove the
busygate on Cancel/backdrop dismissal during the OAuth wait (idle-state dismissal behavior unchanged). - Add a
useEffectcleanup that cancels on unmount. - Add Vitest tests for the abortable flow.
Verification
- Vitest tests for
ConnectAuthModal.tsx— verify cancel during wait stops poll, backdrop dismiss works, idle behavior unchanged. - Manual: connect OAuth MCP server, start sign-in, cancel mid-wait — modal closes immediately.
Risks and Open Questions
- None identified — the change is scoped to a single component and the fix is already implemented on the feature branch.
Acceptance Criteria
- As listed in the issue body (four acceptance checkboxes).
Verified — still reproduces on main (6be58a9ab), and PR #5033 has drifted from the file it patches
The bug is exactly as described. In app/src/components/channels/mcp/ConnectAuthModal.tsx:
Every dismissal path is gated on busy — line 491:
closePolicy={{ backdrop: !busy, escape: !busy, button: !busy }}
and line 494:
<Button variant="secondary" size="sm" onClick={onClose} disabled={busy}>
{t('common.cancel')}
</Button>
The wait is 180s and unabortable — lines 290-306:
const started = Date.now();
const poll = async (): Promise<void> => {
const statuses = await mcpClientsApi.status();
const mine = statuses.find(s => s.server_id === server.server_id);
if (mine?.status === 'connected') { … return; }
if (Date.now() - started > 180000) {
throw new Error(t('mcp.connectAuth.oauthTimeout'));
}
window.setTimeout(() => { void poll().catch(handlePollError); }, 2500);
};
The setTimeout handle is never stored, so there is nothing to clear, and this effect has no cancellation flag — the two cancelled flags in the file (lines 265 and 327) belong to the authKind fetch and the registryGet effect, not to this poll. A user who abandons the browser sign-in is held for up to three minutes and the poll keeps firing after unmount.
One thing changed since this was filed, and it affects the fix
The modal gained an Escape path. When #5032 was written the dismissal was a manual backdrop handler; main now routes all three through the shared closePolicy prop. So the trap is now wider than the issue describes — acceptance criterion 1 mentions Cancel and backdrop, but Escape is trapped too, on the same !busy gate.
PR #5033 still patches the old shape. Its hunk is:
onMouseDown={e => {
- if (e.target === e.currentTarget && !busy) onClose();
+ if (e.target === e.currentTarget && (!busy || oauthWaiting)) handleClose();
}}
That onMouseDown backdrop handler no longer exists on main — grep -n "currentTarget" ConnectAuthModal.tsx returns nothing. The hunk will conflict on rebase, and resolving it by taking the PR's side reintroduces a handler that duplicates closePolicy. The correct port is to widen the policy itself:
closePolicy={{
backdrop: !busy || oauthWaiting,
escape: !busy || oauthWaiting,
button: !busy || oauthWaiting,
}}
Everything else in the PR is the right shape and applies cleanly — oauthPollTimer ref, cancelOAuthWait(), window.clearTimeout(oauthPollTimer.current), the unmount cleanup useEffect(() => () => cancelOAuthWait(), [cancelOAuthWait]), and disabled={busy && !oauthWaiting} on Cancel. It also ships 74 lines of ConnectAuthModal.test.tsx, which should cover acceptance criterion 4 (diff coverage ≥ 80%).
Status
PR #5033 is open (not draft) and unmerged; it is nearly two months old, which is where the drift comes from. Recommend a rebase with the closePolicy port above before merge, and adding Escape to acceptance criterion 1 so the rebase doesn't quietly leave one of the three paths trapped.
Leaving open.