Skip to content

Make MCP OAuth attempts atomic and eliminate orphan auth sessions #833

Description

@dcramer

Problem

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.

Related: #782.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions