fix: initialize result and run_status before try block in send_message (#9265)

Initialize `result` and `run_status` variables before the try block
to prevent UnboundLocalError in the finally block when exceptions
occur early in execution (e.g., during AgentLoop.load()).

Previously, if an exception was raised before `result` was assigned
inside the try block, the finally block would fail when trying to
access `result`, masking the original error with an UnboundLocalError.

This fix ensures the finally block can safely check and use these
variables regardless of when/where an exception occurs.
This commit is contained in:
jnjpng
2026-02-03 15:10:24 -08:00
committed by Caren Thomas
parent 170886b8a8
commit 9bf10b4761

View File

@@ -1579,6 +1579,8 @@ async def send_message(
await redis_client.set(f"{REDIS_RUN_ID_PREFIX}:{agent_id}", run.id if run else None)
run_update_metadata = None
result = None
run_status = None
try:
agent_loop = AgentLoop.load(agent_state=agent, actor=actor)
result = await agent_loop.step(