GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): serialize MCP OAuth refreshes across processes by rekram1-node · Pull Request #50994 · anomalyco/opencode

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Sep 23, 2026

Copy link
Copy Markdown
Member

Fixes #34520.

Problem

MCP OAuth credentials live in one global row that every opencode process shares: the background server, each opencode acp, and run --standalone. When the access token expires, two processes can refresh at once with the same refresh token. The authorization server rotates it for the first request and rejects the second with invalid_grant. Servers with refresh-token reuse detection go further and revoke the whole token family, so every process ends up in needs_auth and the user has to log in again.

Within one process, concurrent refreshes already share a single request. Across processes, nothing coordinates them.

Change

  • SDK patch. Adds an optional withRefreshLock(refresh) hook to OAuthClientProvider. The SDK runs its read-tokens, refresh, save-tokens sequence inside that hook. Providers that don't implement it are unchanged.
  • MCP provider. The provider for a stored credential implements the hook with the existing EffectFlock lock, keyed by credential ID. Because tokens() runs inside the lock, a process that waited reads the refresh token the previous holder just saved. It never replays the old one.

The hook sits in the SDK because every refresh happens there, triggered by a 401, a step-up or a retry after invalid_grant. Wrapping only our own call sites would leave those paths unlocked.

A compare-and-swap on the row, as the issue suggests, would keep the stale refresh from overwriting good tokens. But the stale refresh request would still reach the authorization server, and that request is what triggers reuse detection. Only serializing the refresh stops it.

What this wins

  • Parallel processes no longer knock each other into needs_auth when a shared token expires.
  • Servers with reuse detection no longer revoke the token family.

Tests

  • New test: two providers share one credential row, as two processes would, and refresh concurrently. The second refresh presents the rotated token. With the lock removed, the test fails because both refreshes present the same token.
  • packages/core: MCP, MCP OAuth and integration suites pass (116 tests). bun run check passes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lucleray reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@rekram1-node
fix(core): serialize MCP OAuth refreshes across processes
00aee1d
@github-actions github-actions Bot mentioned this pull request Sep 23, 2026
📊 AI CLI 工具社区动态日报 2026-09-24 litang9/big_model_radar#443
Open
This was referenced Sep 25, 2026
[origin-review] anomalyco/opencode#50994 — CLEAN kvnloo/opencode#1
Closed
[origin-review] anomalyco/opencode#50994 — CLEAN kvnloo/opencode#2
Closed
@kvnloo

kvnloo commented Sep 25, 2026

Copy link
Copy Markdown

I took a closer look at the cross-process refresh regression on head 00aee1d.

The useful part is that this is testing more than a normal OAuth refresh:

  • it constructs two separate providers sharing the same EffectFlock state directory
  • it uses plain fetch, so the providers do not share an in-memory single-flight request
  • the token endpoint deliberately holds the first refresh open
  • the observed refresh-token sequence must be r, then r+
  • the final stored refresh token must be r++

That pins the important ownership invariant: the waiter has to re-read the credential after acquiring the lock rather than replaying the refresh token that the previous holder just rotated.

The exact-head check and test workflows are green.

The remaining limit I see is that the regression uses separate provider instances sharing the filesystem lock rather than two real OS processes against an IdP with reuse detection. That feels like qualification evidence rather than a missing unit-level contract, assuming EffectFlock cross-process exclusion is already covered at its owner.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:15
@opencode-agent opencode-agent Bot mentioned this pull request Oct 13, 2026
[FEATURE]: trigger MCP authentication from the ACP client #55048
Open
1 task done
@neriousy neriousy mentioned this pull request Oct 21, 2026
V2 MCP OAuth: serialize credential refresh across locations/processes #34520
Closed
@github-actions

github-actions Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Oct 24, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Oct 24, 2026
@opencodejr opencodejr Bot mentioned this pull request Oct 30, 2026
mcp: concurrent OAuth refreshes across locations invalidate rotating refresh tokens and delete the credential #60612
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

V2 MCP OAuth: serialize credential refresh across locations/processes

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@rekram1-node @kvnloo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.