Repository navigation
feat(cli): Claim Sentry agent handoffs during setup - #2320
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
| }); | ||
|
|
||
| if (getEnv().SENTRY_SETUP_CODE && !hasStoredAuthCredentials()) { | ||
| const handoffCode = getEnv().SENTRY_HANDOFF?.trim(); |
There was a problem hiding this comment.
| const handoffCode = getEnv().SENTRY_HANDOFF?.trim(); | |
| const handoffCode = getEnv().SENTRY_HANDOFF?.trim(); | |
| const setupCode = getEnv().SENTRY_SETUPC_ODE?.trim(); |
should just have both up here then
There was a problem hiding this comment.
Done — setup now reads and trims both handoff and setup codes together before branching.
|
|
||
| if (getEnv().SENTRY_SETUP_CODE && !hasStoredAuthCredentials()) { | ||
| const handoffCode = getEnv().SENTRY_HANDOFF?.trim(); | ||
| let flowInstructions: string | undefined; |
There was a problem hiding this comment.
A better name might be like
| let flowInstructions: string | undefined; | |
| let afterSetupInstructions: string | undefined; |
There was a problem hiding this comment.
Done — renamed this to afterSetupInstructions.
| } = {}, | ||
| ): Promise<BootstrapResult> { | ||
| const code = getEnv().SENTRY_SETUP_CODE; | ||
| const code = options.code ?? getEnv().SENTRY_SETUP_CODE; |
There was a problem hiding this comment.
Should we just make code required and the caller would pass the SENTRY_SETUP_CODE wherever this was called before?
There was a problem hiding this comment.
Done — bootstrapAuthentication now requires code, and the setup and auth command callers pass SENTRY_SETUP_CODE explicitly while handoff passes the returned setup code.
9c9cb07 to
058096d
Compare
058096d to
a751a95
Compare
| yield new CommandOutput( | ||
| await bootstrapAuthentication({ | ||
| ...flags, | ||
| code: getEnv().SENTRY_SETUP_CODE ?? "", | ||
| }), | ||
| ); |
There was a problem hiding this comment.
nvm actually I dislike tis lol, move the SENTRY_SETUP_CODE back into the bootstrapAuthentication and make code optional again
There was a problem hiding this comment.
Done — bootstrapAuthentication now falls back to SENTRY_SETUP_CODE when code is omitted. The auth bootstrap and setup callers use that fallback again, while handoff still passes its claimed setup code explicitly.
a751a95 to
8aac411
Compare
8aac411 to
89984ab
Compare
89984ab to
d070421
Compare
d070421 to
2f8c183
Compare
2f8c183 to
9a607f5
Compare
| clientId: handoff.clientId, | ||
| force: true, | ||
| url: handoff.sentryUrl, | ||
| }); |
There was a problem hiding this comment.
Handoff client ID not persisted
Medium Severity
Handoff authentication exchanges the setup code with handoff.clientId, but that client ID is not stored on the account. Later refresh still calls getClientId(), which is the env/build default. When those IDs differ, refresh is rejected after the access token expires and the headless session dies.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9a607f5. Configure here.
There was a problem hiding this comment.
Tracked separately in #2383. We should persist the issuing OAuth client ID with each stored credential and use it for refresh. This can also affect existing logins if SENTRY_CLIENT_ID changes after login.
9a607f5 to
da5169e
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit da5169e. Configure here.
| if (!flags["no-completions"]) { | ||
| await warmCachesAfterLogin(); | ||
| } | ||
| } else if (setupCode && !hasStoredAuthCredentials()) { |
There was a problem hiding this comment.
Should't we do this even when there are stored auth credentials? To make sure this account is added to the list as it's not guaranteed to be the same as local credentials?
da5169e to
f25b90c
Compare
Web handoffs need setup to claim the intended account even when another login is already stored. Exchange the short-lived handoff during the existing setup path, replace the applicable account, and reveal the returned instructions only after authentication succeeds.
f25b90c to
6b06a89
Compare
…#2354) Lets Sentry's setup page show one command that installs the CLI and claims the agent handoff: `curl -fsSL https://cli.sentry.dev/install/sntryh_… | bash`. `/install/<code>` returns the normal install script with `export SENTRY_HANDOFF='<code>'` added after the shebang. `sentry cli setup --install` then claims the handoff (#2320). Plain `/install` doesn't change. The site is deployed as static Vercel build output, so the new route goes to a small Edge Function. At packaging time, the function gets the same install script the release ships. It only accepts codes that match Sentry's format: `sntryh_` followed by 43 base64url chars, the same regex as `sentry/agent_handoff/views.py`. That keeps anything shell-unsafe out of the script. Any other code returns 404, and responses are sent with `Cache-Control: no-store`. To add a function, packaging had to move out of the inline `printf`/`zip` in `cli-build.yml` and into `apps/cli-docs/vercel/build-output.mjs`. The existing `/install` routes are byte-for-byte unchanged. **Open questions** - Vercel's routing to the function hasn't been tried on a real deployment yet. The function reads the code from either the rewritten `?code=` or the original `/install/<code>` path, so it works whichever URL Vercel passes it. Worth trying on a preview deploy before merging. - The handoff code now appears in request URLs, so it shows up in Vercel request logs. That seems acceptable for a short-lived, single-use code. - Only bash for now. `install.ps1/<code>` would be a small follow-up if we want a Windows one-liner. <!-- junior-request-attribution:start --> via @evanpurkhiser. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0C272JQP44%3A1794959461.634559 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0C272JQP44%3A1794959461.634559) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0C272JQP44%3A1794959461.634559/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Evan Purkhiser <1421724+evanpurkhiser@users.noreply.github.com>
Agent handoffs now claim and authenticate through Sentry CLI, so the public Markdown page should hand the one-time code to the installer instead of exchanging it itself. This updates `agent-handoff.md` with `SENTRY_HANDOFF` install commands for Unix and PowerShell, removes the legacy Markdown POST, slash alias, and private credential runbook, and moves the remaining claim tests to the public JSON API. Claim and setup-code analytics remain on the shared API path. Draft until [getsentry/toolkit#2320](getsentry/toolkit#2320) lands and its CLI release is available from the stable installer. --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>


The public handoff page launches the installer with
SENTRY_HANDOFF. Setup must claim the intended account even when the CLI is already installed or authenticated to another account or Sentry host, and failures need to remain actionable without exposing either short-lived code.Integrate handoff claiming into the existing
sentry cli setup --installpath used by the shell and PowerShell installers. The CLI uses the generatedclaimAgentHandoffoperation from@sentry/api2.8.0, authenticates with the returned setup code, client ID, and Sentry URL while superseding unrelated credentials, and printsflowInstructionsonly after authentication succeeds.Structured API errors preserve useful server detail. An IP-pinning mismatch provides explicit recovery guidance using the stable code from getsentry/sentry#131464, while handoff and setup codes remain out of logs, telemetry, persisted configuration, and user-facing errors.