Skip to content

fix(file-patch): serialize concurrent updates - #802

Draft
Whxuan0701 wants to merge 1 commit into
lsdefine:mainfrom
Whxuan0701:fix/file-patch-race
Draft

fix(file-patch): serialize concurrent updates#802
Whxuan0701 wants to merge 1 commit into
lsdefine:mainfrom
Whxuan0701:fix/file-patch-race

Conversation

@Whxuan0701

Copy link
Copy Markdown

Closes #799

What

  • Serializes each file_patch() read-modify-write transaction with a per-path thread lock.
  • Adds an OS-backed lock file keyed by the resolved target path for coordination between GenericAgent processes.
  • Keeps the existing uniqueness checks, newline preservation, return values, and dependency footprint.
  • Adds deterministic same-process thread and spawned-process regression tests.

Why

Two subagents could read the same file version, calculate disjoint edits, both return success, and have the last writer silently erase the first edit. The lock makes the read/validate/write sequence one transaction per path; a later conflicting patch now sees current content and follows the existing validation behavior.

Validation

  • Parent baseline f6e5657: deterministic delayed-read reproduction returns success twice but leaves only one edit.
  • New focused suite: 2 passed on Python 3.10.20, 3.12.13, and 3.13.14.
  • Full non-release frontend suite: 242 passed.
  • Release qualification suite: 35 passed.
  • python -m py_compile ga.py and git diff --check passed.

Boundary

The POSIX flock path was exercised on macOS. The Windows path uses the standard-library msvcrt.locking API but was not run on a Windows host; Windows CI feedback is welcome while this remains a draft.

@Whxuan0701

Copy link
Copy Markdown
Author

Implementation and deterministic thread/process regression tests are ready in this draft. The POSIX flock path was exercised on macOS 14.6.1; the Windows msvcrt path awaits Windows CI/maintainer validation.

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.

Concurrent file_patch calls can both succeed while losing an update

1 participant