Skip to content

Do not serialize the initial state when reflex db evaluates the pages - #7817

Merged
FarhanAliRaza merged 2 commits into
mainfrom
fix/migrate-skips-initial-state-compile
Nov 11, 2026
Merged

FarhanAliRaza merged 2 commits into
mainfrom
fix/migrate-skips-initial-state-compile

Conversation

@masenf

@masenf masenf commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Found in the reflex 0.11.0a1 pre-release testing (FINDING-009).

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Description

On a fresh reflex-enterprise app (no .web), reflex db migrate exits 1 after the upgrade has already run, with ValueError: Library @radix-ui/themes is not bundled. On 0.10.1 it exited 0.

The trigger is the migrations.evaluate_pages() step that #7742 added to migrate. evaluate_pages ran get_compiled_app(dry_run=True) with skip-compile set. That branch of compile_app also serializes the initial state, and it never runs the compiler plugins' frontend-dependency bundling. So the bundled-library registry holds only the defaults, unless an earlier compile left one in .web. rxe's strict check in its lambda serializer then raises.

The db commands only need the pages evaluated, so that lazily imported models register. The fix:

  • App._compile and compiler.compile_app take compile_initial_state: bool = True. Both skip-compile branches serialize the initial state only when it is True.
  • migrations.evaluate_pages() calls app._compile(dry_run=True, compile_initial_state=False).

Every other caller keeps the default, so backend-only starts, reflex compile --dry and the stateful-pages marker path behave as before. This also fixes reflex db init and makemigrations on such an app, which go through evaluate_pages too.

The pre-existing failure of a backend-only start on a fresh rxe checkout is out of scope (it also fails on 0.10.1). The skip branch could bundle the plugins' frontend dependencies before it serializes the state; that is a possible follow-up.

Tests

  • tests/units/utils/test_migrations.py::test_db_commands_do_not_serialize_the_initial_state: an app whose state holds a value with a strict serializer, which raises unless @radix-ui/themes is bundled, the way rxe's does. It runs reflex db init, makemigrations and migrate. Before the fix, init fails with the same ValueError; after the fix, all three exit 0.
  • uv run pytest tests/units --cov passes (81.4% coverage; tests/units/reflex_bench/drivers/test_browser.py was skipped because Chromium is not installed here). ruff check, ruff format and pyright reflex tests are clean.

Generated by Claude Code

View guided diff Turn on auto-fix

`reflex db init`, `makemigrations` and `migrate` evaluate every page so that
lazily imported models are registered. They did so through a dry-run,
skip-compile `get_compiled_app`, which also serialized the initial state.
Without a frontend compile, the libraries that compiler plugins bundle are
not registered, so a serializer that requires one (reflex-enterprise's
strict bundled-library check) failed a fresh `reflex db migrate` with
"Library @radix-ui/themes is not bundled", after the upgrade had run.

`App._compile` and `compile_app` take `compile_initial_state` (default
True, so every other caller is unchanged); `evaluate_pages` passes False.

Found in the reflex 0.11.0a1 pre-release testing (FINDING-009).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@masenf
masenf requested a review from a team as a code owner November 11, 2026 09:33
@masenf masenf added this to the v0.11.0 milestone Nov 11, 2026
@masenf masenf added the on deck PRs lined up to review / merge next label Nov 11, 2026

@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 5 files

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

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread tests/units/utils/test_migrations.py Resolved
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Database commands evaluate pages without serializing the initial state.

  • Database commands evaluate pages without serializing the initial state.

Reviews (3) · Last reviewed commit: "Make the db-commands test independent of..." · Reviewed by Greptile

Comment thread tests/units/utils/test_migrations.py Resolved
…e serializers

The test serializer now raises whenever it is called, so the test does not
pass merely because an earlier test bundled @radix-ui/themes, and the test
restores the global serializer registries it extends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@codspeed

codspeed Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.33%

2 warnings

⚠️ 16 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 150 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_process_event_burst_independent_tokens[1] 2.7 ms 2.8 ms -4.33%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/migrate-skips-initial-state-compile (c2c7626) with main (2d71015)

Open in CodSpeed

masenf pushed a commit that referenced this pull request Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@masenf

masenf commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

On the CodSpeed report: test_process_event_burst_independent_tokens[1] (−4.3%) is flagged "ran on different hardware" and shows the same drift on every open PR this morning. This PR only changes what reflex db commands compile, which that benchmark doesn't run.


Generated by Claude Code

@FarhanAliRaza
FarhanAliRaza merged commit 81a08eb into main Nov 11, 2026
167 of 168 checks passed
@FarhanAliRaza
FarhanAliRaza deleted the fix/migrate-skips-initial-state-compile branch November 11, 2026 13:46
masenf added a commit that referenced this pull request Nov 11, 2026
…#7817)

* Do not serialize the initial state when reflex db evaluates the pages

`reflex db init`, `makemigrations` and `migrate` evaluate every page so that
lazily imported models are registered. They did so through a dry-run,
skip-compile `get_compiled_app`, which also serialized the initial state.
Without a frontend compile, the libraries that compiler plugins bundle are
not registered, so a serializer that requires one (reflex-enterprise's
strict bundled-library check) failed a fresh `reflex db migrate` with
"Library @radix-ui/themes is not bundled", after the upgrade had run.

`App._compile` and `compile_app` take `compile_initial_state` (default
True, so every other caller is unchanged); `evaluate_pages` passes False.

Found in the reflex 0.11.0a1 pre-release testing (FINDING-009).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi

* Make the db-commands test independent of bundled libraries and restore serializers

The test serializer now raises whenever it is called, so the test does not
pass merely because an earlier test bundled @radix-ui/themes, and the test
restores the global serializer registries it extends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi

---------

Co-authored-by: Claude <noreply@anthropic.com>
(cherry picked from commit 81a08eb)
masenf pushed a commit that referenced this pull request Nov 11, 2026
…the train

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
@masenf masenf added the release-train Issues found during agentic /prerelease-testing fanout, not necessarily validated bugs. label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on deck PRs lined up to review / merge next release-train Issues found during agentic /prerelease-testing fanout, not necessarily validated bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants