Fix cross-process Linear OAuth refresh wiping valid connections#400
Draft
cursor[bot] wants to merge 1 commit into
Draft
Fix cross-process Linear OAuth refresh wiping valid connections#400cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
When desktop and ade serve both refresh near token expiry, Linear rotates the refresh token on the first exchange. The loser gets invalid_grant and was clearing the shared credential store, forcing a full reconnect. Serialize refresh with a cross-process lock under .ade/secrets and treat invalid_grant as stale when the store already has a rotated refresh token or a fresh access token. Co-authored-by: Arul Sharma <arul28@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
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.
Bug and impact
When ADE desktop and
ade serve(headless runtime) are both active for the same project, a near-expiry Linear OAuth refresh can race. Linear rotates the refresh token on the first successful exchange; the second runtime retries with the now-invalid refresh token, getsinvalid_grant, and clears the shared credential store — forcing the user to reconnect Linear even though the connection was still valid.This was introduced by the automatic OAuth token refresh added in #395.
Root cause
ensureFreshToken()deduped refreshes in-process only (refreshInFlight).EncryptedFileCredentialStoreunder.ade/secrets.invalid_grant, both services unconditionally cleared all Linear credentials.Fix
linear-oauth-refresh.lock) so only one runtime refreshes at a time.invalid_grant; if the refresh token was rotated or the access token is now fresh, treat the failure as a stale race and do not clear the connection.linearCredentialService) and headless (headlessLinearServices).Validation
npm run test -- --run src/main/services/cto/linearTokenRefresh.test.ts src/main/services/cto/linearAuth.test.ts(45 tests passed)npm --prefix apps/ade-cli run test -- --run src/headlessLinearServices.test.ts(22 tests passed)npm --prefix apps/desktop run typecheck