Repository navigation
feat(cli): Pick the stored account from the target org or server - #1528
Open
sentry-junior[bot] wants to merge 10 commits into
Open
sentry-junior[bot] wants to merge 10 commits into
sentry-junior[bot] wants to merge 10 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 16, 2026 21:06
b9d3f2c to
a9699d8
Compare
BYK
reviewed
Oct 16, 2026
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 16, 2026 23:21
ad24de9 to
2139d1a
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 00:21
0e933d8 to
46c6dc7
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 00:30
46c6dc7 to
c288b7b
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 00:37
c288b7b to
66b331e
Compare
BYK
marked this pull request as ready for review
October 17, 2026 01:09
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 01:11
66b331e to
dc83d07
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 01:16
dc83d07 to
3de3978
Compare
sentry-junior
Bot
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 01:46
2715364 to
6c99389
Compare
With several stored accounts, commands now use the one that fits what they target instead of always using the active account: - an explicit server (SENTRY_HOST/SENTRY_URL, .sentryclirc, or a pasted Sentry URL) selects the stored account on that server - an organization missing from the active account's cached org list selects the stored account that has used it, for the rest of the invocation Schema v19 records which account each cached org row belongs to and backfills existing rows. The stored active account never changes, one invocation never mixes identities, and forced env tokens still win.
Use `last_used_at` (falling back to `updated_at`) when choosing the most recently used account for an org or server, matching logout promotion.
`hasCachedOrgList` ignored `updated_at`, so an expired org list still let org-based selection override the active account. Apply the same 7-day TTL as `getCachedOrganizations`.
…t account Push recency ordering and the usable-credential filter into the account queries instead of sorting and filtering rows in TypeScript. The org lookup is now one query over the `org_regions.account_id` cache that returns usable owners most recently used first; only same-server matching (origin normalization, `*.sentry.io` as one server) stays in code. Rename the per-invocation selection from "pinned" to the invocation's default account, and document why the scope is keyed by the env object: library-mode calls can overlap in one process, each under its own env.
…org cache A login stored while a command had picked another account for its target org wrote to that account: re-authentication overwrote its credentials and recording the user could then delete the active account as a duplicate. Logins now drop the invocation's picked account first, so they replace the active account (or add a new one) and the rest of the invocation uses the new credentials. Invalidating an account's credentials also only cleared org memberships cached under its current identity. Rows written before a refresh-token rotation kept the account id, so a later login on that account inherited stale memberships. Clear rows by account id too, as account deletion does.
Picking the account for a DSN-style `oNNNN` org only matched cached rows carrying that numeric id, but resolving a single org by slug caches no id (only org lists do). An account that had used the org by slug was missed and the active account kept. Also match rows for the slug that any cached row on the same server maps the id to.
… authenticate `selectAccountForOrg` kept the account in effect whenever it had no fresh cached org list. An account whose credentials were invalidated (token cleared, org cache dropped) always qualified, so a usable stored account that knows the org was never picked and the command failed auth. Only keep the account in effect on that ground when it can still authenticate.
BYK
force-pushed
the
feat/cli-account-routing
branch
from
October 17, 2026 05:51
c192232 to
a592763
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a592763. Configure here.
BYK
approved these changes
Oct 17, 2026
BYK
approved these changes
Oct 17, 2026
…sts unsnapshotted Replacing credentials in place (`sentry auth login --force`, automatic re-login) wrote to the account selected for the configured server, so SENTRY_HOST/SENTRY_URL or `.sentryclirc` naming another stored account's server overwrote that account instead of the active one. The legacy NULL host backfill had the same mix-up. Both now use the stored active account. Pasting a SaaS URL read the active token host after clearing the URL; with an env token in effect that snapshotted the token's host as SaaS even when it was scoped to a self-hosted server. Compare the stored account in effect instead, which never touches the env-token snapshot.
Member
|
I wonder if we should modify commands like "org list" to list all available organizations under all accounts. Wdyt? |
`sentry auth login --force` (and automatic re-login) replaced the stored active account even when the login targeted another server, so a self-hosted login could overwrite a SaaS account and vice versa. Accounts are now always tied to their server: an in-place login replaces the active account only when it is on the login's server, otherwise the most recently used account on that server, and adds a new account when that server has none. Accounts on other servers are never touched. The `--force --token` path removes only that server's previous login, after the new token validates. Co-Authored-By: Burak Yigit Kaya <burak.kaya@sentry.io>
This branch was previously deployed
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.

Stacked on #1526. Covers the automatic-selection half of #1396: with several stored accounts, commands use the account that fits what they target, so users don't have to
sentry auth switchback and forth.How the account is chosen (per invocation, most specific first)
resolveOrgRegion/resolveEffectiveOrg, so it covers the ~55 org-scoped call sites and DSNoNNNNids.SENTRY_HOST/SENTRY_URL,.sentryclirc, or a pasted Sentry URL for another account's server selects the stored account on that server. Previously this was aHostScopeError.Guardrails
token-host.ts.auth switch), it is kept. An account that simply hasn't used the org yet can't be overridden by one that has.defaults.urlcounts as soft: when the pinned account is elsewhere, it yields to that account's host.SENTRY_FORCE_ENV_TOKENis never overridden.Storage
Schema v19 adds
org_regions.account_id. Writes record the account whose credentials fetched the row, following in-process refresh-token rotation. The migration backfills existing rows by matching credential identity. The org→account mapping is warm right away for new logins, because login already warms the org cache.Memoized credential state (token, fingerprint, row, stored-creds flag) is now keyed by selection, and user info reads and writes go to the account in effect. Account management (
switch,logout,list) still works on the stored active account.Not covered
via byk.
--
View Junior Session [Sentry]