Skip to content

Non-compiling backend workers lose bundled-library metadata and can drop the entire hydrate delta #7096

Closed

Description

@masenf

An existing session can reload showing compiled defaults even though its current state is still stored on the server. A Python-callable state value registered by reflex-enterprise triggers this when its serializer checks a process-local bundled-library registry that was never populated in the backend worker. That serializer raises inside JSON encoding, so the entire hydrate packet is lost, including unrelated valid state vars.

This is pre-existing in Reflex 0.9.10.post2 and reproduced in 0.9.11a1 with reflex-enterprise 0.9.5. The detailed independent verification narrows and extends the original finding: it is not limited to dev, and an unsupported value without a registered serializer does not cause this failure.

Minimal reproduction

Install reflex-enterprise==0.9.5 alongside the tested Reflex version. In a normal Reflex app (with app_name="minapp" in rxconfig.py):

import reflex as rx
import reflex_enterprise as rxe


def cell_renderer(params: rx.Var) -> rx.Component:
    return rx.text("cell")


class MinState(rx.State):
    count: int = 0
    col_defs: list[dict] = [{"field": "name", "cell_renderer": cell_renderer}]

    @rx.event
    def increment(self):
        self.count += 1


def index():
    return rx.vstack(
        rx.text(MinState.count, id="count"),
        rx.button("Increment", on_click=MinState.increment),
    )


app = rxe.App()
app.add_page(index)
  1. Start reflex run from a fresh compile, before making any source edits.
  2. Click Increment three times: the UI shows 3.
  3. Reload the page: the UI shows 0 and the backend reports ValueError: Library @radix-ui/themes is not bundled.
  4. Click once: the UI jumps to 4. The server retained the state; only delivery failed.

The campaign's minimized app and driver require no AG Grid, memo component, patched demo, or special routes. Inspect ent_aggrid/verification/issue2_hydrate_delta/app/ for the exact tested source.

Affected configurations and controls

Configuration Observed result
Fresh dev worker that skips compilation Reload shows 0; next click shows 4
Separately started backend serving a production build with __REFLEX_SKIP_COMPILE=true Same lost state delivery; generic error banner in the UI
Default reflex run --env prod Granian path that compiles in the serving process No failure
Dev after the first source hot reload triggers a real compile No failure
Same probe without enterprise, using an object with no serializer Encodes as null; unrelated state survives reload

Both versions were independently checked. on_load still runs and is_hydrated can become true despite the lost hydrate packet. This affects reload/reconnect of an existing session most visibly, rather than first visits already displaying defaults.

Mechanism and ownership

  1. reflex_components_radix/plugin.py registers @radix-ui/themes during RadixThemesPlugin.enter_component, in the full compile walk.
  2. The early, non-compiling path in reflex/compiler/compiler.py:compile_app evaluates pages and returns before bundled-library setup. Its registry contains only react, @emotion/react, $/utils/context, and $/utils/state, even though the deployed frontend includes Radix.
  3. reflex_enterprise/vars.py:serialize_lambda validates that incomplete registry at websocket serialization time and raises ValueError.
  4. The exception escapes the JSON default= hook through reflex_base.utils.serializers.serialize → format.json_dumps → reflex.app._sio_dumps → Socket.IO packet encoding. The entire packet is aborted.

The framework-side action is to make bundled-library metadata match the actual frontend build in non-compiling workers, including dependencies discovered during component traversal. Persisting/restoring the compiled registry is one possible direction. The enterprise serializer also should not treat missing compilation context as proof a deployed library is absent. Silently swallowing arbitrary serializer errors would hide real data problems and is not a sufficient fix.

Expected: unrelated session state is delivered on reload, and backend bundle validation reflects the shipped build. Raw exception text in dev is intentional; production correctly uses a generic message, so error-message disclosure is not part of this bug.

Verified workaround

At app module import time:

from reflex_base.components.dynamic import bundle_library

bundle_library("@radix-ui/themes")

The campaign verified zero exceptions and a reload preserving 3 with that registration. It survives in a non-compiling worker; the compiling process can register Radix through its plugin.

Evidence and duplicate check

See the verification section near the end of ent_aggrid/NOTES.md and verification/issue2_hydrate_delta/: reports/min_a1_dev_report.json, reports/min_0910_dev_report.json, reports/deploylike_report.json, the corresponding log excerpts, probe_registry.py, serve_deploy_like.py, and reports/workaround_report.json.

Searched open and closed Reflex issues for hydrate, serialization, unserializable values, bundled libraries, and missing dispatchers. Related #6975 / #7016 concern registrations discarded during frontend compilation and subpath rewriting; this report concerns absent compiled metadata in a non-compiling backend. #6019 concerns client-side missing dispatchers after packet delivery. Neither covers the packet being dropped during backend serialization. No matching existing issue found.

Source: prerelease finding 018, recorded against Reflex 0.9.11a1 and compared with 0.9.10.post2. See the full campaign report and cluster notes and reproduction artifacts. Findings and verification status above are from that campaign; this filing does not claim a new browser rerun.

Activity

  1. linear-code commented on Sep 11, 2026

    @linear-code
  2. masenf commented on Sep 11, 2026

    @masenf
    CollaboratorAuthor

    Status on the published 0.9.11a2 batch: the failure moved earlier

    Re-ran the minimized reproduction from this issue against published packages only (reflex 0.9.11a2 + reflex-base 0.9.11a2 + reflex-enterprise 0.9.5), with 0.9.11a1 running beside it as a control.

    Stack Observation
    0.9.11a1 + rxe 0.9.5 unchanged: counter reaches 3, reload shows 0 (with on_load-ran and is_hydrated true), next click shows 4. The ValueError appears twice in the log and the worker survives.
    0.9.11a2 + rxe 0.9.5 the app never starts — worker-1 exits while loading the app module, the backend never binds, the frontend serves but cannot hydrate.
    File ".../reflex/compiler/utils.py", …          return serializers.serialize(value)
    File ".../reflex_base/utils/serializers.py", …  serialized = serializer(value)
    File ".../reflex_enterprise/vars.py", …         return serialize_lambda_var(LiteralLambdaVar.create(func))
    File ".../reflex_enterprise/vars.py", 166       raise ValueError(
    ValueError: Library @radix-ui/themes is not bundled. Use `from reflex.components.dynamic import
    bundle_library; bundle_library('@radix-ui/themes') to enable it it.
    [ERROR] Unexpected exit from worker-1
    

    Deterministic — reproduced twice, the second time after rm -rf .web.

    Raising at compile time is the better failure mode, so this is a step in the right direction rather than something to revert: the silent packet loss is gone and the problem is now loud and immediate. What remains is that the app still cannot run, and the error's advice cannot be followed from where it is raised — the value lives in a state field's default, and the exception happens while the worker is importing the app module.

    Why the new extraction misses this case

    The serialize_initial_value hook that #7109 added in reflex/compiler/utils.py::_compile_initial_state (new in a2 — it does not exist in the 0.9.11a1 wheel) only bundles when the value is a component:

    def serialize_initial_value(value: Any) -> Any:
        if isinstance(value, Component):
            value_imports = value._get_all_imports()
            _bundle_imports(value_imports)
            ...
        return serializers.serialize(value)

    The value here is a plain Python callable. reflex-enterprise turns it into a LiteralLambdaVar, and the component it renders — and therefore @radix-ui/themes — is reachable only through that Var's var data, never through isinstance(value, Component).

    Suggested direction

    Extend the initial-state dynamic-import extraction so it also looks at fields that are a Var whose _get_all_var_data() carries components, and bundle those imports the same way it bundles a component's own. That should cover this case.

    One wrinkle for whoever picks it up: the validation currently raises inside the serializer (LiteralLambdaVar.create → _validate_and_extend_return_expr), so an extraction hook that inspects the value first has to reach the var data without going through the validating construction — or the validation has to be deferred until after bundling — otherwise the hook raises before it gets the chance to register anything.

    Worth weighing against the fact that removing the dynamic-bundling feature altogether is on the table; if that is where this ends up, this is not worth much investment.

    Evidence

    From the 0.9.11a2 published-package validation: PUBLISHED_VALIDATION_RESULTS.md (the "018 — separately labelled adjacent check" section, with the smallest reproduction), plus published_review_a2/out/f018_a{1,2}_dev.json, published_review_a2/logs/minrx_a{1,2}_*.tail.log and the driver published_review_a2/scripts/drive_018.py.

    The production-build / separately-started non-compiling backend variant of the check was not run on a2: the app cannot start at all there, so that configuration has no meaning until the startup failure is resolved.


    Generated by Claude Code

  3. masenf commented on Sep 11, 2026

    @masenf
    CollaboratorAuthor

    Follow-up on the "raises before it can register anything" wrinkle from my previous comment — agreed, that half is reflex-enterprise's, and there are two shapes it could take.

    The var data is already in hand at the raise site. LiteralLambdaVar._validate_and_extend_return_expr (reflex_enterprise/vars.py:121 in 0.9.5) computes return_expr._get_all_var_data() and then walks vd.imports against get_bundled_libraries(), raising on the first package that is not registered (:162-168). That is exactly the data a framework-side initial-state extraction would want, so enterprise can either register those imports itself instead of raising, or expose a non-validating construction and let the caller bundle first.

    One ordering caveat either way. In compile_app, both non-compiling branches call utils._compile_initial_state(app._state) and return before _reset_bundled_libraries_for_compile() and the plugin dependency registration (reflex/compiler/compiler.py:1234 and :1254 vs :1264-1271). So in a non-compiling worker, registering at that moment cannot repair a frontend that was already built — it only helps when the same process goes on to build. Which is the same conclusion this issue already reaches from the other direction: a non-compiling worker's registry should not be treated as authoritative evidence that a deployed library is absent.

    Or drop the mechanism. Replacing LiteralLambdaVar with function-style rx.memo for ag-grid-style callback props would remove the bespoke __reflex['<pkg>']?.<tag> runtime lookup, and the bundled-library validation with it, in favour of components reflex already compiles and bundles through the normal path. Enterprise's own error messages in that same function already steer users to @rx.memo for the custom-code and hooks cases — this would extend that to the whole mechanism rather than keeping two ways to ship a callback.

    Recording this here because reflex-enterprise is a separate tracker; happy for it to move.


    Generated by Claude Code

  4. harsh21234i commented on Sep 12, 2026

    @harsh21234i
    Contributor

    This change addresses the original non-compiling-worker hydration failure by restoring the bundled-library registry before state serialization. However, the newer 0.9.11a2 failure occurs earlier, while reflex- enterprise imports the app module and validates the callable, before Reflex can restore the registry.
    That remaining startup failure appears to require a coordinated reflex-enterprise change or a maintainer-approved framework API. I do not want to claim this PR completely resolves #7096 without covering that path.

  5. added
    release-train
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    release-train

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions