Skip to content

fix(config): load rxconfig with cwd prepended - #6933

Open
benedikt-bartscher wants to merge 4 commits into
reflex-dev:mainfrom
benedikt-bartscher:fix-config-syspath-race
Open

fix(config): load rxconfig with cwd prepended#6933
benedikt-bartscher wants to merge 4 commits into
reflex-dev:mainfrom
benedikt-bartscher:fix-config-syspath-race

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Review in cubic

… sys.path, racing concurrent first-time imports

_load_config cleared sys.path down to the cwd for the duration of the
rxconfig import, so any concurrent first-time import in another thread
failed with ModuleNotFoundError (e.g. the lazy granian import when the
backend starts while another thread loads the config). Prepending the cwd
keeps the same resolution priority without blinding other threads.

Dropping the clear also removes the except-retry fallback, which had been
papering over a second bug: find_spec("rxconfig") answers from sys.modules,
so a leftover module from another project directory faked the existence
probe. Evict rxconfig from sys.modules before probing instead.
@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review August 23, 2026 17:59
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner August 23, 2026 17:59
@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR changes configuration loading to preserve the process import path during rxconfig imports and introduces thread-scoped tracking for project-local dependencies.

  • Prepends and removes the working-directory path by identity.
  • Replaces global sys.modules snapshotting with a thread-bound meta-path recorder.
  • Adds concurrency and path-ownership regression tests.

Confidence Score: 4/5

The PR is not yet safe to merge because project configuration code can remove the temporary meta-path recorder and turn configuration loading into a cleanup failure.

The unconditional recorder removal can raise ValueError after arbitrary rxconfig execution, masking the original import result and preventing the intended failed-import dependency cleanup.

Files Needing Attention: packages/reflex-base/src/reflex_base/config.py

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/config.py Preserves sys.path during configuration imports and narrows dependency tracking, but meta-path cleanup can raise if project code mutates the installed recorder.
tests/units/test_config.py Adds regression coverage for concurrent imports, caller-owned path entries, and dependency attribution.
packages/reflex-base/news/6933.bugfix.md Documents the configuration-loading concurrency and stale-module fixes.

Reviews (4): Last reviewed commit: "Merge branch 'main' into fix-config-sysp..." | Re-trigger Greptile

Comment thread packages/reflex-base/src/reflex_base/config.py Outdated
Comment thread tests/units/test_config.py
@codspeed-hq

codspeed-hq Bot commented Aug 23, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 27 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing benedikt-bartscher:fix-config-syspath-race (c2172cd) with main (126ef6d)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/reflex-base/src/reflex_base/config.py
Comment thread packages/reflex-base/src/reflex_base/config.py Outdated

@abulvenz abulvenz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, nice finding. I would improve on the in-code-comment as annotated. In the tests those comments can help to understand why that test is needed.

Comment on lines +909 to +910
sys.path here made concurrent first-time imports elsewhere fail with
ModuleNotFoundError for the duration of the rxconfig import.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment describes the historic version that is now gone.

try:
rxconfig = importlib.import_module(constants.Config.MODULE)
finally:
sys.meta_path.remove(recorder)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Meta-path cleanup masks load result

When rxconfig.py or one of its imports removes or rebuilds sys.meta_path, this unconditional removal raises ValueError, turning a successful configuration load into a failure or masking the original import exception and skipping dependency recording.

Suggested change
sys.meta_path.remove(recorder)
for i, finder in enumerate(sys.meta_path):
if finder is recorder:
del sys.meta_path[i]
break

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.

2 participants