refactor(bearertoken): reduce re-auth by increasing polling rate. #6882
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.
Problem
we have an internal that runs every 5 minutes to take the current bearer token in the extension and send it to the language server. This is attempting to solve the problem of ensuring the bearer token used by the codewhisperer-LSP has not expired.
The difficulty is that the codewhisperer-LSP does not know when it is expired so it is the responsibility of the client(us) to ensure this token has not expired.
We currently do not passively refresh this token, but actively refresh it on request (see here:
aws-toolkit-vscode/packages/core/src/auth/sso/ssoAccessTokenProvider.ts
Lines 100 to 122 in c3ea31d
The current solution is to get and send the bearer token to the lsp every 5 minutes. However, if the token expires in the middle of these intervals, there is then a 1-5 minute period where if the customer interacts with anything using the codewhisperer-lsp, they will be prompted to re-auth unnecessarily.
The issue can be observed by manually poisoning the bearerToken used by the codewhisper lsp with something like:
Then, any lsp interaction will prompt for re-auth (until next interval 5 minute interval hits and token is refreshed).
Note that manually expiring the token locally does not work, since it is still valid for requests on the LSP.
Solution
getToken
(linked above) on a regular interval. However, if its cached, this is very cheap operation.auth.init -> auth.refreshConnection
to be more specific.Verification
UpdateBearerToken: {request}
log message shows up (from:aws-toolkit-vscode/packages/amazonq/src/lsp/auth.ts
Line 83 in ce01fa8
Alternative Solutions
feature/x
branches will not be squash-merged at release time.