Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Jan 14, 2026

This will convert ImmutableMutableProxy to MutableProxy for example when a value is stashed from a background event, then is accessed from a regular event.

…lues

This will convert ImmutableMutableProxy to MutableProxy for example when a
value is stashed from a background event, then is accessed from a regular
event.
@linear
Copy link

linear bot commented Jan 14, 2026

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 14, 2026

Greptile Summary

Fixed MutableProxy._wrap_recursive to properly handle proxy rebinding by unwrapping and rewrapping existing proxy values instead of just updating the state reference. This ensures ImmutableMutableProxy instances (from background events) are correctly converted to MutableProxy when accessed from regular events.

  • Changed _wrap_recursive in reflex/istate/proxy.py to unwrap existing proxies before rewrapping with current state reference
  • Removed conditional logic that only updated _self_state reference on existing proxies
  • Added comprehensive test assertions in test_rebind_mutable_proxy to verify proper proxy type conversion
  • Test validates that ImmutableMutableProxy becomes MutableProxy when accessed through unwrapped state

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is well-tested with comprehensive assertions covering the rebinding behavior. The logic simplification (unwrap then rewrap) is clearer and more correct than the previous approach (conditional state reference update). No edge cases or potential issues identified.
  • No files require special attention

Important Files Changed

Filename Overview
reflex/istate/proxy.py Fixed _wrap_recursive to unwrap and rewrap existing proxies, ensuring state references are properly rebound when converting ImmutableMutableProxy to MutableProxy
tests/units/test_state.py Added comprehensive test assertions to verify proxy rebinding behavior, including checks for proper conversion from ImmutableMutableProxy to MutableProxy

Sequence Diagram

sequenceDiagram
    participant BG as Background Event
    participant SP as StateProxy
    participant IMP as ImmutableMutableProxy
    participant MP as MutableProxy
    participant State as BaseState

    Note over BG,State: Background event stores value
    BG->>SP: async with state_proxy
    SP->>State: Access data["b"]
    State-->>SP: Returns ImmutableMutableProxy
    SP->>SP: state_proxy.data["a"] = state_proxy.data["b"]
    Note over SP: Stores ImmutableMutableProxy to data["a"]

    Note over BG,State: Regular event accesses stored value
    BG->>State: Access wrapped state.data["a"]
    State->>MP: _wrap_recursive(ImmutableMutableProxy)
    MP->>MP: Detect isinstance(value, MutableProxy)
    MP->>MP: Unwrap: value = value.__wrapped__
    MP->>MP: Rewrap with current state reference
    MP-->>State: Return new MutableProxy (not ImmutableMutableProxy)
    Note over MP: State reference properly updated
Loading

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 14, 2026

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing masenf/rebind-proxy2 (52e26b4) with main (ce9b21a)

Open in CodSpeed

@masenf masenf merged commit c441e33 into main Jan 14, 2026
48 checks passed
@masenf masenf deleted the masenf/rebind-proxy2 branch January 14, 2026 22:15
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.

3 participants