fix: create metadata.json when joining conversation if it doesn't exist (#8986)

This commit is contained in:
Mizote Hikaru 2025-06-24 04:05:26 +09:00 committed by GitHub
parent c29b5e9757
commit a156d5d243
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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_title
from 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 metadata
def create_conversation_validator() -> ConversationValidator:
conversation_validator_cls = os.environ.get(