From 45bd48ff6701571fdb031a9c326973def83227d5 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 29 Aug 2026 11:20:05 +0530 Subject: [PATCH] fix: initialize affinity_token before the turn-lease early returns The turn-lease timeout/interrupt paths return from inside the try block before set_affinity_scope() runs; the finally then read an unassigned local -> UnboundLocalError. This was the cause of the 4 red cross-process lease tests on PR #97158's CI. (cherry picked from commit 05a3c8a4caa59831b01d13f3950e61385aadbfa5) --- run_agent.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run_agent.py b/run_agent.py index 72e3000754..61329934f8 100644 --- a/run_agent.py +++ b/run_agent.py @@ -9067,6 +9067,11 @@ class AIAgent: durable_turn_lease_turn_active = False durable_turn_lease_interrupt_message = None token = None + # Initialized alongside `token`: the turn-lease timeout/interrupt + # early returns leave the try block before set_affinity_scope() runs, + # and the finally reads this name unconditionally (UnboundLocalError + # otherwise — the 4 red cross-process lease tests on PR #97158). + affinity_token = None acct_token = None task_started = False task_finished = False