Skip to content

Fix provider cache atomic write temp path collisions#2291

Merged
juliusmarminge merged 5 commits into
mainfrom
cursor/provider-cache-hydration-rename-6462
Apr 23, 2026
Merged

Fix provider cache atomic write temp path collisions#2291
juliusmarminge merged 5 commits into
mainfrom
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 temp path collisions in provider cache atomic writes by extracting writeFileStringAtomically

  • Introduces atomicWrite.ts with a writeFileStringAtomically utility that writes to a UUID-named temp file in a scoped temp directory co-located with the target, then renames it to the final path.
  • Replaces duplicated inline atomic-write logic (mkdir, write temp, rename, ensure cleanup) across providerStatusCache.ts, serverRuntimeState.ts, serverSettings.ts, and keybindings.ts with calls to the new utility.
  • The original implementations shared a fixed temp filename suffix, causing collisions under concurrent writes; the UUID-based naming in the new utility prevents this.

Macroscope summarized 6ad9e56.

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: aa459f72-3ecc-40e2-8c44-3881e43eac09

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
Comment thread apps/server/src/provider/providerStatusCache.test.ts
@juliusmarminge juliusmarminge marked this pull request as ready for review April 23, 2026 04:24
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 23, 2026

Approvability

Verdict: Approved

This PR extracts duplicate atomic file write logic into a shared utility and improves temp file path generation to use UUIDs instead of pid+timestamp, addressing potential collision issues. The changes are mechanical consolidation with a minor reliability improvement, self-contained with no API or schema changes.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit e25db3a into main Apr 23, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the cursor/provider-cache-hydration-rename-6462 branch April 23, 2026 04:33
yazandabbas pushed a commit to yazandabbas/Presence that referenced this pull request Apr 23, 2026
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
(cherry picked from commit e25db3a)
Morphexe pushed a commit to Morphexe/t3code that referenced this pull request May 4, 2026
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
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