Skip to content

Fix provider cache atomic write temp path collisions#2291

Draft
juliusmarminge wants to merge 4 commits intomainfrom
cursor/provider-cache-hydration-rename-6462
Draft

Fix provider cache atomic write temp path collisions#2291
juliusmarminge wants to merge 4 commits intomainfrom
cursor/provider-cache-hydration-rename-6462

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 22, 2026

What Changed

  • introduced a shared atomic file write helper that now uses Effect-native UUID generation and scoped temp directories
  • switched provider cache persistence to use the shared helper
  • added a regression test covering overlapping writes to the same provider cache file
  • migrated the other duplicated server-side atomic JSON writers to the same helper for consistency

Why

Provider cache writes used temp filenames derived from process.pid and Date.now(). Two writes to the same cache file in the same process and same millisecond could pick the same temp path, causing one rename() to move the file and the other to fail with ENOENT. The helper now creates a scoped temp directory beside the target file and writes a UUID-named temp file before the final atomic rename, removing that collision class while keeping the implementation inside Effect APIs.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes
Open in Web Open in Cursor 

Note

Fix provider cache atomic write temp path collisions using random UUIDs

  • Adds makeAtomicWriteTempPath in atomicWrite.ts that generates unique temp paths using process.pid + crypto.randomUUID() instead of time-based suffixes, preventing collisions on concurrent writes.
  • Adds writeFileStringAtomically as a shared Effect-based utility that handles directory creation, temp file write, rename, and cleanup.
  • Refactors writeProviderStatusCache, persistServerRuntimeState, writeSettingsAtomically, and writeConfigAtomically to all delegate to this shared utility, removing duplicated atomic write logic.
  • Adds a concurrent-write test for writeProviderStatusCache that verifies two parallel writes to the same file both succeed without data corruption.

Macroscope summarized fc43d5f. (Automatic summaries will resume when PR exits draft mode or review begins).

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 675a48e6-0410-4f0d-8139-01b9117fb4e0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/provider-cache-hydration-rename-6462

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Apr 22, 2026
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Apr 22, 2026
cursoragent and others added 2 commits April 22, 2026 14:45
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Apr 22, 2026
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usless test @cursor, remove

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants