Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amazonq): Use the correct state for Q in remote environment #5575

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nkomonen-amazon
Copy link
Contributor

Problem:

As part of our design we intentionally separate the Auth state between a local environment, versus a remote (ssh'd) one. We do this so that if the user has 2 IDE instances, one local and the other remote, if one changes its auth state the other one will not be affected.

The reason for separating auth that I can remember is due to how we store the actual tokens on disk. Because the remote does not have access to the disk of the local, we need to ensure the remote operates its auth independently of the local auth.

By design globalState is shared by both local and remote instances. So for local we need to ensure we do not use the base globalState, otherwise the same Auth state as the remote will be used.

The problem, SecondaryAuth is not doing this for all cases. It is using the globalState when it should be asking Auth which state it should use. The happy path was working though, but there can be potential issues with this bug at some other point.

Solution:

Expose the state that Auth is using so that something like SecondaryAuth can ask Auth for the correct state object depending on the local vs remote.


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@nkomonen-amazon nkomonen-amazon requested a review from a team as a code owner September 11, 2024 20:49
Copy link

This pull request modifies files in src/ but no tests were added/updated. Confirm whether tests should be added or ensure the PR description explains why tests are not required.

Copy link

This pull request modifies a feature or fixes a bug, but it does not include a changelog entry. All pull requests that introduce new features or bug fixes must have a corresponding changelog item describing the changes.

Problem:

As part of our design we intentionally separate the Auth state between a local environment, versus a remote (ssh'd) one.
We do this so that if the user has 2 IDE instances, one local and the other remote, if one changes its auth state
the other one will not be affected.

The reason for separating auth that I can remember is due to how we store the actual tokens on disk.
Because the remote does not have access to the disk of the local, we need to ensure the remote operates its
auth independently of the local auth.

By design globalState is shared by both local and remote instances. So for local we need to ensure we do not use the
base globalState, otherwise the same Auth state as the remote will be used.

The problem, SecondaryAuth is not doing this for all cases. It is using the globalState when it should be asking Auth
which state it should use. The happy path was working though, but there can be potential issues with this bug
at some other point.

Solution:

Expose the state that Auth is using so that something like SecondaryAuth can ask Auth for the correct state object
depending on the local vs remote.
Signed-off-by: Nikolas Komonen <[email protected]>
@hayemaxi
Copy link
Contributor

Won't this log existing users out? It seems that the key that stores the last connection ID now lives somewhere else.

due to this change one of the tests needed a slight update to work again due
to a race condition that occurs during testing since we do not know when all
the required event emitters are fully completed.

In this case the onDidDeleteConnection event handler in SecondaryAuth was async
and the unit test completed before the handler finished. This caused the test to fail.

Signed-off-by: nkomonen-amazon <[email protected]>
@nkomonen-amazon
Copy link
Contributor Author

Won't this log existing users out? It seems that the key that stores the last connection ID now lives somewhere else.

@hayemaxi

  • this will not impact the Local IDE users as the state they were using will remain the same even with the changes in this pr
  • this will not impact Remote IDE users since when we use SecondaryAuth.activeConnection it first checks the #savedConnection and then fallsback to the #activeConnection if needed. Before this PR in SecondaryAuth.useNewConnection() it would indirectly add the connection to both the #savedConnection and #activeConnection. But due to this bug, if a user also signed in on local, the #savedConnection in remote would become invalid (due to the remote incorrectly using the same state as the local). Though when retrieving the #savedConnection in the remote failed we fellback to #activeConnection and this was correct since #activeConnection is what Auth is using and that was already using the correct state.
    • So a summary would be that things coincidentally worked before but in this bugged scenario it was using the #activeConnection when we thought it was using the #savedConnection. Now it will correctly set the #savedConnection next time they log in.
    • I think also this value in the recent telemetry change may have been incorrectly representing the state. We should have used SecondaryAuth.activeConnection instead of the #savedConnection since the auth would actually fall back to the #activeConnection if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants