All Runtime Status Codes should be in the RuntimeStatus enum (#9601)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Tim O'Farrell
2025-07-09 15:34:46 -06:00
committed by GitHub
parent 1f416f616c
commit cf276b2e96
16 changed files with 121 additions and 76 deletions

View File

@@ -75,6 +75,7 @@ from openhands.events.observation import (
from openhands.events.serialization.event import truncate_content
from openhands.llm.llm import LLM
from openhands.llm.metrics import Metrics
from openhands.runtime.runtime_status import RuntimeStatus
from openhands.storage.files import FileStore
# note: RESUME is only available on web GUI
@@ -248,10 +249,10 @@ class AgentController:
self.state.last_error = f'{type(e).__name__}: {str(e)}'
if self.status_callback is not None:
err_id = ''
runtime_status = RuntimeStatus.ERROR
if isinstance(e, AuthenticationError):
err_id = 'STATUS$ERROR_LLM_AUTHENTICATION'
self.state.last_error = err_id
runtime_status = RuntimeStatus.ERROR_LLM_AUTHENTICATION
self.state.last_error = runtime_status.value
elif isinstance(
e,
(
@@ -260,20 +261,20 @@ class AgentController:
APIError,
),
):
err_id = 'STATUS$ERROR_LLM_SERVICE_UNAVAILABLE'
self.state.last_error = err_id
runtime_status = RuntimeStatus.ERROR_LLM_SERVICE_UNAVAILABLE
self.state.last_error = runtime_status.value
elif isinstance(e, InternalServerError):
err_id = 'STATUS$ERROR_LLM_INTERNAL_SERVER_ERROR'
self.state.last_error = err_id
runtime_status = RuntimeStatus.ERROR_LLM_INTERNAL_SERVER_ERROR
self.state.last_error = runtime_status.value
elif isinstance(e, BadRequestError) and 'ExceededBudget' in str(e):
err_id = 'STATUS$ERROR_LLM_OUT_OF_CREDITS'
self.state.last_error = err_id
runtime_status = RuntimeStatus.ERROR_LLM_OUT_OF_CREDITS
self.state.last_error = runtime_status.value
elif isinstance(e, ContentPolicyViolationError) or (
isinstance(e, BadRequestError)
and 'ContentPolicyViolationError' in str(e)
):
err_id = 'STATUS$ERROR_LLM_CONTENT_POLICY_VIOLATION'
self.state.last_error = err_id
runtime_status = RuntimeStatus.ERROR_LLM_CONTENT_POLICY_VIOLATION
self.state.last_error = runtime_status.value
elif isinstance(e, RateLimitError):
# Check if this is the final retry attempt
if (
@@ -283,14 +284,14 @@ class AgentController:
):
# All retries exhausted, set to ERROR state with a special message
self.state.last_error = (
'CHAT_INTERFACE$AGENT_RATE_LIMITED_STOPPED_MESSAGE'
RuntimeStatus.AGENT_RATE_LIMITED_STOPPED_MESSAGE.value
)
await self.set_agent_state_to(AgentState.ERROR)
else:
# Still retrying, set to RATE_LIMITED state
await self.set_agent_state_to(AgentState.RATE_LIMITED)
return
self.status_callback('error', err_id, self.state.last_error)
self.status_callback('error', runtime_status, self.state.last_error)
# Set the agent state to ERROR after storing the reason
await self.set_agent_state_to(AgentState.ERROR)