Compare commits

...

2 Commits

Author SHA1 Message Date
amanape
0b13903453 Update conversation management and frontend hooks
Co-authored-by: openhands <openhands@all-hands.dev>
2025-08-07 23:47:03 +04:00
amanape
3b88fd0d63 fix: fetch full conversation data for WebSocket connection
The createConversation API returns ConversationResponse which lacks the url
and session_api_key fields needed for WebSocket connection. This causes
WebSocket connections to fail in SaaS environments where runtime pods have
specific URLs like https://runtime-123.prod-runtime.all-hands.dev.

This fix:
- Fetches the full Conversation object after creation using getConversation()
- Uses the proper url and session_api_key from the loaded conversation
- Includes fallback to original behavior if fetching fails
- Resolves missing toast notifications due to failed WebSocket connections

Root cause: Backend POST /api/conversations returns ConversationResponse
(no url/session_api_key) but WebSocket connection requires these fields
from the full Conversation object.

Co-authored-by: openhands <openhands@all-hands.dev>
2025-08-07 23:17:00 +04:00
2 changed files with 19 additions and 7 deletions

View File

@@ -58,7 +58,6 @@ export const useCreateConversationAndSubscribeMultiple = () => {
window?.location.host;
}
// Subscribe to the conversation
subscribeToConversation({
conversationId: data.conversation_id,
sessionApiKey: data.session_api_key,
@@ -67,7 +66,6 @@ export const useCreateConversationAndSubscribeMultiple = () => {
onEvent: onEventCallback,
});
// Call the success callback if provided
if (onSuccessCallback) {
onSuccessCallback(data.conversation_id);
}

View File

@@ -112,7 +112,7 @@ async def new_conversation(
provider_tokens: PROVIDER_TOKEN_TYPE = Depends(get_provider_tokens),
user_secrets: UserSecrets = Depends(get_user_secrets),
auth_type: AuthType | None = Depends(get_auth_type),
) -> ConversationResponse:
) -> ConversationInfo | ConversationResponse:
"""Initialize a new session or join an existing one.
After successful initialization, the client should connect to the WebSocket
@@ -180,11 +180,25 @@ async def new_conversation(
conversation_id=conversation_id,
)
return ConversationResponse(
status='ok',
conversation_id=conversation_id,
conversation_status=agent_loop_info.status,
# Get the conversation metadata to return full conversation info
conversation_store = await ConversationStoreImpl.get_instance(config, user_id)
metadata = await conversation_store.get_metadata(conversation_id)
# Return full conversation info instead of just ConversationResponse
# This includes url and session_api_key needed for WebSocket connection
conversation_info = await _get_conversation_info(
metadata, 0, agent_loop_info # num_connections=0 for new conversation
)
if conversation_info is None:
# Fallback to original response if conversation info creation fails
return ConversationResponse(
status='ok',
conversation_id=conversation_id,
conversation_status=agent_loop_info.status,
)
return conversation_info
except MissingSettingsError as e:
return JSONResponse(
content={