tinyhumansai/openhuman · info

OpenRouter OAuth was cancelled.

Error message

OpenRouter OAuth was cancelled.

What it means

Pre-flight cancellation check in connectOpenRouterViaOAuth: immediately after the loopback listener binds, the function inspects deps.signal?.aborted and, if the caller already aborted, cancels the listener and throws. It represents an expected control-flow exit — the user (or component teardown) cancelled the OAuth attempt before the external browser was opened.

Solutions

  1. Treat this as expected cancellation, not an error: catch it and show a neutral 'cancelled' state instead of an error banner or Sentry report
  2. Don't abort on mere unmount if the sign-in should survive navigation — abort only on explicit user cancel
  3. Create one AbortController per flow attempt and never reuse it after abort
  4. Check `signal.aborted` before even starting the flow to avoid binding then immediately tearing down the listener

Example fix

// before
useEffect(() => {
  const ctrl = new AbortController();
  connectOpenRouterViaOAuth({ signal: ctrl.signal }).catch(reportError);
  return () => ctrl.abort();
}, []);

// after
useEffect(() => {
  const ctrl = new AbortController();
  connectOpenRouterViaOAuth({ signal: ctrl.signal }).catch(err => {
    if (err instanceof Error && err.message.includes('cancelled')) return; // expected
    reportError(err);
  });
  return () => ctrl.abort();
}, []);
Defensive patterns

Strategy: try-catch

Validate before calling

if (signal?.aborted) {
  return; // don't even bind the loopback listener
}
const key = await connectOpenRouterViaOAuth({ signal });

Try / catch

try {
  const key = await connectOpenRouterViaOAuth({ signal: ctrl.signal });
} catch (err) {
  if (err instanceof Error && err.message.includes('cancelled')) {
    setCancelledState(); // expected control flow — no error UI, no Sentry
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: An AbortController tied to the flow is aborted between calling connectOpenRouterViaOAuth and the listener binding completing — user closes the sign-in dialog instantly, the component unmounts (React StrictMode double-mount cleanup) and its effect aborts, or an overall timeout signal fires.

Common situations: React effects that create an AbortController per mount and abort on cleanup; StrictMode's mount/unmount/mount cycle in dev; a race between the user hitting Cancel and the listener binding; tests that abort the signal before awaiting.

Related errors


AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17). Data as JSON: /api/errors/4119e6a278f0d36a. Report an issue: GitHub.

Appendix: source

Thrown at app/src/utils/openrouterOAuth.ts:131

  // sibling OAuthProviderButton flow, which trusts the bound port).
  parsed.hostname = 'localhost';
  return parsed.toString();
}

export async function connectOpenRouterViaOAuth(deps: OpenRouterOAuthDeps = {}): Promise<string> {
  const startLoopbackListener = deps.startLoopbackListener ?? startLoopbackOauthListener;
  const openExternalUrl = deps.openExternalUrl ?? openUrl;
  const fetchImpl = deps.fetchImpl ?? fetch;
  const signal = deps.signal;

  const loopback = await startLoopbackListener({ port: OPENROUTER_LOOPBACK_PORT });
  if (!loopback) {
    throw new Error('OpenRouter OAuth requires the desktop app. Use an API key instead.');
  }

  if (signal?.aborted) {
    await loopback.cancel();
    throw new Error('OpenRouter OAuth was cancelled.');
  }

  const verifier = randomVerifier();
  const challenge = await createCodeChallenge(verifier);
  const authUrl = new URL(OPENROUTER_AUTH_URL);
  authUrl.searchParams.set('callback_url', toOpenRouterCallbackUrl(loopback.redirectUri));
  authUrl.searchParams.set('code_challenge', challenge);
  authUrl.searchParams.set('code_challenge_method', PKCE_METHOD);

  try {
    await openExternalUrl(authUrl.toString());
    const callbackUrl = await Promise.race([
      loopback.awaitCallback(),
      new Promise<string>((_, reject) => {
        if (!signal) return;
        const onAbort = () => {
          signal.removeEventListener('abort', onAbort);
          reject(new Error('OpenRouter OAuth was cancelled.'));

View on GitHub (pinned to 7491200858)