Skip to content

Commit 0dc9d63

Browse files
committed
Fix missing None-check in get_conversations (#8927)
1 parent 2cea146 commit 0dc9d63

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

openhands/server/conversation_manager/standalone_conversation_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ async def attach_to_conversation(
111111
return None
112112
end_time = time.time()
113113
logger.info(
114-
f'ServerConversation {c.sid} connected in {end_time - start_time} seconds'
114+
f'ServerConversation {c.sid} connected in {end_time - start_time} seconds',
115+
extra={'session_id': sid}
115116
)
116117
self._active_conversations[sid] = (c, 1)
117118
return c

openhands/server/routes/conversation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,5 @@ async def search_events(
145145
@app.post('/events')
146146
async def add_event(request: Request, conversation: ServerConversation = Depends(get_conversation)):
147147
data = request.json()
148-
conversation_manager.send_to_event_stream(conversation.sid, data)
148+
await conversation_manager.send_to_event_stream(conversation.sid, data)
149149
return JSONResponse({'success': True})

openhands/server/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from fastapi import Depends, Request
1+
from fastapi import Depends, HTTPException, Request, status
22

3+
from openhands.core.logger import openhands_logger as logger
34
from openhands.server.shared import ConversationStoreImpl, config, conversation_manager
45
from openhands.server.user_auth import get_user_auth, get_user_id
56
from openhands.storage.conversation.conversation_store import ConversationStore
@@ -25,6 +26,15 @@ async def get_conversation(
2526
conversation = await conversation_manager.attach_to_conversation(
2627
conversation_id, user_id
2728
)
29+
if not conversation:
30+
logger.warn(
31+
f'get_conversation: conversation {conversation_id} not found, attach_to_conversation returned None',
32+
extra={'session_id': conversation_id, 'user_id': user_id},
33+
)
34+
raise HTTPException(
35+
status_code=status.HTTP_404_NOT_FOUND,
36+
detail=f'Conversation {conversation_id} not found',
37+
)
2838
try:
2939
yield conversation
3040
finally:

0 commit comments

Comments
 (0)