Fix for trace_child_tasks exception handling

I had Claude Fable 5 review our use of contextvar and
it spotted this place where exceptions were not
correctly handled.
This commit is contained in:
Simon Willison 2026-06-12 13:21:58 -07:00
commit d4cb8b464b
2 changed files with 17 additions and 2 deletions

View file

@ -27,8 +27,10 @@ def get_task_id():
@contextmanager
def trace_child_tasks():
token = trace_task_id.set(get_task_id())
yield
trace_task_id.reset(token)
try:
yield
finally:
trace_task_id.reset(token)
@contextmanager