Repository navigation
fix(auth): stop MCP OAuth discovery from failing with 500 on Workers - #61
Merged
Merged
Conversation
Better Auth's runtime schema check is one promise per isolate, started in the background of the request that builds the instance. On Workers, a request that ends first (an unauthenticated MCP call answers 401 at once) leaves it unable to settle, and every later request in that isolate fails. getAuth already migrates the schema, so the runtime check is off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Executor couldn't start a Spendle sign-in: its OAuth discovery got HTTP 500 from
/.well-known/oauth-protected-resource/api/mcp, while the same URL answered 200 from elsewhere.Production logs for those 500s show
This promise was created by a request that has since ended, so it can never settle, thrown where Better Auth awaits its runtime schema check. That check is one promise per isolate, started in the background of the request that builds the auth instance. On Workers, when that request ends first (an unauthenticatedPOST /api/mcpanswers 401 right away, which is what Executor's discovery sends first), the promise can never settle, and every later auth or discovery request in that isolate fails with 500 until Cloudflare recycles it.getAuthalready migrates the auth schema itself (once per deployment on Workers), so this turns Better Auth's runtime check off (advanced.database.validateSchema: false).Testing
vp build --mode qa,vp preview --mode qa, fresh D1): an unauthenticated MCP call (401), then the protected resource metadata, authorization server metadata and JWKS (200), QA sign-in and a signed-in page all work. Without the slow production D1 I could not reproduce the hang locally.Created with Claude Opus 5.5 in Claude Code (T3 Code).