Skip to content

Commit

Permalink
Fix conversation sorting and pagination (#6014)
Browse files Browse the repository at this point in the history
Co-authored-by: openhands <[email protected]>
  • Loading branch information
tofarr and openhands-agent authored Jan 3, 2025
1 parent 1ddf398 commit a6d3923
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion openhands/storage/conversation/file_conversation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ async def search(
num_conversations = len(conversation_ids)
start = page_id_to_offset(page_id)
end = min(limit + start, num_conversations)
conversation_ids = conversation_ids[start:end]
conversations = []
for conversation_id in conversation_ids:
try:
Expand All @@ -79,6 +78,8 @@ async def search(
exc_info=True,
stack_info=True,
)
conversations.sort(key=_sort_key, reverse=True)
conversations = conversations[start:end]
next_page_id = offset_to_page_id(end, end < num_conversations)
return ConversationMetadataResultSet(conversations, next_page_id)

Expand All @@ -92,3 +93,10 @@ def get_conversation_metadata_filename(self, conversation_id: str) -> str:
async def get_instance(cls, config: AppConfig, token: str | None):
file_store = get_file_store(config.file_store, config.file_store_path)
return FileConversationStore(file_store)


def _sort_key(conversation: ConversationMetadata) -> str:
last_updated_at = conversation.last_updated_at
if last_updated_at:
return last_updated_at.isoformat() # YYYY-MM-DDTHH:MM:SS for sorting
return ''

0 comments on commit a6d3923

Please sign in to comment.