Fix goal failure cleanup in Python SDK

This commit is contained in:
Ahmed Ibrahim
2026-06-08 12:13:06 -07:00
parent 079aaa83b1
commit 4557f39923
6 changed files with 66 additions and 22 deletions
+24
View File
@@ -501,6 +501,30 @@ class CodexClient:
"""Pause the active goal used by a logical goal turn."""
return self.thread_goal_set(thread_id, status=ThreadGoalStatus.paused)
def stop_failed_goal(self, state: _GoalOperationState) -> None:
"""Best-effort cleanup after a physical goal turn fails."""
try:
self.pause_goal(state.thread_id)
except Exception:
pass
turn_id = state.current_turn()
if turn_id is None:
return
try:
self.turn_interrupt(state.thread_id, turn_id)
except InvalidRequestError as exc:
if not exc.message.startswith("expected active turn id"):
return
next_turn_id = state.current_turn()
if next_turn_id is None or next_turn_id == turn_id:
return
try:
self.turn_interrupt(state.thread_id, next_turn_id)
except Exception:
pass
except Exception:
pass
def start_goal_operation(
self,
thread_id: str,