Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions openhands/runtime/impl/remote/remote_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ def _get_action_execution_server_host(self):
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
Expand Down
69 changes: 35 additions & 34 deletions openhands/server/session/agent_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,43 @@ async def start(
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"""
Expand Down