Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix closing sessions #6114

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
3e364cb
Closing stale sessions
tofarr Jan 6, 2025
18f02e7
Merge branch 'main' into fix-closing-sessions
tofarr Jan 6, 2025
3750e5e
User id
tofarr Jan 6, 2025
753c054
Added user_id to session
tofarr Jan 6, 2025
80603e4
WIP
tofarr Jan 6, 2025
3e5ad1a
Merge branch 'main' into fix-closing-sessions
tofarr Jan 6, 2025
187b3e8
Refactor conversations
tofarr Jan 7, 2025
7c55584
Closing existing session
tofarr Jan 7, 2025
eb3bb1b
Fix test
tofarr Jan 7, 2025
675a9a0
Test fixes
tofarr Jan 7, 2025
882a7e7
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
1845a41
WIP
tofarr Jan 7, 2025
c78c549
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
559fa85
Emit stopped event when stopping session
tofarr Jan 7, 2025
48e27a4
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
b2a0de2
WIP
tofarr Jan 7, 2025
7910c12
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
9c649fc
Changed name as suggested
tofarr Jan 7, 2025
bf9cd2a
Merge branch 'fix-closing-sessions' of github.com:All-Hands-AI/OpenHa…
tofarr Jan 7, 2025
8ff5e95
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
be9eaac
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
bab53a0
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
88af9f8
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
a008351
Remote check fix
tofarr Jan 7, 2025
0c92868
Merge branch 'fix-closing-sessions' of github.com:All-Hands-AI/OpenHa…
tofarr Jan 7, 2025
0d0d5f9
Merge branch 'main' into fix-closing-sessions
tofarr Jan 7, 2025
ddad146
Timezones are in UTC
tofarr Jan 7, 2025
30d8dc5
Minio did not delete directories. Now it does.
tofarr Jan 8, 2025
72dac8c
Renamed oh_event to session_msg
tofarr Jan 8, 2025
235725a
Fix types
tofarr Jan 8, 2025
411e0d1
Merge branch 'main' into fix-closing-sessions
tofarr Jan 8, 2025
73744f5
Merge branch 'main' into fix-closing-sessions
tofarr Jan 8, 2025
edfbc2e
Merge branch 'main' into fix-closing-sessions
tofarr Jan 8, 2025
02d6c56
WIP
tofarr Jan 8, 2025
334c849
Merge branch 'fix-closing-sessions' of github.com:All-Hands-AI/OpenHa…
tofarr Jan 8, 2025
26a0183
Merge branch 'main' into fix-closing-sessions
tofarr Jan 8, 2025
d38783c
Merge branch 'main' into fix-closing-sessions
tofarr Jan 8, 2025
09df0d0
Not sending messages if not needed
tofarr Jan 8, 2025
365ccb7
Do not send messages unless needed
tofarr Jan 8, 2025
bcc4657
Removed unneeded code
tofarr Jan 8, 2025
76496b6
Revert
tofarr Jan 8, 2025
563a25d
Fix iteration bug
tofarr Jan 8, 2025
f98f71d
Merge branch 'main' into fix-closing-sessions
tofarr Jan 8, 2025
3611ad1
Added try catch for more resiliency
tofarr Jan 8, 2025
24db670
Merge branch 'fix-closing-sessions' of github.com:All-Hands-AI/OpenHa…
tofarr Jan 8, 2025
b061c26
Setting keep runtime alive to false
tofarr Jan 8, 2025
869f47d
Merge branch 'main' into fix-closing-sessions
tofarr Jan 9, 2025
b77c8be
Merge branch 'main' into fix-closing-sessions
tofarr Jan 9, 2025
d88e5cc
Fix for FD
tofarr Jan 9, 2025
2af5ae0
Event stream close handles its own unsubscribe
tofarr Jan 9, 2025
43b7754
Reduced default close delay to 60 seconds
tofarr Jan 9, 2025
78416b4
Changed close delay default to 15 seconds
tofarr Jan 9, 2025
0f92daf
Merge branch 'main' into fix-closing-sessions
tofarr Jan 10, 2025
73d42f9
Updated started at
tofarr Jan 10, 2025
2d7ef56
More concise logging
tofarr Jan 10, 2025
6ea9910
Fix FD Leak
tofarr Jan 11, 2025
6769659
Fix for more file descriptor leaks
tofarr Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openhands/server/listen_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def connect(connection_id: str, environ, auth):
logger.error('No conversation_id in query params')
raise ConnectionRefusedError('No conversation_id in query params')

user_id = -1
user_id = None
if openhands_config.app_mode != AppMode.OSS:
cookies_str = environ.get('HTTP_COOKIE', '')
cookies = dict(cookie.split('=', 1) for cookie in cookies_str.split('; '))
Expand Down Expand Up @@ -61,7 +61,7 @@ async def connect(connection_id: str, environ, auth):

try:
event_stream = await session_manager.join_conversation(
conversation_id, connection_id, settings
conversation_id, connection_id, settings, user_id
)
except ConversationDoesNotExistError:
logger.error(f'Conversation {conversation_id} does not exist')
Expand Down
21 changes: 10 additions & 11 deletions openhands/server/routes/manage_conversations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuid
from datetime import datetime
from datetime import datetime, timezone
from typing import Callable

from fastapi import APIRouter, Body, Request
Expand Down Expand Up @@ -42,7 +42,8 @@ async def new_conversation(request: Request, data: InitSessionRequest):
logger.info('Initializing new conversation')

logger.info('Loading settings')
settings_store = await SettingsStoreImpl.get_instance(config, get_user_id(request))
user_id = get_user_id(request)
settings_store = await SettingsStoreImpl.get_instance(config, user_id)
settings = await settings_store.load()
logger.info('Settings loaded')

Expand All @@ -55,9 +56,7 @@ async def new_conversation(request: Request, data: InitSessionRequest):
session_init_args['selected_repository'] = data.selected_repository
conversation_init_data = ConversationInitData(**session_init_args)
logger.info('Loading conversation store')
conversation_store = await ConversationStoreImpl.get_instance(
config, get_user_id(request)
)
conversation_store = await ConversationStoreImpl.get_instance(config, user_id)
logger.info('Conversation store loaded')

conversation_id = uuid.uuid4().hex
Expand All @@ -76,19 +75,19 @@ async def new_conversation(request: Request, data: InitSessionRequest):
ConversationMetadata(
conversation_id=conversation_id,
title=conversation_title,
github_user_id=get_user_id(request),
github_user_id=user_id,
selected_repository=data.selected_repository,
)
)

logger.info(f'Starting agent loop for conversation {conversation_id}')
event_stream = await session_manager.maybe_start_agent_loop(
conversation_id, conversation_init_data
conversation_id, conversation_init_data, user_id
)
try:
event_stream.subscribe(
EventStreamSubscriber.SERVER,
_create_conversation_update_callback(get_user_id(request), conversation_id),
_create_conversation_update_callback(user_id, conversation_id),
UPDATED_AT_CALLBACK_ID,
)
except ValueError:
Expand All @@ -112,8 +111,8 @@ async def search_conversations(
for conversation in conversation_metadata_result_set.results
if hasattr(conversation, 'created_at')
)
running_conversations = await session_manager.get_agent_loop_running(
set(conversation_ids)
running_conversations = await session_manager.get_running_agent_loops(
get_user_id(request), set(conversation_ids)
)
result = ConversationInfoResultSet(
results=await wait_all(
Expand Down Expand Up @@ -222,5 +221,5 @@ def callback(*args, **kwargs):
async def _update_timestamp_for_conversation(user_id: int, conversation_id: str):
conversation_store = await ConversationStoreImpl.get_instance(config, user_id)
conversation = await conversation_store.get_metadata(conversation_id)
conversation.last_updated_at = datetime.now()
conversation.last_updated_at = datetime.now(timezone.utc)
await conversation_store.save_metadata(conversation)
Loading
Loading