Skip to content

fix(auth): refresh under the lock, finish a started refresh, retry a replaced token [ENG-5309] - #43

Merged
Arlieeee merged 2 commits into
mainfrom
arliexubindu/refresh-under-lock
Nov 3, 2026
Merged

Arlieeee merged 2 commits into
mainfrom
arliexubindu/refresh-under-lock

Conversation

@Arlieeee

@Arlieeee Arlieeee commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

A token refresh in one process no longer breaks the others. The API ends the previous access token as soon as it issues a new one, so before this change a refresh in one command (a terminal, another agent, a host app) made every other holder of the old token fail with 401: a running wait, or a credential a host app handed over.

Fixed

  • Refresh under the lock. The OAuth refresh runs entirely under the credentials lock, and the profile is re-read there: commands started together refresh once, and the rest use the new token instead of spending the refresh token again.
  • A started refresh is always saved. From the refresh request to the save, a second Ctrl-C or the end of a terminate signal's grace period waits; the exit follows the save. A process stopped in between used to leave only a spent refresh token, which ended the login on the next refresh.
  • A replaced token is retried once. After a 401 with an OAuth token (stored, or handed over through DSH_MESHY_CREDENTIAL), the request is retried once with the token now stored for the same login. Another account's token is never used.
  • Windows: wait for PowerShell. The key store waits up to 30 seconds for Windows PowerShell (was 5). PowerShell can take several seconds to start on a cold or busy machine, which made the CLI fall back to the key file when saving a login, or fail to open a stored one. DPAPI never prompts; the Keychain and the Secret Service keep 5 seconds.

🤖 Generated with Claude Code

Arlieeee and others added 2 commits November 3, 2026 16:02
…replaced token [ENG-5309]

- The OAuth refresh runs under the credentials lock and re-reads the
  profile there, so parallel commands refresh once and the rest adopt the
  new token.
- From the refresh request to the save, forced exits (a second Ctrl-C, the
  end of a terminate signal's grace period) wait, so a rotated refresh
  token is never lost.
- After a 401 with an OAuth token (stored or host-provided), the request is
  retried once with the token now stored for the same login: the API ends
  the previous access token as soon as another process refreshes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PowerShell can take several seconds to start; a 5 s limit made a cold or
busy Windows machine fall back to the key file, or fail to open a stored
login. DPAPI never prompts, so it now waits up to 30 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Arlieeee
Arlieeee merged commit 8343510 into main Nov 3, 2026
7 checks passed
@Arlieeee
Arlieeee deleted the arliexubindu/refresh-under-lock branch November 3, 2026 08:09
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.

1 participant