Skip to content

Commit 8cc47a1

Browse files
BloggerBustjayanth-kumar-morem
authored andcommitted
fix(runtime): generate stable IDs using accurate user callsites
Previously, `with_render_tracking` would infer a `callsite_hint` using stack inspection when none was provided, which could result in incorrect IDs from stdlib or venv code. This fallback has been removed. Instead, `generate_stable_id` reliably falls back to `get_user_code_callsite`, which filters out venvs and site-packages using absolute path prefixes. This ensures that lifted components without explicit callsite_hint receive stable and user script IDs.
1 parent 4b9a6ad commit 8cc47a1

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

preswald/engine/render_tracking.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,15 @@ def wrapped_with_kwargs(*args, **kwargs):
5454

5555
@wraps(func)
5656
def wrapper(*args, **kwargs):
57-
# Extract a callsite hint for ID generation if not explicitly provided
58-
if "callsite_hint" not in kwargs:
59-
stack = inspect.stack()
60-
for frame in stack:
61-
if "preswald" not in frame.filename:
62-
kwargs["callsite_hint"] = f"{frame.filename}:{frame.lineno}"
63-
break
64-
6557
# Resolve component ID and corresponding atom name
6658
if "component_id" in kwargs:
6759
component_id = kwargs["component_id"]
6860
atom_name = generate_stable_atom_name_from_component_id(component_id)
6961
logger.debug(f"[with_render_tracking] Using provided component_id {component_id}:{atom_name}")
7062
else:
7163
identifier = kwargs.get("identifier")
72-
component_id = generate_stable_id(component_type, callsite_hint=kwargs["callsite_hint"], identifier=identifier)
64+
callsite_hint = kwargs.get("callsite_hint")
65+
component_id = generate_stable_id(component_type, callsite_hint=callsite_hint, identifier=identifier)
7366
atom_name = generate_stable_atom_name_from_component_id(component_id)
7467
kwargs["component_id"] = component_id
7568
logger.debug(f"[with_render_tracking] Generated component_id {component_id}:{atom_name}")

preswald/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ def get_user_code_callsite(exc: BaseException | None = None, fallback: str = "un
154154
preswald_src_dir = os.path.abspath(os.path.join(__file__, ".."))
155155

156156
def is_user_code(filepath: str) -> bool:
157+
filepath = os.path.abspath(filepath)
157158
return not (
158159
filepath.startswith(preswald_src_dir)
159-
or ".venv" in filepath
160-
or "site-packages" in filepath
160+
or filepath.startswith(sys.prefix)
161161
or filepath.startswith(sys.base_prefix)
162+
or "site-packages" in filepath
162163
)
163164

164165
if exc and exc.__traceback__:

0 commit comments

Comments
 (0)