Skip to content

Keep concurrent MCP OAuth writes from wiping tokens - #487

Closed
TheGreatAxios wants to merge 1 commit into
mainfrom
fix/mcp-oauth-token-persist
Closed

Keep concurrent MCP OAuth writes from wiping tokens#487
TheGreatAxios wants to merge 1 commit into
mainfrom
fix/mcp-oauth-token-persist

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

MCP OAuth auth state was full-snapshot last-writer-wins. A concurrent session (or second connect) could save a new PKCE code verifier and erase tokens just written by another session — Linear often ended with only client registration + verifier and no tokens, while the UI could still look connected. Concurrent re-auth also races PKCE (Invalid PKCE code_verifier). Stale dynamic client registration against a previous loopback port made re-auth fail as well.

This has been latent since remote MCP OAuth landed (#44).

Changes

  • Serialize read-modify-write per auth file and add updateAuthState so field patches merge instead of clobbering
  • Use unique temp paths so concurrent renames do not hit ENOENT
  • Drop stale DCR clients when the loopback redirect port no longer matches and there are no refreshable tokens
  • Regression tests for concurrent token+verifier writes and redirect mismatch

Test plan

  • bun run typecheck
  • bun test ./src/mcp
  • Clear Linear auth, re-auth once with a single Corbits process built from this branch, confirm durable tokens on disk
  • Confirm two concurrent connects no longer wipe tokens when one saves a verifier

Linear

Fixes CL-6679
https://linear.app/abklabs/issue/CL-6679/keep-concurrent-mcp-oauth-writes-from-wiping-tokens

Auth-store last-writer-wins full snapshots let a second session codeVerifier save erase tokens just written by the first. Serialize read-modify-write per server, use unique temp files, and drop stale DCR clients when the loopback redirect port no longer matches.
@TheGreatAxios
TheGreatAxios force-pushed the fix/mcp-oauth-token-persist branch from 70892fe to 27d3136 Compare August 21, 2026 15:12
@TheGreatAxios
TheGreatAxios deleted the fix/mcp-oauth-token-persist branch August 22, 2026 16:14
@linear-code

linear-code Bot commented Aug 22, 2026

Copy link
Copy Markdown

CL-6679

@TheGreatAxios

Copy link
Copy Markdown
Collaborator Author

Work continues on #499 under CL-6679 (same commit 27d3136). This PR closed as a side effect of renaming the branch to the Linear slug.

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.

1 participant