π OpenHands: AI-Driven Development
fix(enterprise): fix type errors - missing returns and async interface (#13145)
Rohit Malhotra4dab34e7b0b4
diff --git a/enterprise/integrations/gitlab/gitlab_view.py b/enterprise/integrations/gitlab/gitlab_view.pyindex 9db884bfdf..bad7e7b451 100644--- a/enterprise/integrations/gitlab/gitlab_view.py+++ b/enterprise/integrations/gitlab/gitlab_view.py@@ -446,3 +446,5 @@ class GitlabFactory:previous_comments=[],is_mr=True,)++ raise ValueError(f'Unhandled GitLab webhook event: {message}')diff --git a/enterprise/integrations/jira_dc/jira_dc_types.py b/enterprise/integrations/jira_dc/jira_dc_types.pyindex 80190ab561..6b18649907 100644--- a/enterprise/integrations/jira_dc/jira_dc_types.py+++ b/enterprise/integrations/jira_dc/jira_dc_types.py@@ -19,7 +19,7 @@ class JiraDcViewInterface(ABC):conversation_id: str@abstractmethod- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Get initial instructions for the conversation."""passdiff --git a/enterprise/integrations/jira_dc/jira_dc_view.py b/enterprise/integrations/jira_dc/jira_dc_view.pyindex 177d071288..6992748380 100644--- a/enterprise/integrations/jira_dc/jira_dc_view.py+++ b/enterprise/integrations/jira_dc/jira_dc_view.py@@ -36,7 +36,7 @@ class JiraDcNewConversationView(JiraDcViewInterface):selected_repo: str | Noneconversation_id: str- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Instructions passed when conversation is first initialized"""instructions_template = jinja_env.get_template('jira_dc_instructions.j2')@@ -61,7 +61,7 @@ class JiraDcNewConversationView(JiraDcViewInterface):provider_tokens = await self.saas_user_auth.get_provider_tokens()user_secrets = await self.saas_user_auth.get_secrets()- instructions, user_msg = self._get_instructions(jinja_env)+ instructions, user_msg = await self._get_instructions(jinja_env)try:agent_loop_info = await create_new_conversation(@@ -113,7 +113,7 @@ class JiraDcExistingConversationView(JiraDcViewInterface):selected_repo: str | Noneconversation_id: str- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Instructions passed when conversation is first initialized"""user_msg_template = jinja_env.get_template('jira_dc_existing_conversation.j2')@@ -167,7 +167,7 @@ class JiraDcExistingConversationView(JiraDcViewInterface):if not agent_state or agent_state == AgentState.LOADING:raise StartingConvoException('Conversation is still starting')- _, user_msg = self._get_instructions(jinja_env)+ _, user_msg = await self._get_instructions(jinja_env)user_message_event = MessageAction(content=user_msg)await conversation_manager.send_event_to_conversation(self.conversation_id, event_to_dict(user_message_event)diff --git a/enterprise/integrations/linear/linear_types.py b/enterprise/integrations/linear/linear_types.pyindex a4e87cb8ed..237fdcb303 100644--- a/enterprise/integrations/linear/linear_types.py+++ b/enterprise/integrations/linear/linear_types.py@@ -19,7 +19,7 @@ class LinearViewInterface(ABC):conversation_id: str@abstractmethod- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Get initial instructions for the conversation."""passdiff --git a/enterprise/integrations/linear/linear_view.py b/enterprise/integrations/linear/linear_view.pyindex 0641c64200..7f8282b705 100644--- a/enterprise/integrations/linear/linear_view.py+++ b/enterprise/integrations/linear/linear_view.py@@ -33,7 +33,7 @@ class LinearNewConversationView(LinearViewInterface):selected_repo: str | Noneconversation_id: str- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Instructions passed when conversation is first initialized"""instructions_template = jinja_env.get_template('linear_instructions.j2')@@ -58,7 +58,7 @@ class LinearNewConversationView(LinearViewInterface):provider_tokens = await self.saas_user_auth.get_provider_tokens()user_secrets = await self.saas_user_auth.get_secrets()- instructions, user_msg = self._get_instructions(jinja_env)+ instructions, user_msg = await self._get_instructions(jinja_env)try:agent_loop_info = await create_new_conversation(@@ -110,7 +110,7 @@ class LinearExistingConversationView(LinearViewInterface):selected_repo: str | Noneconversation_id: str- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Instructions passed when conversation is first initialized"""user_msg_template = jinja_env.get_template('linear_existing_conversation.j2')@@ -164,7 +164,7 @@ class LinearExistingConversationView(LinearViewInterface):if not agent_state or agent_state == AgentState.LOADING:raise StartingConvoException('Conversation is still starting')- _, user_msg = self._get_instructions(jinja_env)+ _, user_msg = await self._get_instructions(jinja_env)user_message_event = MessageAction(content=user_msg)await conversation_manager.send_event_to_conversation(self.conversation_id, event_to_dict(user_message_event)diff --git a/enterprise/integrations/slack/slack_types.py b/enterprise/integrations/slack/slack_types.pyindex c6b11922df..17c375a24c 100644--- a/enterprise/integrations/slack/slack_types.py+++ b/enterprise/integrations/slack/slack_types.py@@ -24,7 +24,7 @@ class SlackViewInterface(SummaryExtractionTracker, ABC):v1_enabled: bool@abstractmethod- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Instructions passed when conversation is first initialized"""passdiff --git a/enterprise/integrations/slack/slack_view.py b/enterprise/integrations/slack/slack_view.pyindex 986ba52233..85c2465b79 100644--- a/enterprise/integrations/slack/slack_view.py+++ b/enterprise/integrations/slack/slack_view.py@@ -75,7 +75,7 @@ class SlackUnkownUserView(SlackViewInterface):team_id: strv1_enabled: bool- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:raise NotImplementedErrorasync def create_or_update_conversation(self, jinja_env: Environment):@@ -118,7 +118,7 @@ class SlackNewConversationView(SlackViewInterface):return block['user_id']return ''- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"""Instructions passed when conversation is first initialized"""user_info: SlackUser = self.slack_to_openhands_user@@ -242,7 +242,9 @@ class SlackNewConversationView(SlackViewInterface):self, jinja: Environment, provider_tokens, user_secrets) -> None:"""Create conversation using the legacy V0 system."""- user_instructions, conversation_instructions = self._get_instructions(jinja)+ user_instructions, conversation_instructions = await self._get_instructions(+ jinja+ )# Determine git provider from repositorygit_provider = None@@ -273,7 +275,9 @@ class SlackNewConversationView(SlackViewInterface):async def _create_v1_conversation(self, jinja: Environment) -> None:"""Create conversation using the new V1 app conversation system."""- user_instructions, conversation_instructions = self._get_instructions(jinja)+ user_instructions, conversation_instructions = await self._get_instructions(+ jinja+ )# Create the initial message requestinitial_message = SendMessageRequest(@@ -346,7 +350,7 @@ class SlackNewConversationFromRepoFormView(SlackNewConversationView):class SlackUpdateExistingConversationView(SlackNewConversationView):slack_conversation: SlackConversation- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:client = WebClient(token=self.bot_access_token)result = client.conversations_replies(channel=self.channel_id,@@ -401,7 +405,7 @@ class SlackUpdateExistingConversationView(SlackNewConversationView):if not agent_state or agent_state == AgentState.LOADING:raise StartingConvoException('Conversation is still starting')- instructions, _ = self._get_instructions(jinja)+ instructions, _ = await self._get_instructions(jinja)user_msg = MessageAction(content=instructions)await conversation_manager.send_event_to_conversation(self.conversation_id, event_to_dict(user_msg)@@ -469,7 +473,7 @@ class SlackUpdateExistingConversationView(SlackNewConversationView):agent_server_url = get_agent_server_url_from_sandbox(running_sandbox)# 4. Prepare the message content- user_msg, _ = self._get_instructions(jinja)+ user_msg, _ = await self._get_instructions(jinja)# 5. Create the message requestsend_message_request = SendMessageRequest(diff --git a/enterprise/integrations/types.py b/enterprise/integrations/types.pyindex c18acb25f6..7b7446fe82 100644--- a/enterprise/integrations/types.py+++ b/enterprise/integrations/types.py@@ -38,7 +38,7 @@ class ResolverViewInterface(SummaryExtractionTracker):is_public_repo: boolraw_payload: dict- def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:+ async def _get_instructions(self, jinja_env: Environment) -> tuple[str, str]:"Instructions passed when conversation is first initialized"raise NotImplementedError()diff --git a/enterprise/storage/org_service.py b/enterprise/storage/org_service.pyindex 00fdf4443e..22bb4360ce 100644--- a/enterprise/storage/org_service.py+++ b/enterprise/storage/org_service.py@@ -3,6 +3,7 @@ Service class for managing organization operations.Separates business logic from route handlers."""+from typing import NoReturnfrom uuid import UUID, uuid4from uuid import UUID as parse_uuid@@ -325,7 +326,7 @@ class OrgService:user_id: str,original_error: Exception,error_message: str,- ) -> None:+ ) -> NoReturn:"""Handle failure by cleaning up LiteLLM resources and raising appropriate error.diff --git a/enterprise/storage/slack_team_store.py b/enterprise/storage/slack_team_store.pyindex df8e2cd65d..95924e769a 100644--- a/enterprise/storage/slack_team_store.py+++ b/enterprise/storage/slack_team_store.py@@ -32,6 +32,7 @@ class SlackTeamStore:# Store the tokensession.add(slack_team)session.commit()+ return slack_team@classmethoddef get_instance(cls):diff --git a/enterprise/tests/unit/integrations/jira_dc/test_jira_dc_view.py b/enterprise/tests/unit/integrations/jira_dc/test_jira_dc_view.pyindex 91865f101d..33d019871e 100644--- a/enterprise/tests/unit/integrations/jira_dc/test_jira_dc_view.py+++ b/enterprise/tests/unit/integrations/jira_dc/test_jira_dc_view.py@@ -18,9 +18,11 @@ from openhands.core.schema.agent import AgentStateclass TestJiraDcNewConversationView:"""Tests for JiraDcNewConversationView"""- def test_get_instructions(self, new_conversation_view, mock_jinja_env):+ async def test_get_instructions(self, new_conversation_view, mock_jinja_env):"""Test _get_instructions method"""- instructions, user_msg = new_conversation_view._get_instructions(mock_jinja_env)+ instructions, user_msg = await new_conversation_view._get_instructions(+ mock_jinja_env+ )assert instructions == 'Test Jira DC instructions template'assert 'PROJ-123' in user_msg@@ -83,9 +85,9 @@ class TestJiraDcNewConversationView:class TestJiraDcExistingConversationView:"""Tests for JiraDcExistingConversationView"""- def test_get_instructions(self, existing_conversation_view, mock_jinja_env):+ async def test_get_instructions(self, existing_conversation_view, mock_jinja_env):"""Test _get_instructions method"""- instructions, user_msg = existing_conversation_view._get_instructions(+ instructions, user_msg = await existing_conversation_view._get_instructions(mock_jinja_env)diff --git a/enterprise/tests/unit/integrations/linear/test_linear_view.py b/enterprise/tests/unit/integrations/linear/test_linear_view.pyindex 05e465e37f..09505aa3fc 100644--- a/enterprise/tests/unit/integrations/linear/test_linear_view.py+++ b/enterprise/tests/unit/integrations/linear/test_linear_view.py@@ -18,9 +18,11 @@ from openhands.core.schema.agent import AgentStateclass TestLinearNewConversationView:"""Tests for LinearNewConversationView"""- def test_get_instructions(self, new_conversation_view, mock_jinja_env):+ async def test_get_instructions(self, new_conversation_view, mock_jinja_env):"""Test _get_instructions method"""- instructions, user_msg = new_conversation_view._get_instructions(mock_jinja_env)+ instructions, user_msg = await new_conversation_view._get_instructions(+ mock_jinja_env+ )assert instructions == 'Test instructions template'assert 'TEST-123' in user_msg@@ -83,9 +85,9 @@ class TestLinearNewConversationView:class TestLinearExistingConversationView:"""Tests for LinearExistingConversationView"""- def test_get_instructions(self, existing_conversation_view, mock_jinja_env):+ async def test_get_instructions(self, existing_conversation_view, mock_jinja_env):"""Test _get_instructions method"""- instructions, user_msg = existing_conversation_view._get_instructions(+ instructions, user_msg = await existing_conversation_view._get_instructions(mock_jinja_env)diff --git a/enterprise/tests/unit/integrations/slack/test_slack_view.py b/enterprise/tests/unit/integrations/slack/test_slack_view.pyindex 99aa60009a..fb1cc6193f 100644--- a/enterprise/tests/unit/integrations/slack/test_slack_view.py+++ b/enterprise/tests/unit/integrations/slack/test_slack_view.py@@ -263,7 +263,9 @@ class TestPausedSandboxResumption:@patch('openhands.app_server.config.get_httpx_client')@patch('openhands.app_server.event_callback.util.ensure_running_sandbox')@patch('openhands.app_server.event_callback.util.get_agent_server_url_from_sandbox')- @patch.object(SlackUpdateExistingConversationView, '_get_instructions')+ @patch.object(+ SlackUpdateExistingConversationView, '_get_instructions', new_callable=AsyncMock+ )async def test_paused_sandbox_resumption(self,mock_get_instructions,