Skip to content

fix(config): keep rxconfig dependencies on same-root reload - #7075

Open
benedikt-bartscher wants to merge 7 commits into
reflex-dev:mainfrom
benedikt-bartscher:config-deps-evict-on-root-change
Open

fix(config): keep rxconfig dependencies on same-root reload#7075
benedikt-bartscher wants to merge 7 commits into
reflex-dev:mainfrom
benedikt-bartscher:config-deps-evict-on-root-change

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #7028

_get_config() evicts every project-local module that rxconfig.py imported before each load. rx.App() calls reload_config(), so every backend worker loads rxconfig.py twice and re-executes those modules in between. The app code imported before rx.App() keeps the first copies, sys.modules holds the second ones, and every class defined in an evicted module now exists twice.

For state-defining modules that is the StateValueError from #7028. For plain modules it is quieter and worse: pickle.dumps() of an instance of the app's copy fails with Can't pickle <class 'myapp.routes.Route'>: it's not the same object as myapp.routes.Route, because the qualified name resolves to the re-imported class. In our production app that made the auth substate unserializable, so it was never persisted to redis and clients got stuck on hydrate.

Changes

Testing

Review in cubic

@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner September 10, 2026 08:47
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge with no outstanding correctness, security, or repository-rule issues.

Summary

  • Tracks the project root associated with recorded rxconfig.py dependencies.
  • Keeps dependency module identities stable during same-root reloads, avoiding duplicate state classes and pickle identity failures.
  • Restricts rxconfig discovery to the explicitly requested project root.
  • Adds regression coverage for successful reloads, failed loads, cross-root switching, state registration, and serialization.
  • Adds a user-facing bugfix news fragment.

Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..."

@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
@codspeed-hq

codspeed-hq Bot commented Sep 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 40 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing benedikt-bartscher:config-deps-evict-on-root-change (b46485c) with main (9165dc6)

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 across 2 files (changes from recent commits).

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

Re-trigger cubic

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

@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 across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread packages/reflex-base/src/reflex_base/config.py Outdated
Comment thread packages/reflex-base/src/reflex_base/config.py Outdated
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.

Reloading a config whose rxconfig.py imports a state-defining module raises StateValueError

1 participant