Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix stuck execution flow (#5458)

Engel Nyst287404138154
diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.py
index 8f614745b1..ed253c1710 100644
--- a/openhands/controller/agent_controller.py
+++ b/openhands/controller/agent_controller.py
@@ -454,13 +454,10 @@ class AgentController:
await asyncio.sleep(1)
return
- if self._is_stuck():
- await self._react_to_exception(RuntimeError('Agent got stuck in a loop'))
- return
-
if self.delegate is not None:
assert self.delegate != self
if self.delegate.get_agent_state() == AgentState.PAUSED:
+ # no need to check too often
await asyncio.sleep(1)
else:
await self._delegate_step()
@@ -487,6 +484,10 @@ class AgentController:
if stop_step:
return
+ if self._is_stuck():
+ await self._react_to_exception(RuntimeError('Agent got stuck in a loop'))
+ return
+
self.update_state_before_step()
action: Action = NullAction()
try: