Skip to content

mig: scope user oauth tokens to toolset#1478

Merged
walker-tx merged 1 commit intomainfrom
walker/index-user-tokens-by-toolset-id
Feb 4, 2026
Merged

mig: scope user oauth tokens to toolset#1478
walker-tx merged 1 commit intomainfrom
walker/index-user-tokens-by-toolset-id

Conversation

@walker-tx
Copy link
Member

@walker-tx walker-tx commented Feb 3, 2026

This migration indexes user OAuth tokens by toolset_id instead of Issuer.


Open with Devin

@walker-tx walker-tx requested a review from a team as a code owner February 3, 2026 23:01
@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

⚠️ No Changeset found

Latest commit: e6ba3aa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

🔴 1 issue in files not directly in the diff

🔴 UpsertUserOAuthToken ON CONFLICT clause references non-existent unique index (server/internal/oauth/repo/queries.sql:138)

The UpsertUserOAuthToken query uses ON CONFLICT (user_id, organization_id, oauth_server_issuer) but the migration changes the unique index to (user_id, organization_id, toolset_id). After the migration runs, the ON CONFLICT clause will not match any unique constraint.

Click to expand

Impact

When a user completes OAuth authentication and the system tries to store/update their token via UpsertUserOAuthToken at server/internal/oauth/external_oauth.go:479, PostgreSQL will either:

  1. Raise an error because the ON CONFLICT target doesn't match any unique constraint
  2. Insert duplicate rows instead of updating existing ones

Actual vs Expected

  • Actual: The query's ON CONFLICT references (user_id, organization_id, oauth_server_issuer) which no longer has a unique index
  • Expected: The ON CONFLICT should reference (user_id, organization_id, toolset_id) to match the new unique index

Code Reference

The migration at server/migrations/20260203225638_index-user-tokens-by-toolset-id.sql:6 creates:

CREATE UNIQUE INDEX ... ON "user_oauth_tokens" ("user_id", "organization_id", "toolset_id")

But the query at server/internal/oauth/repo/queries.sql:138 still uses:

ON CONFLICT (user_id, organization_id, oauth_server_issuer) WHERE deleted IS FALSE DO UPDATE SET

Recommendation: Update the ON CONFLICT clause to use (user_id, organization_id, toolset_id) to match the new unique index. Also update the DO UPDATE SET clause to include toolset_id = EXCLUDED.toolset_id if needed, and consider whether client_registration_id and project_id should also be updated.

View issue and 4 additional flags in Devin Review.

Open in Devin Review

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

atlas migrate lint on server/migrations

Status Step Result
1 new migration file detected 20260203225638_index-user-tokens-by-toolset-id.sql
ERD and visual diff generated View Visualization
Analyze 20260203225638_index-user-tokens-by-toolset-id.sql
1 reports were found in analysis
Data dependent changes detected
Adding a unique index "user_oauth_tokens_user_org_issuer_key" on table "user_oauth_tokens" might fail in case columns "user_id", "organization_id", "toolset_id" contain duplicate entries (MF101)
Read the full linting report on Atlas Cloud

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

atlas migrate lint on server/clickhouse/migrations

Status Step Result
No migration files detected  
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

@walker-tx walker-tx changed the title mid: scope user oauth tokens to toolset mig: scope user oauth tokens to toolset Feb 3, 2026
@github-actions github-actions bot added the preview Spawn a preview environment label Feb 3, 2026
@speakeasybot
Copy link
Collaborator

speakeasybot commented Feb 3, 2026

🚀 Preview Environment (PR #1478)

Preview URL: https://pr-1478.dev.getgram.ai

Component Status Details Updated (UTC)
✅ Database Ready Created and validated 2026-02-03 23:10:32.
✅ Images Available Container images ready 2026-02-03 23:10:14.

Gram Preview Bot

@walker-tx walker-tx merged commit 76e6f73 into main Feb 4, 2026
27 of 29 checks passed
@walker-tx walker-tx deleted the walker/index-user-tokens-by-toolset-id branch February 4, 2026 13:08
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

preview Spawn a preview environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants