Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Fix Cody onboarding redirect problem#63096

Merged
vdavid merged 2 commits intomainfrom
dv/fix-cody-onboarding-redirect
Jun 5, 2024
Merged

Fix Cody onboarding redirect problem#63096
vdavid merged 2 commits intomainfrom
dv/fix-cody-onboarding-redirect

Conversation

@vdavid
Copy link
Contributor

@vdavid vdavid commented Jun 5, 2024

Closes https://linear.app/sourcegraph/issue/PRIME-299/unable-to-sign-into-cody-account-via-github

The problem is that in some cases, the Cody Management page (https://courcegraph.com/cody/manage) doesn't redirect requests to the returnTo URL passed to it.
The situation when this occurs is when the user has not completed the Cody onboarding flow in the browser they are seeing the page.

History of the bug:

  • Originally, it worked, but only because of an apparently accidental, transient state in this line where the variable completed was initialized with the value of true.
  • I made a change in December (in https://github.com/sourcegraph/sourcegraph/pull/58854) where I removed that transient state, but thus, I broke the redirect, which caused severe onboarding UX problems.
  • This PR fixes the redirect again, by making the redirect decision logic consider requestFrom=CODY even in the return URL.

This is actually just another hack; the right solution would be for clients to propoerly pass the request=CODY to the Cody Management page itself, not just in the return URL. But it is what it is, this solution works with that glitch, which is a solution that works with versions of clients that are already released.

Test plan

I've tested locally with all combinations of

  • ab-shortened-install-first-signup-flow-cody-2024-04 feature flag being on/off
  • the string requestFrom=CODY present/not present in the return URL
  • the cody.onboarding.completed temporary setting being true/false

Changelog

fix(cody): redirect Cody client requests to the access token creation page in all cases

@vdavid vdavid requested review from a team and olafurpg June 5, 2024 11:30
@cla-bot cla-bot bot added the cla-signed label Jun 5, 2024
Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

I think this fix will only work for VS Code

const returnToURL = parameters.get('returnTo')
const isCody = parameters.get('requestFrom') === 'CODY'
// Even if just the return URL contains `requestFrom=CODY`, we should treat it as a request from Cody.
const isCody = parameters.get('requestFrom') === 'CODY' || returnToURL?.includes('requestFrom=CODY')
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@olafurpg I see. Looks like a miscommunication happened about the intended interface of this page, as none of the clients seem to be passing the requestFrom=CODY argument to the /cody/manage page specifically. I think this requirement might not have been communicated to client teams. Anyway, it is what it is, let's figure out how to go forward.

I have a few ideas for a solution:
a.) Add yet another exception to detect requestFrom=JETBRAINS in the URL. But then, Neovim or others might fall into the same hole.
b.) Detect "/user/settings/tokens/new/callback" in the URL instead—all clients use it, so it clearly indicates a call coming from Cody.
c.) I wonder if we could just do the redirect for any returnTo without showing the onboarding form. I'd need to check with Product, but as I'm aware of our flows, we don't call this page with a returnTo with the intention for the user to go through the onboarding flow and then be redirected.

If Product agrees, I'd just go with c.), as that's the simplest logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

We will add login flows for Visual Studio and Eclipse soon. I vote for c), but option b) also works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@olafurpg, I've implemented a solution between b and c, redirecting all requests that have requestFrom as a search param to /cody/manage, or anywhere in the returnTo URL: https://github.com/sourcegraph/sourcegraph/pull/63096/commits/2421f60d89c848e1302d7a17316090744042c06c

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

@vdavid vdavid enabled auto-merge (squash) June 5, 2024 12:01
@vdavid vdavid merged commit 23eed1d into main Jun 5, 2024
@vdavid vdavid deleted the dv/fix-cody-onboarding-redirect branch June 5, 2024 12:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants