Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Agent session no longer stuck in starting on raised exception (#6703)

tofarrcb5e7f0130af
diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.py
index 068461cc61..56b0ec28ca 100644
--- a/openhands/runtime/impl/remote/remote_runtime.py
+++ b/openhands/runtime/impl/remote/remote_runtime.py
@@ -92,8 +92,9 @@ class RemoteRuntime(ActionExecutionClient):
async def connect(self):
try:
await call_sync_from_async(self._start_or_attach_to_runtime)
- except AgentRuntimeNotReadyError:
- self.log('error', 'Runtime failed to start, timed out before ready')
+ except Exception:
+ self.close()
+ self.log('error', 'Runtime failed to start')
raise
await call_sync_from_async(self.setup_initial_env)
self._runtime_initialized = True
diff --git a/openhands/server/session/agent_session.py b/openhands/server/session/agent_session.py
index 31a31bd151..79b9873385 100644
--- a/openhands/server/session/agent_session.py
+++ b/openhands/server/session/agent_session.py
@@ -99,42 +99,43 @@ class AgentSession:
return
self._starting = True
self._started_at = time.time()
- self._create_security_analyzer(config.security.security_analyzer)
- await self._create_runtime(
- runtime_name=runtime_name,
- config=config,
- agent=agent,
- github_token=github_token,
- selected_repository=selected_repository,
- selected_branch=selected_branch,
- )
-
- self.controller = self._create_controller(
- agent,
- config.security.confirmation_mode,
- max_iterations,
- max_budget_per_task=max_budget_per_task,
- agent_to_llm_config=agent_to_llm_config,
- agent_configs=agent_configs,
- )
- if github_token:
- self.event_stream.set_secrets(
- {
- 'github_token': github_token.get_secret_value(),
- }
- )
- if initial_message:
- self.event_stream.add_event(initial_message, EventSource.USER)
- self.event_stream.add_event(
- ChangeAgentStateAction(AgentState.RUNNING), EventSource.ENVIRONMENT
- )
- else:
- self.event_stream.add_event(
- ChangeAgentStateAction(AgentState.AWAITING_USER_INPUT),
- EventSource.ENVIRONMENT,
+ try:
+ self._create_security_analyzer(config.security.security_analyzer)
+ await self._create_runtime(
+ runtime_name=runtime_name,
+ config=config,
+ agent=agent,
+ github_token=github_token,
+ selected_repository=selected_repository,
+ selected_branch=selected_branch,
)
- self._starting = False
+ self.controller = self._create_controller(
+ agent,
+ config.security.confirmation_mode,
+ max_iterations,
+ max_budget_per_task=max_budget_per_task,
+ agent_to_llm_config=agent_to_llm_config,
+ agent_configs=agent_configs,
+ )
+ if github_token:
+ self.event_stream.set_secrets(
+ {
+ 'github_token': github_token.get_secret_value(),
+ }
+ )
+ if initial_message:
+ self.event_stream.add_event(initial_message, EventSource.USER)
+ self.event_stream.add_event(
+ ChangeAgentStateAction(AgentState.RUNNING), EventSource.ENVIRONMENT
+ )
+ else:
+ self.event_stream.add_event(
+ ChangeAgentStateAction(AgentState.AWAITING_USER_INPUT),
+ EventSource.ENVIRONMENT,
+ )
+ finally:
+ self._starting = False
async def close(self):
"""Closes the Agent session"""