fix(auth): prevent OAuth refresh lock races - #32
Merged
Merged
Conversation
graseeel
marked this pull request as ready for review
August 12, 2026 00:45
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.
What changed
ENOTACQUIRED/ERELEASEDduring lock cleanup from replacing an OAuth result that was already determinedWhy
A long tool turn can trigger a proactive token check and a server-initiated 401 recovery close together. Those paths previously used separate in-flight guards, so both could acquire or replace the same
proper-lockfiletarget. If their release callbacks completed out of order, the CLI surfacedLock is not acquired/owned by youand aborted the turn even when the refreshed token had already been persisted.This change serializes the two refresh paths and treats only the two known stale-ownership cleanup codes as non-fatal. It does not retry the whole agent turn, avoiding duplicate tool side effects.
Validation
ENOTACQUIREDtest failed before the fix and passes after itbun test src/utils/auth.refresh.test.ts src/utils/providerAccounts/store.cross-process.test.ts— 8 pass, 0 failbun run build— passed; CLI and SDK bundles validatednode dist/cli.mjs --version—0.15.13 (Verboo Code)bun run scripts/pr-intent-scan.ts --base upstream/main— no suspicious additionsRepository-wide validation is not currently green:
bun testreported 2697 pass / 137 fail in other suites, andbun run typecheckreports existing generated-surface/type drift. The changed auth files introduce no additional scoped typecheck errors.No version bump or release is included in this PR.