Skip to content

fix: prevent OAuth race condition causing auth failures#70

Merged
steipete merged 2 commits into
openclaw:mainfrom
monotykamary:fix/oauth-race-condition
Mar 2, 2026
Merged

fix: prevent OAuth race condition causing auth failures#70
steipete merged 2 commits into
openclaw:mainfrom
monotykamary:fix/oauth-race-condition

Conversation

@monotykamary
Copy link
Copy Markdown
Contributor

@monotykamary monotykamary commented Feb 15, 2026

Summary

Fixes a race condition in the OAuth authorization flow that caused authentication to fail with a timeout error.

Problem

When authenticating with OAuth-based MCP servers (like Linear), waitForAuthorizationCode() was creating a new deferred promise if one didn't exist. However, redirectToAuthorization() also creates a new deferred. If the SDK's OAuth flow called waitForAuthorizationCode() before redirectToAuthorization() completed, they would wait on different deferreds, causing the OAuth callback to resolve a promise that nothing was waiting on. This resulted in the authentication hanging until timeout.

Solution

Changed waitForAuthorizationCode() to wait for redirectToAuthorization() to be initiated before proceeding, rather than creating a new deferred. A redirectInitiatedDeferred is used to signal when the redirect has been initiated, allowing waitForAuthorizationCode() to wait for it if called first. This ensures both methods always use the same authorizationDeferred promise.

Testing

  • Verified mcporter auth linear now properly waits for browser approval
  • The OAuth callback correctly resolves the authorization code

Fixes #36

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 047e86e880

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/oauth.ts Outdated
@monotykamary monotykamary force-pushed the fix/oauth-race-condition branch from 047e86e to f3c774e Compare February 16, 2026 02:24
monotykamary and others added 2 commits March 2, 2026 19:59
Ensure waitForAuthorizationCode uses the same deferred created by redirectToAuthorization instead of creating a new one. If waitForAuthorizationCode is called before redirectToAuthorization has been invoked, it now waits for the redirect to be initiated before proceeding. This fixes the race condition where the OAuth callback could resolve a different promise than what the runtime was waiting on, causing authentication to fail with a timeout.

Fixes openclaw#36
@steipete steipete force-pushed the fix/oauth-race-condition branch from f3c774e to cca61bb Compare March 2, 2026 20:02
@steipete steipete merged commit 30abe3d into openclaw:main Mar 2, 2026
@steipete
Copy link
Copy Markdown
Collaborator

steipete commented Mar 2, 2026

Landed via temp rebase onto main.

  • Gate: pnpm check && pnpm test && pnpm build && pnpm run docs:list
  • Land commit: cca61bb
  • Merge commit: 30abe3d

Thanks @monotykamary!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crashes when trying to auth linear mcp server

2 participants