Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix missing None-check in get_conversations (#8927)

Ray Myersafd8ee61e725
diff --git a/openhands/server/conversation_manager/standalone_conversation_manager.py b/openhands/server/conversation_manager/standalone_conversation_manager.py
index e547f8e5c8..a0b8f9e950 100644
--- a/openhands/server/conversation_manager/standalone_conversation_manager.py
+++ b/openhands/server/conversation_manager/standalone_conversation_manager.py
@@ -111,7 +111,8 @@ class StandaloneConversationManager(ConversationManager):
return None
end_time = time.time()
logger.info(
- f'ServerConversation {c.sid} connected in {end_time - start_time} seconds'
+ f'ServerConversation {c.sid} connected in {end_time - start_time} seconds',
+ extra={'session_id': sid}
)
self._active_conversations[sid] = (c, 1)
return c
diff --git a/openhands/server/routes/conversation.py b/openhands/server/routes/conversation.py
index 5993c83446..1acf3ce992 100644
--- a/openhands/server/routes/conversation.py
+++ b/openhands/server/routes/conversation.py
@@ -145,5 +145,5 @@ async def search_events(
@app.post('/events')
async def add_event(request: Request, conversation: ServerConversation = Depends(get_conversation)):
data = request.json()
- conversation_manager.send_to_event_stream(conversation.sid, data)
+ await conversation_manager.send_to_event_stream(conversation.sid, data)
return JSONResponse({'success': True})
diff --git a/openhands/server/utils.py b/openhands/server/utils.py
index 0bdb94050a..a717870445 100644
--- a/openhands/server/utils.py
+++ b/openhands/server/utils.py
@@ -1,5 +1,6 @@
-from fastapi import Depends, Request
+from fastapi import Depends, HTTPException, Request, status
+from openhands.core.logger import openhands_logger as logger
from openhands.server.shared import ConversationStoreImpl, config, conversation_manager
from openhands.server.user_auth import get_user_id
from openhands.storage.conversation.conversation_store import ConversationStore
@@ -24,6 +25,15 @@ async def get_conversation(
conversation = await conversation_manager.attach_to_conversation(
conversation_id, user_id
)
+ if not conversation:
+ logger.warn(
+ f'get_conversation: conversation {conversation_id} not found, attach_to_conversation returned None',
+ extra={'session_id': conversation_id, 'user_id': user_id},
+ )
+ raise HTTPException(
+ status_code=status.HTTP_404_NOT_FOUND,
+ detail=f'Conversation {conversation_id} not found',
+ )
try:
yield conversation
finally: