Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
decrypt_incoming_llm_secrets,
)
from openhands.agent_server.conversation_registry import ConversationRegistry
from openhands.agent_server.conversation_service import (
ConversationService,
InvalidParentConversation,
UnavailableAgentTool,
)
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import (
get_cipher,
get_conversation_registry,
get_conversation_service,
get_llm_profile_store,
)
from openhands.agent_server.errors import error_responses
from openhands.agent_server.event_service import CondensationUnavailable
from openhands.agent_server.exceptions import (
CondensationUnavailable,
InvalidParentConversation,
UnavailableAgentTool,
)
from openhands.agent_server.launch import launch_error
from openhands.agent_server.message_sender import SenderError
from openhands.agent_server.models import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
LEASE_RENEW_INTERVAL_SECONDS,
EventService,
RunSlot,
)
from openhands.agent_server.exceptions import (
CredentialBindingActivationRequired,
InvalidParentConversation,
ServiceInactive,
UnavailableAgentTool,
)
from openhands.agent_server.experimental_features import (
experimental_feature_tools,
Expand Down Expand Up @@ -95,7 +100,6 @@
CredentialBindingError,
VersionedCredentialBinding,
)
from openhands.sdk.errors import Conflict
from openhands.sdk.event import MessageEvent
from openhands.sdk.event.conversation_state import ConversationStateUpdateEvent
from openhands.sdk.git.exceptions import GitCommandError, GitRepositoryError
Expand Down Expand Up @@ -124,13 +128,6 @@
SERVER_SHUTDOWN_WS_CLOSE = (1012, "Server shutting down")


class CredentialBindingActivationRequired(Conflict, RuntimeError):
"""A runtime credential binding must be activated first; retry after it."""

def __init__(self, detail: str) -> None:
super().__init__(detail, extra={"retryable": True})


def _build_worktree_guidance(
*,
source_workspace: Path,
Expand Down Expand Up @@ -339,16 +336,6 @@ def _create_conversation_worktree(plan: _WorktreePlan) -> LocalWorkspace:
logger = logging.getLogger(__name__)


class InvalidParentConversation(ValueError):
"""``parent_conversation_id`` is unknown, self-referential, or in
a different workspace."""


class UnavailableAgentTool(ValueError):
"""The agent names a tool whose ``tool_module_qualnames`` module the server
cannot import, so the agent could never be built."""


def _same_workspace(a: LocalWorkspace, b: LocalWorkspace) -> bool:
return Path(a.working_dir).resolve() == Path(b.working_dir).resolve()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import get_conversation_service
from openhands.agent_server.event_service import CredentialBindingActivationTooLate
from openhands.agent_server.exceptions import CredentialBindingActivationTooLate
from openhands.agent_server.persistence import FileSecretsStore, run_store
from openhands.sdk.agent.acp_file_credentials import supports_file_credential_binding
from openhands.sdk.credential import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
get_settings_store,
)
from openhands.agent_server.errors import GatewayTimeout, error_responses
from openhands.agent_server.event_service import EventService, ServiceInactive
from openhands.agent_server.event_service import EventService
from openhands.agent_server.exceptions import ServiceInactive
from openhands.agent_server.experimental_features import (
host_experimental_features,
is_enabled,
Expand Down
30 changes: 6 additions & 24 deletions openhands-agent-server/openhands/agent_server/event_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
ConversationLease,
ConversationOwnershipLostError,
)
from openhands.agent_server.exceptions import (
CondensationUnavailable,
ConversationRunLimitExceeded,
CredentialBindingActivationTooLate,
ServiceInactive,
)
from openhands.agent_server.managed_llm_key import register_managed_llm_key_refresh
from openhands.agent_server.models import (
ConfirmationResponseRequest,
Expand Down Expand Up @@ -75,7 +81,6 @@
HttpVersionedCredentialBinding,
VersionedCredentialBinding,
)
from openhands.sdk.errors import RateLimited
from openhands.sdk.event import (
AgentErrorEvent,
ObservationBaseEvent,
Expand Down Expand Up @@ -135,25 +140,6 @@ def _without_skill_bodies(
return event


class ConversationRunLimitExceeded(RateLimited, RuntimeError):
"""The server has no capacity to start another conversation run."""


class CondensationUnavailable(ValueError):
"""The conversation's agent has no condenser that handles requests."""


class ServiceInactive(ValueError):
"""The service is not running: not started yet, or closing or closed.

It stays a ``ValueError`` with the message ``"inactive_service"``, so
routes and clients see the same error as before; callers catch the type.
"""

def __init__(self) -> None:
super().__init__("inactive_service")


class _RunPermit:
"""Ref-counted permit shared by the chained runs of one admission session."""

Expand Down Expand Up @@ -233,10 +219,6 @@ def __exit__(self, *_exc) -> None:
self.release()


class CredentialBindingActivationTooLate(RuntimeError):
pass


def _log_emit_failure(event_kind: str, future: "asyncio.Future[None]") -> None:
"""Log an event emission that failed inside the executor thread."""
if future.cancelled():
Expand Down
50 changes: 50 additions & 0 deletions openhands-agent-server/openhands/agent_server/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Exceptions the agent server's conversation and event services raise.

Each one names a refusal or a state that callers handle by type. The ones that
subclass an ``openhands.sdk.errors`` category get their HTTP status from
``errors.py``; the ``ValueError`` ones keep the messages they always had, and
routes map them where they are caught.
"""

from openhands.sdk.errors import Conflict, RateLimited


class ServiceInactive(ValueError):
"""The service is not running: not started yet, or closing or closed.

It stays a ``ValueError`` with the message ``"inactive_service"``, so
routes and clients see the same error as before; callers catch the type.
"""

def __init__(self) -> None:
super().__init__("inactive_service")


class ConversationRunLimitExceeded(RateLimited, RuntimeError):
"""The server has no capacity to start another conversation run."""


class CondensationUnavailable(ValueError):
"""The conversation's agent has no condenser that handles requests."""


class InvalidParentConversation(ValueError):
"""``parent_conversation_id`` is unknown, self-referential, or in
a different workspace."""


class UnavailableAgentTool(ValueError):
"""The agent names a tool whose ``tool_module_qualnames`` module the server
cannot import, so the agent could never be built."""


class CredentialBindingActivationRequired(Conflict, RuntimeError):
"""A runtime credential binding must be activated first; retry after it."""

def __init__(self, detail: str) -> None:
super().__init__(detail, extra={"retryable": True})


class CredentialBindingActivationTooLate(RuntimeError):
"""The conversation can no longer take this credential binding in place:
it already has a different one, is not running, or is not an ACP agent."""
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

from openhands.agent_server import sockets
from openhands.agent_server.config import Config
from openhands.agent_server.conversation_service import (
ConversationService,
CredentialBindingActivationRequired,
)
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import get_config, get_conversation_service
from openhands.agent_server.exceptions import CredentialBindingActivationRequired
from openhands.agent_server.pub_sub import MaxSubscribersError, Subscriber
from openhands.agent_server.session_protocol import (
MAX_FRAME_BYTES,
Expand Down
6 changes: 2 additions & 4 deletions openhands-agent-server/openhands/agent_server/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@

from openhands.agent_server.bash_service import BashEventService
from openhands.agent_server.config import Config
from openhands.agent_server.conversation_service import (
ConversationService,
CredentialBindingActivationRequired,
)
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import (
get_config,
get_conversation_service,
get_server_bash_event_service,
)
from openhands.agent_server.event_router import normalize_datetime_to_server_timezone
from openhands.agent_server.exceptions import CredentialBindingActivationRequired
from openhands.agent_server.models import (
BashError,
BashEventBase,
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_server/test_ask_user_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
get_settings_store,
)
from openhands.agent_server.event_router import event_router
from openhands.agent_server.event_service import ServiceInactive
from openhands.agent_server.exceptions import ServiceInactive
from openhands.agent_server.models import StartConversationRequest
from openhands.agent_server.persistence import PersistedSettings, ServerStores
from openhands.sdk import LLM, Agent
Expand Down
3 changes: 2 additions & 1 deletion tests/agent_server/test_conversation_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from openhands.agent_server.conversation_router import conversation_router
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import get_conversation_service
from openhands.agent_server.event_service import EventService, ServiceInactive
from openhands.agent_server.event_service import EventService
from openhands.agent_server.exceptions import ServiceInactive
from openhands.sdk import LLM, Agent, Conversation, LocalConversation, Message
from openhands.sdk.event import ActionEvent, MessageEvent
from openhands.sdk.llm import MessageToolCall, TextContent
Expand Down
9 changes: 3 additions & 6 deletions tests/agent_server/test_conversation_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
from openhands.agent_server.conversation_router import conversation_router
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import get_conversation_service
from openhands.agent_server.event_service import (
CondensationUnavailable,
EventService,
ServiceInactive,
)
from openhands.agent_server.event_service import EventService
from openhands.agent_server.exceptions import CondensationUnavailable, ServiceInactive
from openhands.agent_server.launch import launch_source
from openhands.agent_server.models import (
ConversationInfo,
Expand Down Expand Up @@ -3343,7 +3340,7 @@ def test_start_conversation_unavailable_agent_tool_returns_422(
client, mock_conversation_service
):
"""An agent tool whose module the server cannot import yields 422, not 500."""
from openhands.agent_server.conversation_service import UnavailableAgentTool
from openhands.agent_server.exceptions import UnavailableAgentTool

mock_conversation_service.start_conversation.side_effect = UnavailableAgentTool(
"The agent uses tools whose modules the agent server cannot import: "
Expand Down
4 changes: 2 additions & 2 deletions tests/agent_server/test_conversation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
from openhands.agent_server.conversation_service import (
AutoTitleSubscriber,
ConversationService,
UnavailableAgentTool,
_compose_conversation_info,
_ConversationRecord,
_create_conversation_worktree,
_get_worktree_start_point,
_plan_conversation_worktree,
)
from openhands.agent_server.event_service import EventService, ServiceInactive
from openhands.agent_server.event_service import EventService
from openhands.agent_server.exceptions import ServiceInactive, UnavailableAgentTool
from openhands.agent_server.models import (
ConversationInfo,
ConversationPage,
Expand Down
10 changes: 4 additions & 6 deletions tests/agent_server/test_credential_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@

import openhands.agent_server.event_service as event_service_module
from openhands.agent_server.api import add_domain_error_handler
from openhands.agent_server.conversation_service import (
ConversationService,
CredentialBindingActivationRequired,
)
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.credential_binding import (
LocalVersionedCredentialBinding,
router,
)
from openhands.agent_server.event_service import (
from openhands.agent_server.event_service import EventService
from openhands.agent_server.exceptions import (
CredentialBindingActivationRequired,
CredentialBindingActivationTooLate,
EventService,
)
from openhands.agent_server.models import StartConversationRequest, StoredConversation
from openhands.agent_server.persistence import (
Expand Down
8 changes: 4 additions & 4 deletions tests/agent_server/test_domain_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

from openhands.agent_server.api import _add_exception_handlers
from openhands.agent_server.conversation_lease import ConversationOwnershipLostError
from openhands.agent_server.conversation_service import (
CredentialBindingActivationRequired,
)
from openhands.agent_server.errors import (
ERROR_STATUS,
ForwardedStatus,
error_for_status,
error_responses,
status_for,
)
from openhands.agent_server.event_service import ConversationRunLimitExceeded
from openhands.agent_server.exceptions import (
ConversationRunLimitExceeded,
CredentialBindingActivationRequired,
)
from openhands.sdk.errors import (
Busy,
Conflict,
Expand Down
3 changes: 1 addition & 2 deletions tests/agent_server/test_event_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
from openhands.agent_server.errors import status_for
from openhands.agent_server.event_router import run_gateway_message
from openhands.agent_server.event_service import (
CondensationUnavailable,
EventService,
RunSlot,
ServiceInactive,
_log_emit_failure,
)
from openhands.agent_server.exceptions import CondensationUnavailable, ServiceInactive
from openhands.agent_server.file_router import _create_zip_from_directory
from openhands.agent_server.models import (
ConfirmationResponseRequest,
Expand Down
3 changes: 2 additions & 1 deletion tests/agent_server/test_event_socket_races.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

from openhands.agent_server import session_socket, sockets
from openhands.agent_server.config import Config
from openhands.agent_server.event_service import EventService, ServiceInactive
from openhands.agent_server.event_service import EventService
from openhands.agent_server.exceptions import ServiceInactive
from openhands.agent_server.models import StoredConversation
from openhands.agent_server.pub_sub import PubSub, Subscriber
from openhands.agent_server.server_context import build_server_context
Expand Down
2 changes: 1 addition & 1 deletion tests/agent_server/test_openai_gateway_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from openhands.agent_server.docker_runtime.registry import DockerConversationRegistry
from openhands.agent_server.errors import GatewayTimeout, status_for
from openhands.agent_server.event_router import run_gateway_message
from openhands.agent_server.event_service import ConversationRunLimitExceeded
from openhands.agent_server.exceptions import ConversationRunLimitExceeded
from openhands.agent_server.openai import service as gateway
from openhands.agent_server.persistence import ServerStores
from openhands.sdk.conversation.conversation_stats import ConversationStats
Expand Down
11 changes: 4 additions & 7 deletions tests/agent_server/test_parent_child_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@

from openhands.agent_server.api import add_domain_error_handler
from openhands.agent_server.conversation_router import conversation_router
from openhands.agent_server.conversation_service import (
ConversationService,
InvalidParentConversation,
)
from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.dependencies import get_conversation_service
from openhands.agent_server.event_service import (
from openhands.agent_server.event_service import EventService, RunSlot
from openhands.agent_server.exceptions import (
ConversationRunLimitExceeded,
EventService,
RunSlot,
InvalidParentConversation,
)
from openhands.agent_server.message_sender import SenderError
from openhands.agent_server.models import (
Expand Down
Loading
Loading