Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Remove ConversationMetadata dataclass and use UUID directly (#14176)

Tim O'Farrellb0169342f7b1
diff --git a/enterprise/integrations/github/github_manager.py b/enterprise/integrations/github/github_manager.py
index fc10025e3d..c9f5980b46 100644
--- a/enterprise/integrations/github/github_manager.py
+++ b/enterprise/integrations/github/github_manager.py
@@ -356,7 +356,7 @@ class GithubManager(Manager[GithubViewType]):
)
)
- convo_metadata = await github_view.initialize_new_conversation()
+ conversation_id = await github_view.initialize_new_conversation()
saas_user_auth = await get_saas_user_auth(
github_view.user_info.keycloak_user_id, self.token_manager
@@ -365,20 +365,20 @@ class GithubManager(Manager[GithubViewType]):
await github_view.create_new_conversation(
self.jinja_env,
secret_store.provider_tokens,
- convo_metadata,
+ conversation_id,
saas_user_auth,
)
- conversation_id = github_view.conversation_id
+ conversation_id_hex = github_view.conversation_id
logger.info(
- f'[GitHub] Created conversation {conversation_id} for user {user_info.username}'
+ f'[GitHub] Created conversation {conversation_id_hex} for user {user_info.username}'
)
# V1 callback processors are registered by the view during conversation creation
# Send message with conversation link
- conversation_link = CONVERSATION_URL.format(conversation_id)
+ conversation_link = CONVERSATION_URL.format(conversation_id_hex)
msg_info = f"I'm on it! {user_info.username} can [track my progress at all-hands.dev]({conversation_link})"
except MissingSettingsError as e:
diff --git a/enterprise/integrations/github/github_view.py b/enterprise/integrations/github/github_view.py
index 6a64ad67b1..81328294ca 100644
--- a/enterprise/integrations/github/github_view.py
+++ b/enterprise/integrations/github/github_view.py
@@ -31,6 +31,7 @@ from openhands.agent_server.models import SendMessageRequest
from openhands.app_server.app_conversation.app_conversation_models import (
AppConversationStartRequest,
AppConversationStartTaskStatus,
+ ConversationTrigger,
)
from openhands.app_server.config import get_app_conversation_service
from openhands.app_server.services.injector import InjectorState
@@ -41,10 +42,6 @@ from openhands.integrations.provider import PROVIDER_TOKEN_TYPE, ProviderType
from openhands.integrations.service_types import Comment
from openhands.sdk import TextContent
from openhands.server.user_auth.user_auth import UserAuth
-from openhands.storage.data_models.conversation_metadata import (
- ConversationMetadata,
- ConversationTrigger,
-)
from openhands.utils.async_utils import call_sync_from_async
OH_LABEL, INLINE_OH_LABEL = get_oh_labels(HOST)
@@ -143,7 +140,7 @@ class GithubIssue(ResolverViewInterface):
return user_secrets.custom_secrets if user_secrets else None
- async def initialize_new_conversation(self) -> ConversationMetadata:
+ async def initialize_new_conversation(self) -> UUID:
# Resolve target org based on claimed git organizations
self.resolved_org_id = await resolve_org_for_repo(
provider='github',
@@ -152,23 +149,19 @@ class GithubIssue(ResolverViewInterface):
)
# All conversations use V1 app conversation service
- self.conversation_id = uuid4().hex
- return ConversationMetadata(
- conversation_id=self.conversation_id,
- selected_repository=self.full_repo_name,
- )
+ conversation_id = uuid4()
+ self.conversation_id = conversation_id.hex
+ return conversation_id
async def create_new_conversation(
self,
jinja_env: Environment,
git_provider_tokens: PROVIDER_TOKEN_TYPE,
- conversation_metadata: ConversationMetadata,
+ conversation_id: UUID,
saas_user_auth: UserAuth,
):
# V0 conversation path has been removed - all conversations use V1 app conversation service
- await self._create_v1_conversation(
- jinja_env, saas_user_auth, conversation_metadata
- )
+ await self._create_v1_conversation(jinja_env, saas_user_auth, conversation_id)
async def _get_v1_initial_user_message(self, jinja_env: Environment) -> str:
"""Build the initial user message for V1 resolver conversations.
@@ -196,7 +189,7 @@ class GithubIssue(ResolverViewInterface):
self,
jinja_env: Environment,
saas_user_auth: UserAuth,
- conversation_metadata: ConversationMetadata,
+ conversation_id: UUID,
):
"""Create conversation using the new V1 app conversation system."""
logger.info('[GitHub V1]: Creating V1 conversation')
@@ -216,7 +209,7 @@ class GithubIssue(ResolverViewInterface):
# Create the V1 conversation start request with the callback processor
start_request = AppConversationStartRequest(
- conversation_id=UUID(conversation_metadata.conversation_id),
+ conversation_id=conversation_id,
# NOTE: Resolver instructions are intended to be lower priority than the
# system prompt, so we inject them into the initial user message.
system_message_suffix=None,
diff --git a/enterprise/integrations/gitlab/gitlab_manager.py b/enterprise/integrations/gitlab/gitlab_manager.py
index e23d67aeb9..34ffc90ebe 100644
--- a/enterprise/integrations/gitlab/gitlab_manager.py
+++ b/enterprise/integrations/gitlab/gitlab_manager.py
@@ -208,8 +208,8 @@ class GitlabManager(Manager[GitlabViewType]):
)
)
- # Initialize conversation and get metadata (following GitHub pattern)
- convo_metadata = await gitlab_view.initialize_new_conversation()
+ # Initialize conversation and get UUID
+ conversation_id = await gitlab_view.initialize_new_conversation()
saas_user_auth = await get_saas_user_auth(
gitlab_view.user_info.keycloak_user_id, self.token_manager
@@ -218,19 +218,19 @@ class GitlabManager(Manager[GitlabViewType]):
await gitlab_view.create_new_conversation(
self.jinja_env,
secret_store.provider_tokens,
- convo_metadata,
+ conversation_id,
saas_user_auth,
)
- conversation_id = gitlab_view.conversation_id
+ conversation_id_hex = gitlab_view.conversation_id
logger.info(
- f'[GitLab] Created conversation {conversation_id} for user {user_info.username}'
+ f'[GitLab] Created conversation {conversation_id_hex} for user {user_info.username}'
)
# V1 callback processors are registered by the view during conversation creation
- conversation_link = CONVERSATION_URL.format(conversation_id)
+ conversation_link = CONVERSATION_URL.format(conversation_id_hex)
msg_info = f"I'm on it! {user_info.username} can [track my progress at all-hands.dev]({conversation_link})"
except MissingSettingsError as e:
diff --git a/enterprise/integrations/gitlab/gitlab_view.py b/enterprise/integrations/gitlab/gitlab_view.py
index d4295c3361..25a60bfcd5 100644
--- a/enterprise/integrations/gitlab/gitlab_view.py
+++ b/enterprise/integrations/gitlab/gitlab_view.py
@@ -19,6 +19,7 @@ from openhands.agent_server.models import SendMessageRequest
from openhands.app_server.app_conversation.app_conversation_models import (
AppConversationStartRequest,
AppConversationStartTaskStatus,
+ ConversationTrigger,
)
from openhands.app_server.config import get_app_conversation_service
from openhands.app_server.services.injector import InjectorState
@@ -29,10 +30,6 @@ from openhands.integrations.provider import PROVIDER_TOKEN_TYPE, ProviderType
from openhands.integrations.service_types import Comment
from openhands.sdk import TextContent
from openhands.server.user_auth.user_auth import UserAuth
-from openhands.storage.data_models.conversation_metadata import (
- ConversationMetadata,
- ConversationTrigger,
-)
OH_LABEL, INLINE_OH_LABEL = get_oh_labels(HOST)
CONFIDENTIAL_NOTE = 'confidential_note'
@@ -105,7 +102,7 @@ class GitlabIssue(ResolverViewInterface):
return user_secrets.custom_secrets if user_secrets else None
- async def initialize_new_conversation(self) -> ConversationMetadata:
+ async def initialize_new_conversation(self) -> UUID:
# Resolve target org based on claimed git organizations
self.resolved_org_id = await resolve_org_for_repo(
provider='gitlab',
@@ -114,29 +111,25 @@ class GitlabIssue(ResolverViewInterface):
)
# All conversations use V1 app conversation service
- self.conversation_id = uuid4().hex
- return ConversationMetadata(
- conversation_id=self.conversation_id,
- selected_repository=self.full_repo_name,
- )
+ conversation_id = uuid4()
+ self.conversation_id = conversation_id.hex
+ return conversation_id
async def create_new_conversation(
self,
jinja_env: Environment,
git_provider_tokens: PROVIDER_TOKEN_TYPE,
- conversation_metadata: ConversationMetadata,
+ conversation_id: UUID,
saas_user_auth: UserAuth,
):
# V0 conversation path has been removed - all conversations use V1 app conversation service
- await self._create_v1_conversation(
- jinja_env, saas_user_auth, conversation_metadata
- )
+ await self._create_v1_conversation(jinja_env, saas_user_auth, conversation_id)
async def _create_v1_conversation(
self,
jinja_env: Environment,
saas_user_auth: UserAuth,
- conversation_metadata: ConversationMetadata,
+ conversation_id: UUID,
):
"""Create conversation using the new V1 app conversation system."""
logger.info('[GitLab V1]: Creating V1 conversation')
@@ -162,7 +155,7 @@ class GitlabIssue(ResolverViewInterface):
# Create the V1 conversation start request with the callback processor
start_request = AppConversationStartRequest(
- conversation_id=UUID(conversation_metadata.conversation_id),
+ conversation_id=conversation_id,
system_message_suffix=conversation_instructions,
initial_message=initial_message,
selected_repository=self.full_repo_name,
diff --git a/enterprise/integrations/jira/jira_view.py b/enterprise/integrations/jira/jira_view.py
index 5088a4e1e1..45f3a4c817 100644
--- a/enterprise/integrations/jira/jira_view.py
+++ b/enterprise/integrations/jira/jira_view.py
@@ -35,6 +35,7 @@ from openhands.agent_server.models import SendMessageRequest
from openhands.app_server.app_conversation.app_conversation_models import (
AppConversationStartRequest,
AppConversationStartTaskStatus,
+ ConversationTrigger,
)
from openhands.app_server.config import get_app_conversation_service
from openhands.app_server.services.injector import InjectorState
@@ -43,10 +44,6 @@ from openhands.core.logger import openhands_logger as logger
from openhands.integrations.provider import ProviderHandler, ProviderType
from openhands.sdk import TextContent
from openhands.server.user_auth.user_auth import UserAuth
-from openhands.storage.data_models.conversation_metadata import (
- ConversationMetadata,
- ConversationTrigger,
-)
from openhands.utils.http_session import httpx_verify_option
JIRA_CLOUD_API_URL = 'https://api.atlassian.com/ex/jira'
@@ -192,32 +189,30 @@ class JiraNewConversationView(JiraViewInterface):
)
await integration_store.create_conversation(jira_conversation)
- conversation_metadata = await self._create_v1_metadata()
- await self._create_v1_conversation(jinja_env, conversation_metadata)
+ conversation_id = await self._initialize_conversation()
+ await self._create_v1_conversation(jinja_env, conversation_id)
return self.conversation_id
- async def _create_v1_metadata(self) -> ConversationMetadata:
- """Create conversation metadata for V1 conversations.
+ async def _initialize_conversation(self) -> UUID:
+ """Initialize conversation and return the conversation ID.
The JiraConversation mapping is saved to the integration store (above), but
V1 conversation metadata is managed by the app conversation system, not
the legacy conversation store.
"""
- logger.info('[Jira]: Creating V1 metadata')
+ logger.info('[Jira]: Initializing V1 conversation')
- # Generate a dummy conversation for V1 (not saved to store)
- self.conversation_id = uuid4().hex
+ # Generate a conversation ID for V1
+ conversation_id = uuid4()
+ self.conversation_id = conversation_id.hex
self.resolved_org_id = await self._get_resolved_org_id()
- return ConversationMetadata(
- conversation_id=self.conversation_id,
- selected_repository=self.selected_repo,
- )
+ return conversation_id
async def _create_v1_conversation(
self,
jinja_env: Environment,
- conversation_metadata: ConversationMetadata,
+ conversation_id: UUID,
):
"""Create conversation using the new V1 app conversation system."""
logger.info('[Jira]: Creating V1 conversation')
@@ -236,7 +231,7 @@ class JiraNewConversationView(JiraViewInterface):
# Create the V1 conversation start request
start_request = AppConversationStartRequest(
- conversation_id=UUID(conversation_metadata.conversation_id),
+ conversation_id=conversation_id,
system_message_suffix=None,
initial_message=initial_message,
selected_repository=self.selected_repo,
diff --git a/enterprise/integrations/jira_dc/jira_dc_view.py b/enterprise/integrations/jira_dc/jira_dc_view.py
index f6d32a18fd..4f4cc0d2e8 100644
--- a/enterprise/integrations/jira_dc/jira_dc_view.py
+++ b/enterprise/integrations/jira_dc/jira_dc_view.py
@@ -27,6 +27,7 @@ from openhands.agent_server.models import SendMessageRequest
from openhands.app_server.app_conversation.app_conversation_models import (
AppConversationStartRequest,
AppConversationStartTaskStatus,
+ ConversationTrigger,
)
from openhands.app_server.config import get_app_conversation_service
from openhands.app_server.services.injector import InjectorState
@@ -35,9 +36,6 @@ from openhands.core.logger import openhands_logger as logger
from openhands.integrations.provider import ProviderHandler, ProviderType
from openhands.sdk import TextContent
from openhands.server.user_auth.user_auth import UserAuth
-from openhands.storage.data_models.conversation_metadata import (
- ConversationTrigger,
-)
integration_store = JiraDcIntegrationStore.get_instance()
diff --git a/enterprise/integrations/slack/slack_view.py b/enterprise/integrations/slack/slack_view.py
index c5dedfad4f..a773d7f12f 100644
--- a/enterprise/integrations/slack/slack_view.py
+++ b/enterprise/integrations/slack/slack_view.py
@@ -24,6 +24,7 @@ from storage.slack_user import SlackUser
from openhands.app_server.app_conversation.app_conversation_models import (
AppConversationStartRequest,
AppConversationStartTaskStatus,
+ ConversationTrigger,
SendMessageRequest,
)
from openhands.app_server.config import get_app_conversation_service
@@ -34,9 +35,6 @@ from openhands.core.logger import openhands_logger as logger
from openhands.integrations.provider import ProviderHandler
from openhands.sdk import TextContent
from openhands.server.user_auth.user_auth import UserAuth
-from openhands.storage.data_models.conversation_metadata import (
- ConversationTrigger,
-)
from openhands.utils.async_utils import GENERAL_TIMEOUT
# =================================================
diff --git a/enterprise/integrations/types.py b/enterprise/integrations/types.py
index 6ecd83a93e..4de80c8a0d 100644
--- a/enterprise/integrations/types.py
+++ b/enterprise/integrations/types.py
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from enum import Enum
from typing import TYPE_CHECKING
+from uuid import UUID
from jinja2 import Environment
from pydantic import BaseModel
@@ -10,7 +11,6 @@ if TYPE_CHECKING:
from openhands.integrations.provider import PROVIDER_TOKEN_TYPE
from openhands.server.user_auth.user_auth import UserAuth
- from openhands.storage.data_models.conversation_metadata import ConversationMetadata
class GitLabResourceType(Enum):
@@ -53,11 +53,11 @@ class ResolverViewInterface(SummaryExtractionTracker):
"""Instructions passed when conversation is first initialized."""
raise NotImplementedError()
- async def initialize_new_conversation(self) -> 'ConversationMetadata':
- """Initialize a new conversation and return metadata.
+ async def initialize_new_conversation(self) -> UUID:
+ """Initialize a new conversation and return the conversation ID.
- For V1 conversations, creates a dummy ConversationMetadata.
- For V0 conversations, initializes through the conversation store.
+ This method resolves the target organization and generates a new
+ conversation ID.
"""
raise NotImplementedError()
@@ -65,7 +65,7 @@ class ResolverViewInterface(SummaryExtractionTracker):
self,
jinja_env: Environment,
git_provider_tokens: 'PROVIDER_TOKEN_TYPE',
- conversation_metadata: 'ConversationMetadata',
+ conversation_id: UUID,
saas_user_auth: 'UserAuth',
) -> None:
"""Create a new conversation.
@@ -73,7 +73,7 @@ class ResolverViewInterface(SummaryExtractionTracker):
Args:
jinja_env: Jinja2 environment for template rendering
git_provider_tokens: Token mapping for git providers
- conversation_metadata: Metadata for the conversation
+ conversation_id: The UUID of the conversation to create
saas_user_auth: User authentication for SaaS
"""
raise NotImplementedError()
diff --git a/enterprise/tests/unit/integrations/github/test_github_view_v1_initial_user_message.py b/enterprise/tests/unit/integrations/github/test_github_view_v1_initial_user_message.py
index 2aa73dd5d2..c0485340cc 100644
--- a/enterprise/tests/unit/integrations/github/test_github_view_v1_initial_user_message.py
+++ b/enterprise/tests/unit/integrations/github/test_github_view_v1_initial_user_message.py
@@ -3,7 +3,7 @@ from __future__ import annotations
from contextlib import asynccontextmanager
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch
-from uuid import uuid4
+from uuid import UUID, uuid4
import pytest
from integrations.github.github_view import (
@@ -17,7 +17,6 @@ from jinja2 import Environment, FileSystemLoader
from openhands.app_server.app_conversation.app_conversation_models import (
AppConversationStartTaskStatus,
)
-from openhands.storage.data_models.conversation_metadata import ConversationMetadata
@pytest.fixture
@@ -44,11 +43,8 @@ class _FakeAppConversationService:
yield MagicMock(status=AppConversationStartTaskStatus.READY, detail=None)
-def _build_conversation_metadata() -> ConversationMetadata:
- return ConversationMetadata(
- conversation_id=str(uuid4()),
- selected_repository='test-owner/test-repo',
- )
+def _build_conversation_id() -> UUID:
+ return uuid4()
def _build_user_data() -> UserData:
@@ -97,7 +93,7 @@ class TestGithubViewV1InitialUserMessage:
await view._create_v1_conversation(
jinja_env=jinja_env,
saas_user_auth=MagicMock(),
- conversation_metadata=_build_conversation_metadata(),
+ conversation_id=_build_conversation_id(),
)
assert len(fake_service.requests) == 1
@@ -153,7 +149,7 @@ class TestGithubViewV1InitialUserMessage:
await view._create_v1_conversation(
jinja_env=jinja_env,
saas_user_auth=MagicMock(),
- conversation_metadata=_build_conversation_metadata(),
+ conversation_id=_build_conversation_id(),
)
assert len(fake_service.requests) == 1
@@ -207,7 +203,7 @@ class TestGithubViewV1InitialUserMessage:
await view._create_v1_conversation(
jinja_env=jinja_env,
saas_user_auth=MagicMock(),
- conversation_metadata=_build_conversation_metadata(),
+ conversation_id=_build_conversation_id(),
)
req = fake_service.requests[0]
diff --git a/enterprise/tests/unit/integrations/gitlab/test_gitlab_manager.py b/enterprise/tests/unit/integrations/gitlab/test_gitlab_manager.py
index 9779a7a574..98a3f8c856 100644
--- a/enterprise/tests/unit/integrations/gitlab/test_gitlab_manager.py
+++ b/enterprise/tests/unit/integrations/gitlab/test_gitlab_manager.py
@@ -5,13 +5,12 @@ All conversations now use V1 app conversation system.
"""
from unittest.mock import AsyncMock, MagicMock, patch
+from uuid import uuid4
import pytest
from integrations.gitlab.gitlab_view import GitlabIssue
from integrations.types import UserData
-from openhands.storage.data_models.conversation_metadata import ConversationMetadata
-
@pytest.fixture
def mock_gitlab_view():
@@ -56,12 +55,9 @@ def mock_saas_user_auth():
@pytest.fixture
-def mock_convo_metadata():
- """Create a mock ConversationMetadata."""
- return ConversationMetadata(
- conversation_id='test_conversation_id',
- selected_repository='test-group/test-repo',
- )
+def mock_conversation_id():
+ """Create a mock conversation UUID."""
+ return uuid4()
class TestGitlabManagerJobCreation:
@@ -80,7 +76,7 @@ class TestGitlabManagerJobCreation:
mock_token_manager,
mock_gitlab_view,
mock_saas_user_auth,
- mock_convo_metadata,
+ mock_conversation_id,
):
"""Test that start_job creates a conversation and sends acknowledgment message."""
from integrations.gitlab.gitlab_manager import GitlabManager
@@ -90,7 +86,7 @@ class TestGitlabManagerJobCreation:
# Mock the view's methods
mock_gitlab_view.initialize_new_conversation = AsyncMock(
- return_value=mock_convo_metadata
+ return_value=mock_conversation_id
)
mock_gitlab_view.create_new_conversation = AsyncMock()
diff --git a/enterprise/tests/unit/integrations/jira/test_jira_view.py b/enterprise/tests/unit/integrations/jira/test_jira_view.py
index eced07503f..248baac085 100644
--- a/enterprise/tests/unit/integrations/jira/test_jira_view.py
+++ b/enterprise/tests/unit/integrations/jira/test_jira_view.py
@@ -444,10 +444,10 @@ class TestJiraV1Conversation:
"""Tests for V1 conversation creation and callback processor registration."""
@pytest.mark.asyncio
- async def test_create_v1_metadata_generates_conversation_id(
+ async def test_initialize_conversation_generates_conversation_id(
self, new_conversation_view
):
- """Test that _create_v1_metadata generates a new conversation ID."""
+ """Test that _initialize_conversation generates a new conversation ID."""
new_conversation_view.conversation_id = ''
with patch.object(
@@ -455,17 +455,19 @@ class TestJiraV1Conversation:
) as mock_get_org:
mock_get_org.return_value = None
- metadata = await new_conversation_view._create_v1_metadata()
+ conversation_id = await new_conversation_view._initialize_conversation()
# Conversation ID should be generated
assert new_conversation_view.conversation_id != ''
assert len(new_conversation_view.conversation_id) == 32 # UUID hex format
- assert metadata.conversation_id == new_conversation_view.conversation_id
+ assert conversation_id.hex == new_conversation_view.conversation_id
mock_get_org.assert_called_once()
@pytest.mark.asyncio
- async def test_create_v1_metadata_sets_resolved_org(self, new_conversation_view):
- """Test that _create_v1_metadata sets resolved_org_id."""
+ async def test_initialize_conversation_sets_resolved_org(
+ self, new_conversation_view
+ ):
+ """Test that _initialize_conversation sets resolved_org_id."""
from uuid import UUID
test_org_id = UUID('12345678-1234-5678-1234-567812345678')
@@ -475,7 +477,7 @@ class TestJiraV1Conversation:
) as mock_get_org:
mock_get_org.return_value = test_org_id
- await new_conversation_view._create_v1_metadata()
+ await new_conversation_view._initialize_conversation()
assert new_conversation_view.resolved_org_id == test_org_id
diff --git a/openhands/storage/data_models/conversation_metadata.py b/openhands/storage/data_models/conversation_metadata.py
deleted file mode 100644
index 8f3c6718f6..0000000000
--- a/openhands/storage/data_models/conversation_metadata.py
+++ /dev/null
@@ -1,36 +0,0 @@
-from dataclasses import dataclass, field
-from datetime import datetime, timezone
-
-from openhands.app_server.app_conversation.app_conversation_models import (
- ConversationTrigger,
-)
-from openhands.integrations.service_types import ProviderType
-
-# Re-export for backward compatibility
-__all__ = ['ConversationTrigger', 'ConversationMetadata']
-
-
-@dataclass
-class ConversationMetadata:
- conversation_id: str
- selected_repository: str | None
- user_id: str | None = None
- selected_branch: str | None = None
- git_provider: ProviderType | None = None
- title: str | None = None
- last_updated_at: datetime | None = None
- trigger: ConversationTrigger | None = None
- pr_number: list[int] = field(default_factory=list)
- created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
- llm_model: str | None = None
- # Cost and token metrics
- accumulated_cost: float = 0.0
- prompt_tokens: int = 0
- completion_tokens: int = 0
- total_tokens: int = 0
- # Tags for automation/plugin context (key-value pairs stored as JSON)
- tags: dict[str, str] | None = None
- # V1 compatibility
- sandbox_id: str | None = None
- conversation_version: str | None = None
- public: bool | None = None