Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Dec 19, 2025

STORE_FAST handling is not generally correct outside of the specific case of dealing with imports. So avoid resetting the stack or other issues when we're not importing.

STORE_FAST handling is not generally correct outside of the specific case of
dealing with imports. So avoid resetting the stack or other issues when we're
not importing.
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 19, 2025

CodSpeed Performance Report

Merging #6058 will not alter performance

Comparing masenf/dep-tracker-limit-import-scope (6d38f3b) with main (488a388)

Summary

✅ 8 untouched

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 19, 2025

Greptile Summary

Fixes incorrect STORE_FAST handling in the DependencyTracker by restricting it to import operations only.

  • Added new GETTING_IMPORT status to track when processing import bytecode instructions
  • Modified STORE_FAST handling to only apply when scan_status == ScanStatus.GETTING_IMPORT
  • Prevents incorrect manipulation of tracked_locals when STORE_FAST is used for other purposes (e.g., storing nested functions)
  • Added test case test_nested_function that verifies dependencies are tracked correctly when nested functions are present

The fix addresses a bug where any STORE_FAST instruction with a non-None top_of_stack would trigger import aliasing logic, even when storing non-import values like nested function definitions.

Confidence Score: 3/5

  • This PR fixes an important bug but introduces another issue with missing state reset
  • The fix correctly restricts STORE_FAST handling to import operations, preventing incorrect behavior with nested functions. However, the scan_status is not reset to SCANNING after handling the import STORE_FAST, which could cause subsequent STORE_FAST instructions to incorrectly trigger import handling logic. This follows the pattern used in _eval_get_state (line 309) where status is reset.
  • Pay close attention to reflex/vars/dep_tracking.py - the missing scan_status reset on line 485 needs to be added

Important Files Changed

Filename Overview
reflex/vars/dep_tracking.py Added GETTING_IMPORT status and restricted STORE_FAST handling to imports only. Missing scan_status reset after STORE_FAST could cause state to persist incorrectly.
tests/units/vars/test_dep_tracking.py Added test_nested_function to verify dependencies are tracked correctly in nested functions - validates the fix prevents incorrect STORE_FAST handling.

Sequence Diagram

sequenceDiagram
    participant Tracker as DependencyTracker
    participant Bytecode as Bytecode Instructions
    participant Status as scan_status
    participant Locals as tracked_locals

    Note over Tracker,Locals: Processing Import Statement
    Bytecode->>Tracker: IMPORT_NAME instruction
    Tracker->>Status: Set to GETTING_IMPORT
    Tracker->>Locals: Add module to tracked_locals
    Tracker->>Tracker: Set top_of_stack = module name
    
    Bytecode->>Tracker: STORE_FAST instruction
    Tracker->>Status: Check scan_status == GETTING_IMPORT?
    Status-->>Tracker: Yes
    Tracker->>Locals: Pop and reassign with alias
    Tracker->>Tracker: Reset top_of_stack = None
    Note over Tracker: BUG: scan_status not reset to SCANNING

    Note over Tracker,Locals: Processing Nested Function (After Fix)
    Bytecode->>Tracker: MAKE_FUNCTION instruction
    Bytecode->>Tracker: STORE_FAST instruction (for nested func)
    Tracker->>Status: Check scan_status == GETTING_IMPORT?
    Status-->>Tracker: No (if properly reset)
    Note over Tracker: STORE_FAST skipped - avoids incorrect handling
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. reflex/vars/dep_tracking.py, line 477-485 (link)

    logic: scan_status should be reset to ScanStatus.SCANNING after handling the STORE_FAST, similar to the pattern in _eval_get_state at line 309.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit 2175b3b into main Dec 19, 2025
48 checks passed
@adhami3310 adhami3310 deleted the masenf/dep-tracker-limit-import-scope branch December 19, 2025 19:32
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