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 @@ -954,7 +954,7 @@ async def navigate_conversation(
)
except ValueError as exc:
# An unknown ``event_id`` against an existing conversation is a 404;
# other ValueErrors (e.g. inactive_service) are genuine server errors.
# other ValueErrors (e.g. ServiceInactive) are genuine server errors.
if "event_id" in str(exc):
raise NotFound(str(exc)) from exc
raise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
LEASE_RENEW_INTERVAL_SECONDS,
EventService,
RunSlot,
ServiceInactive,
)
from openhands.agent_server.experimental_features import (
experimental_feature_tools,
Expand Down Expand Up @@ -779,7 +780,7 @@ async def prepare_for_sandbox_pause(self) -> None:
async with self._exclusive_lifecycle():
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
active_services = tuple(event_services.items())
results = await asyncio.gather(
*(
Expand Down Expand Up @@ -890,7 +891,7 @@ async def _conversation_info(
) -> ConversationInfo | None:
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()

children = (
children_index.get(conversation_id, [])
Expand Down Expand Up @@ -1000,7 +1001,7 @@ async def _refresh_execution_statuses(self) -> None:
"""
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()

targets: list[tuple[UUID, str, tuple[int, int] | None]] = []
for conversation_id, record in list(self._conversation_records.items()):
Expand Down Expand Up @@ -1049,7 +1050,7 @@ async def refresh_persisted_conversation(self, conversation_id: UUID) -> None:
"""Refresh one catalog record changed by an external runtime."""
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
disk_records = await asyncio.to_thread(self._load_catalog_sync, conversation_id)
if conversation_id not in disk_records:
event_service = event_services.get(conversation_id)
Expand All @@ -1069,7 +1070,7 @@ async def _reconcile_active_records(self) -> None:
"""Add injected live services to the in-memory catalog."""
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
for conversation_id, event_service in event_services.items():
if conversation_id in self._conversation_records:
continue
Expand Down Expand Up @@ -1151,7 +1152,7 @@ async def _get_or_load_event_service(
) -> EventService | None:
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
if (
conversation_id not in event_services
and conversation_id not in self._conversation_records
Expand All @@ -1169,7 +1170,7 @@ async def _get_or_load_event_service_locked(
) -> EventService | None:
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()

event_service = event_services.get(conversation_id)
if event_service is not None and event_service.is_open():
Expand Down Expand Up @@ -1204,7 +1205,7 @@ async def _get_or_load_event_service_locked(

async def get_conversation(self, conversation_id: UUID) -> ConversationInfo | None:
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
record = self._conversation_records.get(conversation_id)
if record is None:
event_service = self._event_services.get(conversation_id)
Expand Down Expand Up @@ -1270,7 +1271,7 @@ async def _search_conversations(
sort_order: ConversationSortOrder,
) -> tuple[list[ConversationInfo], str | None]:
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
await self._reconcile_active_records()

if execution_status is not None:
Expand Down Expand Up @@ -1333,7 +1334,7 @@ async def _count_conversations(
) -> int:
"""Count conversations matching the given filters."""
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
await self._reconcile_active_records()

if execution_status is None:
Expand Down Expand Up @@ -1429,7 +1430,7 @@ async def _reuse_existing_conversation_locked(
catalog cannot change between the existence check and the reuse.
"""
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
existing_record = self._conversation_records.get(conversation_id)
existing_event_service = self._event_services.get(conversation_id)
stored = (
Expand Down Expand Up @@ -1576,7 +1577,7 @@ async def _start_conversation(
) -> tuple[ConversationInfo, bool]:
"""Start a local event_service and return its id."""
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
conversation_id = request.conversation_id or uuid4()
if self._has_conversation(conversation_id):
async with self._conversation_lifecycle(conversation_id):
Expand Down Expand Up @@ -1915,7 +1916,7 @@ def _worktree_dir(self, stored: StoredConversation) -> Path | None:
async def delete_conversation(self, conversation_id: UUID) -> bool:
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
if (
conversation_id not in event_services
and conversation_id not in self._conversation_records
Expand Down Expand Up @@ -2056,7 +2057,7 @@ async def get_persisted_event_service(
) -> EventService | None:
"""Open append-only event history without acquiring a runtime lease."""
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()
record = self._conversation_records.get(conversation_id)
if record is None:
return None
Expand Down Expand Up @@ -2121,7 +2122,7 @@ async def fork_conversation(
conversation.
"""
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()

# Reject duplicate fork IDs before fork() writes into its persistence
# directory. The catalog includes both live and unloaded conversations.
Expand Down Expand Up @@ -2222,7 +2223,7 @@ async def start_child_conversation(
Nothing is persisted in that case.
"""
if self._event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()

parent_service = await self._get_or_load_event_service(parent_id)
if parent_service is None:
Expand Down Expand Up @@ -2572,7 +2573,7 @@ async def _start_event_service(
) -> EventService:
event_services = self._event_services
if event_services is None:
raise ValueError("inactive_service")
raise ServiceInactive()

# A new conversation starts with the ``launched`` agent (meta.json does
# not carry it). Otherwise the agent is read from base_state.json, and
Expand Down Expand Up @@ -2639,7 +2640,7 @@ async def _start_event_service(
# even if the system is not shut down gracefully
await event_service.save_meta()
if self._event_services is not event_services:
raise ValueError("inactive_service")
raise ServiceInactive()
state = await event_service.get_state()
except BaseException:
try:
Expand Down
10 changes: 5 additions & 5 deletions openhands-agent-server/openhands/agent_server/event_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
get_settings_store,
)
from openhands.agent_server.errors import error_responses
from openhands.agent_server.event_service import EventService
from openhands.agent_server.event_service import EventService, ServiceInactive
from openhands.agent_server.experimental_features import (
host_experimental_features,
is_enabled,
Expand Down Expand Up @@ -451,9 +451,9 @@ async def react_to_message(
return await event_service.react(
request.emoji, request.target_event_id, removed=request.removed
)
except ServiceInactive:
raise
except ValueError as exc:
if str(exc) == "inactive_service":
raise
raise Invalid(str(exc))


Expand Down Expand Up @@ -498,9 +498,9 @@ async def answer_ask_user(
return await event_service.answer_ask(
request.ask_id, request.option_index, request.text
)
except ServiceInactive:
raise
except ValueError as exc:
if str(exc) == "inactive_service":
raise
raise Invalid(str(exc))


Expand Down
Loading
Loading