Queue same-process credential writes so each gets its own lock window - #906
Merged
TheGreatAxios merged 4 commits intoSep 11, 2026
Conversation
Same-process writers all polled the on-disk lock against a deadline that started at call time, so one lock held past the timeout failed the whole burst instead of just the first waiter. Writes now chain per auth file, and temp paths get a per-call counter so two saves in one process can never share one.
Replace the fixed 1.4s sleep with await-then-release so the lock-window case cannot flake if the event loop slips past the foreign lock removal, and add a same-process dual-profile save that pins the lost-update net without another timed wait.
TheGreatAxios
commented
Sep 11, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Critic · Comment
Ports MCP tmpWriteCounter + per-file updateChains into createAuthStore so same-process writers no longer share one lock deadline or one path.pid.tmp.
Findings
No blocking defects.
Nits
src/auth/store.test.ts:117—queues same-process profile writes so neither save is loststays green on main for N=2 (file lock alone serializes two saves insideLOCK_TIMEOUT_MS). It documents Done-when #3 but does not red without the queue. The lock-window test at:165is the real red/green pin. Optional follow-up: a higher-concurrency same-process burst (e.g. 20+ profiles) would fail on main via cascaded timeouts and pass with the queue — reproduced locally: main kept 39/50 under a 50-wayPromise.all, branch kept 50/50.src/auth/store.ts:58—updateChainsnever evicts settled entries (same as MCP). Fine for the one-path-per-provider production shape; only matters if a long-lived process injects many distincthomevalues.
CL-7318 Done-when
- Failing concurrency test then passes — met (
gives queued same-process writes their own lock window; fails on main with both waiters timing out, passes on tip). - Both fixes ported — met (
tmpWriteCounteratstore.ts:53/127,updateChains+enqueueAuthFileOpatstore.ts:58/170-188). - Two profiles concurrent save without loss — met (test at
store.test.ts:117+ suite green).
bun test ./src/auth/store.test.ts — 7 pass.
Replace the dual-save case that stayed green without the queue with a 50-way same-process burst that needs fresh lock deadlines, and document the queue plus defensive temp-counter in the store header.
TheGreatAxios
commented
Sep 11, 2026
TheGreatAxios
left a comment
Collaborator
Author
There was a problem hiding this comment.
Critic · Approve
Nit-fix tip replaces the weak N=2 same-process save with a 50-way burst that pins shared-deadline loss, and clarifies queue / temp-counter / lock-window comments.
Findings
No blocking defects.
Notes
- Burst pin is real: prior local check kept 39/50 on main without the queue; tip keeps 50/50 (~19ms). Lock-window test remains the precise deadline-freshness pin.
bun test ./src/auth/store.test.ts— 7 pass.
Ready to merge.
TheGreatAxios
deleted the
cl-7318-createauthstore-has-a-temp-path-collision-and-a-lost-update
branch
September 11, 2026 05:00
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.
Summary
path.pid.tmpVerification
bun test ./src/auth/store.test.ts— 7 passtmpWriteCounter+updateChainspattern already used insrc/mcp/auth-store.tsFixes CL-7318