Repository navigation
fix(mcpdo): restore a fresh OAuth-flow lock instead of deleting it on a lost steal - #2696
Merged
Merged
Conversation
… a lost steal (#2643) When two stealers interleave on a stale per-server lock, the second one renames the first's fresh lock, sees it is fresh and backs off - but deleted it on the way out, letting a third connect win create() and spawn a competing sign-in helper. Link the claim back to the lock path (which refuses if a newer lock exists) before removing the claim, so only a lock confirmed stale is ever discarded. Tests inject the interleaving through a pass-through renameSync seam. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation matches the issue requirements and covers both relevant race outcomes.
0 open findings
What changed in this PR
Fixes #2643 by preserving a fresh OAuth-flow lock encountered during a stale-lock steal race.
Changes:
- Restores fresh locks using a create-only hard link.
- Adds targeted coverage for restoration and
EEXISTraces.
| File | Description |
|---|---|
clients/mcpdo/src/connection/auth-helper.ts |
Restores fresh claimed locks before backing off. |
clients/mcpdo/__tests__/auth-helper.test.ts |
Tests both lock-restoration outcomes. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
Author
|
Copilot review loop closed: round 1 was clean (0 inline comments, nothing suppressed, approval recommended), so no further rounds were requested. |
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.
Closes #2643
Problem
In
tryReserveAuthFlow(clients/mcpdo/src/connection/auth-helper.ts), when two stealers race on a stale per-server lock, stealer B can rename stealer A's fresh lock to its claim path. B correctly detects the claim is fresh and backs off — but it did so withfs.rmSync(claimPath), deleting A's lock. A third connect then winscreate()and spawns a second sign-in helper, and the two contend for the OAuth callback port.Fix
On the fresh-claim branch, put the lock back with
fs.linkSync(claimPath, lockPath)before removing the claim. The hard link keeps the same inode (so A's mtime and contents are preserved), and it fails withEEXISTif a newer lock already took the path — in which case the outer catch backs off as before. Only a lock confirmed stale is ever discarded. Thev8 ignoreon that branch is gone: it's now covered.Tests
auth-helper.test.tsgains a pass-throughrenameSyncseam (the same patterndaemon-coverage.test.tsuses) and two cases that inject the interleaving inside the stat→rename window:npm run local:gatepasses.🤖 Generated with Claude Code