Fix missing None-check in get_conversations (#8927)

This commit is contained in:
Ray Myers 2025-06-05 13:55:41 -05:00 committed by GitHub
parent 93b1276768
commit afd8ee61e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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})

View File

@ -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: