From efd81ac2ab46ee0ade95eec8dfc01402320850e2 Mon Sep 17 00:00:00 2001 From: Vinicius Mello Date: Thu, 13 Nov 2025 10:34:19 -0300 Subject: [PATCH] fix(closes OPEN-8001): handle ValueError in _current_step.reset to manage context variable mismatches --- src/openlayer/lib/tracing/tracer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/openlayer/lib/tracing/tracer.py b/src/openlayer/lib/tracing/tracer.py index 32b04df4..37706961 100644 --- a/src/openlayer/lib/tracing/tracer.py +++ b/src/openlayer/lib/tracing/tracer.py @@ -402,7 +402,14 @@ def create_step( latency = (new_step.end_time - new_step.start_time) * 1000 # in ms new_step.latency = latency - _current_step.reset(token) + try: + _current_step.reset(token) + except ValueError as e: + # Handle context variable mismatch gracefully + # This can occur when async generators cross context boundaries + if "was created in a different Context" not in str(e): + raise + _handle_trace_completion( is_root_step=is_root_step, step_name=name,