improvement(mcp): trace OAuth state writes to diagnose invalid_state clobber#5772
Conversation
…clobber The MCP OAuth callback fails with invalid_state because the authorization state is cleared/missing by the time the user authorizes — but clearState was silent, so the clobber never surfaced in logs. Log every state save and clear with a caller context so the exact source is visible on the next repro.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview
No change to OAuth behavior beyond observability; existing callers without a context still work via the default. Reviewed by Cursor Bugbot for commit 8bf096a. Configure here. |
Greptile SummaryThis PR adds caller context to MCP OAuth state-write diagnostics. The main changes are:
Confidence Score: 5/5The changed flow looks mergeable after a small cleanup to its diagnostics.
apps/sim/lib/mcp/oauth/storage.ts Important Files Changed
Reviews (1): Last reviewed commit: "improvement(mcp): trace OAuth state writ..." | Re-trigger Greptile |
Summary
app.withgauge.com/mcpand others) fails on the callback withinvalid_state("Authorization expired"). Staging DB + logs confirm the authorizationstateis cleared ~5s after/oauth/startsaves it, before the user authorizes — butclearStatewas silent, so the clobber never appeared in logs.state:safeDecryptnever touchesstate(it's a hash, not encrypted), and the discovery/connection paths short-circuit (if (!row.tokens)) before ever running the SDKauth()flow.contexttosaveState/clearStateand logs every write, so the exact clobber source is pinned on the next repro — then the precise fix follows.Type of Change
Testing
Tested manually — lint, typecheck, and 29 OAuth unit tests pass. Instrumentation is behavior-preserving (optional param defaults to
unknown).Checklist