You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make MCP OAuth attempts atomic and eliminate orphan auth sessions #833
Junior eagerly persists an MCP auth session whenever an MCP provider is activated, before knowing whether interaction is required. Successful already-authorized calls leave those records behind for 24 hours.
The per-user/provider index keeps stale IDs and can grow indefinitely for an active user. Same-session link reuse can also delete the live auth session needed by the already-delivered callback URL.
Root causes
auth attempts are inferred from loosely coupled session/index/pending-auth records
lookup uses "latest session for user/provider" rather than deterministic attempt identity
attempt state is created before the SDK reaches an interactive redirect
link reuse deletes the newly prepared session without proving it is distinct from the reused attempt
callback claim/completion is not an atomic, idempotent transition
Acceptance criteria
Silent authenticated MCP calls create no authorization-attempt record.
Attempts are created lazily only when interaction is required.
Attempt identity is deterministic from the owning conversation/session/provider or represented by an explicit opaque attempt ID.
Reusing a live link cannot delete or invalidate its attempt state.
Attempt indexes prune expired entries and cannot grow indefinitely.
Callback claim and completion are atomic and duplicate callbacks are idempotent.
Persisted attempt context includes source, destination, actor, scope, resource, issuer, redirect URI, and resume identity.
Denied, expired, failed, superseded, and completed attempts all reach terminal states.
createMcpOAuthClientProvider in packages/junior/src/chat/mcp/oauth.ts writes the auth session before the SDK decides whether a redirect is needed, so silent already-authorized calls still append to the index.
getLatestMcpAuthSessionForUserProvider picks the latest by updatedAtMs, and putMcpAuthSession resets the index TTL while appending, so the per-user/provider index grows without pruning stale IDs.
finalizeMcpAuthorization has no atomic claim step, so duplicate callbacks would both run transport.finishAuth.
Activity
sentry-pierre commentedon Jul 11, 2026
createMcpOAuthClientProviderinpackages/junior/src/chat/mcp/oauth.tswrites the auth session before the SDK decides whether a redirect is needed, so silent already-authorized calls still append to the index.getLatestMcpAuthSessionForUserProviderpicks the latest byupdatedAtMs, andputMcpAuthSessionresets the index TTL while appending, so the per-user/provider index grows without pruning stale IDs.finalizeMcpAuthorizationhas no atomic claim step, so duplicate callbacks would both runtransport.finishAuth.All root causes line up with the code.