Skip to content

fix(tidy3d): FXC-5400-fix-local-cache-race-conditions#3227

Open
marcorudolphflex wants to merge 1 commit intodevelopfrom
FXC-5400-fix-local-cache-race-conditions
Open

fix(tidy3d): FXC-5400-fix-local-cache-race-conditions#3227
marcorudolphflex wants to merge 1 commit intodevelopfrom
FXC-5400-fix-local-cache-race-conditions

Conversation

@marcorudolphflex
Copy link
Contributor

@marcorudolphflex marcorudolphflex commented Feb 4, 2026

  • Hardened local cache stats updates across processes:
    • Introduced a cross-process file lock with a clear lock boundary for entry-point operations.
    • Switched stats.json writes to unique temp files to avoid collisions.
    • Simplified locking so entry-points take the combined lock and helpers assume it’s held.

Note

Medium Risk
Touches core caching I/O and locking behavior; while changes are localized, mistakes could deadlock or regress cache performance/consistency under concurrency.

Overview
Fixes local result cache corruption when multiple processes update the same cache directory.

LocalCache now wraps entry-point operations (list, clear, _fetch, _store, invalidate, sync_stats, etc.) in a combined in-process + inter-process filelock-based lock with a single, explicit lock boundary (helpers assume the lock is already held). stats.json (and other metadata) writes now use per-process unique temp filenames before os.replace, avoiding tmp-file collisions.

Adds multiprocessing regression tests that force concurrent _store / invalidate / stats updates, and updates dependencies (filelock added to core deps; lockfile changes in poetry.lock). CHANGELOG notes the local cache race fix.

Written by Cursor Bugbot for commit 9ab4c55. This will update automatically on new commits. Configure here.

@marcorudolphflex marcorudolphflex force-pushed the FXC-5400-fix-local-cache-race-conditions branch 2 times, most recently from 6d80a70 to c860582 Compare February 4, 2026 11:57
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/web/cache.py (84.4%): Missing lines 201-203,205-206

Summary

  • Total: 32 lines
  • Missing: 5 lines
  • Coverage: 84%

tidy3d/web/cache.py

Lines 197-210

  197     @contextmanager
  198     def _with_interprocess_lock(self) -> Iterator[None]:
  199         depth = getattr(self._file_lock_state, "depth", 0)
  200         if depth > 0:
! 201             self._file_lock_state.depth = depth + 1
! 202             try:
! 203                 yield
  204             finally:
! 205                 self._file_lock_state.depth -= 1
! 206             return
  207 
  208         self._lock_path.parent.mkdir(parents=True, exist_ok=True)
  209         self._root.mkdir(parents=True, exist_ok=True)
  210         with self._file_lock:

Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

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

Fixed the

ERROR: Failed to fetch cache results: [Errno 2] No such file or
                  directory: '/Users/twhughes/.cache/tidy3d/simulations/stats.tmp' ->
                  '/Users/twhughes/.cache/tidy3d/simulations/stats.json'

for me, thanks @marcorudolphflex !

btw I'm on Mac.

@marcorudolphflex marcorudolphflex force-pushed the FXC-5400-fix-local-cache-race-conditions branch 2 times, most recently from 15a14bc to e8b68c1 Compare February 6, 2026 10:11
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@marcorudolphflex marcorudolphflex force-pushed the FXC-5400-fix-local-cache-race-conditions branch from 9354aae to 8ccfb03 Compare February 6, 2026 11:13
@marcorudolphflex marcorudolphflex force-pushed the FXC-5400-fix-local-cache-race-conditions branch from 8ccfb03 to 9ab4c55 Compare February 6, 2026 12:53
@marcorudolphflex marcorudolphflex added this pull request to the merge queue Feb 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants