π OpenHands: AI-Driven Development
fix: create metadata.json when joining conversation if it doesn't exist (#8986)
Mizote Hikarua156d5d2437b
diff --git a/openhands/storage/conversation/conversation_validator.py b/openhands/storage/conversation/conversation_validator.pyindex 84f0f40808..1690bf165b 100644--- a/openhands/storage/conversation/conversation_validator.py+++ b/openhands/storage/conversation/conversation_validator.py@@ -1,5 +1,12 @@import os+from datetime import datetime, timezone+from openhands.core.config.utils import load_openhands_config+from openhands.core.logger import openhands_logger as logger+from openhands.server.config.server_config import ServerConfig+from openhands.storage.conversation.conversation_store import ConversationStore+from openhands.storage.data_models.conversation_metadata import ConversationMetadata+from openhands.utils.conversation_summary import get_default_conversation_titlefrom openhands.utils.import_utils import get_impl@@ -23,8 +30,44 @@ class ConversationValidator:cookies_str: str,authorization_header: str | None = None,) -> str | None:- return None+ user_id = None+ metadata = await self._ensure_metadata_exists(conversation_id, user_id)+ return metadata.user_id+ async def _ensure_metadata_exists(+ self,+ conversation_id: str,+ user_id: str | None,+ ) -> ConversationMetadata:+++ config = load_openhands_config()+ server_config = ServerConfig()++ conversation_store_class: type[ConversationStore] = get_impl(+ ConversationStore,+ server_config.conversation_store_class,+ )+ conversation_store = await conversation_store_class.get_instance(config, user_id)++ try:+ metadata = await conversation_store.get_metadata(conversation_id)+ except FileNotFoundError:+ logger.info(+ f'Creating new conversation metadata for {conversation_id}',+ extra={'session_id': conversation_id}+ )+ await conversation_store.save_metadata(+ ConversationMetadata(+ conversation_id=conversation_id,+ user_id=user_id,+ title=get_default_conversation_title(conversation_id),+ last_updated_at=datetime.now(timezone.utc),+ selected_repository=None,+ )+ )+ metadata = await conversation_store.get_metadata(conversation_id)+ return metadatadef create_conversation_validator() -> ConversationValidator:conversation_validator_cls = os.environ.get(