Repository navigation
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Merging this PR will not alter performance1 warning
Comparing Footnotes |
[Medium impact] The PR appears safe to merge, with no new actionable issues found. SummarySerializes frontend installs and workspace initialization with the existing per-path lock.
Reviews (11) · Last reviewed commit: "Write through symlinked frontend files a..." · Reviewed by Greptile |
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Two exports (or an export and a prod/preview start) in the same project used to race on .web: the second replaced build/ and env.json while the first was still compiling or zipping, so one of them shipped the other's frontend. Hold an exclusive, reentrant file lock on .web/.reflex-build.lock from compilation through ZIP creation, release it before serving, and never create .web for a backend-only export that has nothing to protect. Split out of #7054 (lock only; the opt-in build cache that needs it follows separately). Claude-Session: https://claude.ai/code/session_018nWB9r2HcC5tkT72UxWgGj
Brings in #7449, which drops Python 3.10 and moves ruff to py311. Claude-Session: https://claude.ai/code/session_01PXcFKAgnzhgdnSvhuCmxWE
PERF203 only applies before Python 3.11, where try/except in a loop costs per iteration. With ruff targeting py311 since #7449 the directive is unused, which RUF100 rejects. Claude-Session: https://claude.ai/code/session_01PXcFKAgnzhgdnSvhuCmxWE
# Conflicts: # reflex/utils/js_runtimes.py # tests/units/test_prerequisites.py
- Generalize path_ops.json_file_lock into file_lock and lock the web dir for installs and .web initialization; drop reflex/utils/frontend_lock.py, the project-root .reflex.frontend.lock file and its gitignore entry. - Extract path_ops.atomic_write from _write_json_file and use it for package.json and lockfile writes; drop the private skeleton writer. - Keep procedure cache writes plain (they run under the install lock) and read a corrupt cache file as a miss with a single except clause. - Stub the lock in test_js_runtimes and isolate REFLEX_DIR so unit tests no longer leave lock files behind; drop tests for removed machinery.
There was a problem hiding this comment.
1 issue found across 15 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="news/+serialize-frontend-installs.bugfix.md">
<violation number="1" location="news/+serialize-frontend-installs.bugfix.md:1">
P3: This guarantee is too absolute: `file_lock` intentionally proceeds unlocked when the lock location is unavailable, so concurrent installs can still race in that supported configuration. Qualify the fragment to say coordination applies when the OS lock is available, while atomic writes still prevent partial files.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Turn on auto-fix | Re-trigger cubic
| @@ -0,0 +1 @@ | |||
| Serialize frontend dependency installs and `.web` initialization per app, and atomically persist package-manager files, so concurrent Reflex commands in one app no longer corrupt or duplicate an install. | |||
There was a problem hiding this comment.
P3: This guarantee is too absolute: file_lock intentionally proceeds unlocked when the lock location is unavailable, so concurrent installs can still race in that supported configuration. Qualify the fragment to say coordination applies when the OS lock is available, while atomic writes still prevent partial files.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At news/+serialize-frontend-installs.bugfix.md, line 1:
<comment>This guarantee is too absolute: `file_lock` intentionally proceeds unlocked when the lock location is unavailable, so concurrent installs can still race in that supported configuration. Qualify the fragment to say coordination applies when the OS lock is available, while atomic writes still prevent partial files.</comment>
<file context>
@@ -1 +1 @@
-Serialize frontend dependency installation per app and atomically persist package-manager files so concurrent Reflex commands cannot corrupt or duplicate an install.
+Serialize frontend dependency installs and `.web` initialization per app, and atomically persist package-manager files, so concurrent Reflex commands in one app no longer corrupt or duplicate an install.
</file context>
| Serialize frontend dependency installs and `.web` initialization per app, and atomically persist package-manager files, so concurrent Reflex commands in one app no longer corrupt or duplicate an install. | |
| Serialize frontend dependency installs and `.web` initialization per app, and atomically persist package-manager files. Concurrent commands are coordinated when the OS lock is available; when it is unavailable, atomic writes prevent partial files but installs may still race. |
There was a problem hiding this comment.
With the best-effort lock confirmed as the design (masenf on #7453), this wording nit is fair: the fragment could say coordination applies when the OS lock is available while atomic writes still prevent partial files. Leaving the edit to the PR's author since it is a one-line docs change on their branch.
Generated by Claude Code
The production build lock had its own copy of the platform-specific locking (flock / msvcrt) next to the sidecar-based json_file_lock, with different Windows polling, a different failure mode and a lock file inside .web. Keep one implementation: json_file_lock becomes file_lock, usable for files and directories, and gains the reentrancy and fork handling the build lock needed. Exports and production/preview startup now lock the .web directory through it. The sidecar lives in REFLEX_DIR, so locking never creates .web and the lock inode survives .web being replaced. Backend-only exports therefore always take the lock instead of skipping it when .web is absent, which closes the race the review bots flagged. The lock is released explicitly on Windows before the descriptor closes. Claude-Session: https://claude.ai/code/session_017XAFCkYB3Z8w3S6pgJrLCh
# Conflicts: # reflex/utils/path_ops.py # tests/units/utils/test_path_ops.py
The backend ZIP walks the app root, and REFLEX_DIR sat inside it, so the exporter archived its own held lock file. Windows refuses reads of a byte-range-locked file, failing the zip with PermissionError. Claude-Session: https://claude.ai/code/session_01PXcFKAgnzhgdnSvhuCmxWE
|
Merged the head of #7453 into this branch (merge commit, no history rewrite). The PR stays targeted at Why: #7453 holds Resolution: the Generated by Claude Code |
| development_dependencies.update( | ||
| _pinned_args_from_constants( | ||
| constants.PackageJson.REACT_COMPILER_DEV_DEPENDENCIES | ||
| with path_ops.file_lock(get_web_dir()): |
There was a problem hiding this comment.
When Granian is selected, _run_preview holds the .web lock while _compile_app starts a worker process and waits for it. During compilation, that worker reaches this new lock acquisition and waits for the parent to release the same lock. Neither process can continue, so the preview server never starts.
Move compilation and lock ownership into the same process, or change the preview lock scope so the parent does not hold it while waiting.
There was a problem hiding this comment.
Confirmed from the code. With Granian selected (the default when uvicorn and gunicorn are absent), _run_preview holds file_lock(.web) and calls _compile_app(), which runs compile_or_validate_app in a ProcessPoolExecutor worker. That reaches App._compile → js_runtimes.install_frontend_packages, which with this PR takes file_lock(get_web_dir()) in the worker. The parent waits on the worker's result, the worker waits on the parent's lock. _run_prod compiles in-process (avoid_dirty_check=False) and export compiles in-process, so only the preview path deadlocks. This only appears now that #7453 is on main.
Smallest fix, in reflex/reflex.py: pass the parent's held lock paths (path_ops._held_locks.paths) into _compile_app_worker and seed the worker's _held_locks.paths with them before running the task. The worker then reenters the lock the parent holds, which is correct because the parent is blocked on it for the whole compile. About six lines plus a test; it is safe on main without this PR too. Leaving the choice of where it lands (this PR or a small PR against main) to the author.
Generated by Claude Code
There was a problem hiding this comment.
Thanks for confirming the execution path. This is a real deadlock introduced by the new lock scope: in Granian preview, the parent holds the .web lock while waiting for the compile worker, while the worker reaches the same lock during install_frontend_packages.
The proposed handoff is the smallest targeted fix: pass the parent’s held lock paths to _compile_app_worker, seed the worker’s process-local held-path set before invoking app_task, and add a regression test covering Granian preview compilation. This preserves the existing fork behavior— inherited descriptors are cleared—while making the worker’s reentrant acquisition explicit. Please land that fix before merging this PR, whether here or as the prerequisite change on main.
There was a problem hiding this comment.
Fixed in 281f8dc: _compile_app passes path_ops.held_lock_paths() to the worker, which calls path_ops.adopt_held_locks before compiling, so the worker reenters the .web lock the waiting parent holds. Regression tests in test_reflex.py and test_path_ops.py cover the handoff.
Generated by Claude Code
Preserve atomic manifest writes alongside UTF-8/LF package.json formatting. Add atomic replacement and rollback regression coverage.
|
Pushed 61d1052 on top of the main merge: pre-commit's codespell read the escaped Generated by Claude Code |
…the compile worker atomic_write replaced a symlinked destination (e.g. a root bun.lock linked to a shared file) with a regular file and left the shared file stale. It now resolves the destination first, so the link survives and its target is replaced, as the previous copy-based writer did. With Granian, `reflex run --env preview` holds the .web lock while a ProcessPoolExecutor worker compiles the app, and that compile's frontend install takes the same lock: the parent waited on the worker and the worker on the parent. _compile_app now hands the locks held by its thread to the worker, which reenters them; the parent stays blocked for the whole compile, so the worker effectively owns them. Claude-Session: https://claude.ai/code/session_01LwJUCTv4VmfFw1ND9wvz8Z
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/units/test_reflex.py">
<violation number="1" location="tests/units/test_reflex.py:228">
P2: The deadlock cleanup kills every active child process, which can terminate unrelated test subprocesses and create cascading, misleading failures. Track the pool’s child process or the child set created by this test, then terminate only those processes.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
View guided diff | Turn on auto-fix | Re-trigger cubic
| deadlocked = thread.is_alive() | ||
| if deadlocked: | ||
| # Break the deadlock so the pool and the parent's lock are released. | ||
| for child in multiprocessing.active_children(): |
There was a problem hiding this comment.
P2: The deadlock cleanup kills every active child process, which can terminate unrelated test subprocesses and create cascading, misleading failures. Track the pool’s child process or the child set created by this test, then terminate only those processes.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/units/test_reflex.py, line 228:
<comment>The deadlock cleanup kills every active child process, which can terminate unrelated test subprocesses and create cascading, misleading failures. Track the pool’s child process or the child set created by this test, then terminate only those processes.</comment>
<file context>
@@ -175,6 +175,64 @@ def test_compile_app_worker_flushes_telemetry_on_failure(mocker):
+ deadlocked = thread.is_alive()
+ if deadlocked:
+ # Break the deadlock so the pool and the parent's lock are released.
+ for child in multiprocessing.active_children():
+ child.kill()
+ thread.join(DEFAULT_TIMEOUT)
</file context>
There was a problem hiding this comment.
Staying as is. That block runs only on the failure path, after the regression has already reproduced and the test has already failed; its sole job is to unwind the blocked pool so the suite can continue. multiprocessing.active_children() lists only this process's children, the unit suite does not run under xdist, and the pool's worker is created inside _compile_app, so the test has no handle to it. Tracking it would mean reaching into the executor for a cleanup that never runs when the fix holds.
Generated by Claude Code
Why
Two Reflex processes can currently enter the same frontend install transaction together. Both can mutate
.web, invoke the package manager, overwrite the procedure cache, and persist root lockfiles concurrently. A simultaneous frontend reinitialization can also replace.webduring an install.What changed
.reflex.frontend.lock. POSIX usesflock; Windows uses a retrying one-bytemsvcrtlock. The process-local layer is thread-safe and reentrant, and the OS releases ownership after crashes.initialize_web_directorywith the same lock so it cannot replace.webduring an active install.Atomic replacement guarantees complete-file visibility and preserves the prior file when commit fails; it does not claim power-loss durability without
fsync.Validation
uv run pytest -q tests/units/test_prerequisites.py tests/units/utils/test_utils.py tests/units/reflex_base/constants/test_base.py tests/units/reflex_base/constants/test_installer.py— 344 passeduv run ruff check .— passeduv run ruff format --check .— 1407 files already formatteduv run pyright reflex tests— 0 errors, 0 warningsuv run pre-commit run --all-files— all hooks passed, including Ruff, codespell, Pyright, ty, and BiomeTests cover positive same-project OS contention, complete transaction scope, completed-cache reuse by a waiting process, separate-project concurrency, reentrancy, exceptions and abrupt process exits, Windows contention retries, initialization exclusion, atomic failure recovery, corrupt-cache recovery, permissions, and symlink compatibility.
Checklist
CONTRIBUTING.md