Repository navigation
fix(mcp): prevent auth failures during concurrent token refresh - #4441
benjaminshafii wants to merge 6 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 4 Skipped Deployments
|
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (33161db84f26a23ffe48940d0cc0991fc4efe3bd). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
|
@OmarMcAdam Please review the Better Auth dependency patch, especially refresh-token replay binding, revocation, grace limits, and polling. CI passes, but this changes the authentication boundary; the branch also currently has a merge conflict. Holding for your review under the current merge instructions. |
Deploying openwork with
|
| Latest commit: |
af3dd12
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://446db974.openwork.pages.dev |
| Branch Preview URL: | https://fix-codex-mcp-auth.openwork.pages.dev |
Test evidence — overlapping-mcp-refreshes-reuse-one-successor-without-granting-another-client-or — ✅ passed✅ passed · 6 expectations passed · 0 failed · 0 pending verdict passed · 0 user observations · 0 probes · steps 0/0 ℹ️ ASSERTION — 1. Concurrent refresh round 1 succeedsHTTP statuses: 200, 200, 200, 200
ℹ️ ASSERTION — 2. Concurrent refresh round 2 succeedsHTTP statuses: 200, 200, 200, 200
ℹ️ ASSERTION — 3. Concurrent refresh round 3 succeedsHTTP statuses: 200, 200, 200, 200
ℹ️ ASSERTION — 4. Replay remains usable later within the grace intervalAfter 20 seconds, the same refresh request returns HTTP 200 and the identical access and refresh tokens.
ℹ️ ASSERTION — 5. Replay remains bound to the original request and grace intervalNarrower-scope replay and a foreign resource returned 400. After 31 seconds, stale replay and its revoked successor both returned invalid_grant.
ℹ️ ASSERTION — 6. One successor remains usable and replay cannot cross clients or expand scopesAll overlapping responses shared one successor; wrong-client and wider-scope attempts returned 400; the final successor refreshed and initialized MCP with HTTP 200.
Test run created 2026-09-04T22:04:30.158Z · Source: |
Codex can successfully initialize OpenWork MCP and then report
Auth requiredwhen overlapping workers refresh the same credential. The investigated client log containedinvalid_grant: invalid refresh token; it does not establish the exact cause of that historical rejection. A new HTTP journey reproduced a concrete race in the pinned OAuth provider: four concurrent refreshes returned[400, 400, 200, 400]before the patch.The provider revokes the original token before persisting the winning response. This patch lets both the atomic-update loser and a reader of that intermediate state briefly poll for the same encrypted replay response. It preserves the existing client, scope, resource, confirmation-binding, and grace checks and never mints a second successor. Polling is capped at 40 attempts with 25 ms between attempts; failures remain closed. The dependency patch needs review on the next Better Auth upgrade.
Validation:
pnpm evals:pr specs/mcp-oauth-concurrent-refresh.test.ts(local API + isolated MySQL database; no reused Den). Covers PKCE sign-in/consent, three rounds of four concurrent refreshes, one shared successor per round, MCP initialization, rejection of another client/broader scopes/mismatched replay/foreign resource, and stale replay with family revocation after 31 seconds. Test evidence is published below. Spec boundary and channel ratchets also passed. The general CI lane explicitly skips this database journey when MySQL/Redis are absent; a dedicated Linux step provisions both services and requires the regression to execute. Missing services in that step fail the job.The investigation and recovery guidance are in
docs/mcp-oauth-refresh-race.md. Already expired or revoked credentials still require reauthorization; this does not claim to restore them or prove that the reproduced race caused the historical incident.CI also exposed a shutdown-order assertion in the server unit suite: retirement marks a generation dead before the process exits. The test now waits (bounded to five seconds) for process exit, preserving the original assertion.