Fix out of order messages

This commit is contained in:
Douwe Osinga
2026-02-24 07:10:05 -05:00
parent fc60b50347
commit 581065eff5
3 changed files with 6 additions and 1 deletions
+1
View File
@@ -1638,6 +1638,7 @@ impl Agent {
session_manager.add_message(&session_config.id, msg).await?;
}
conversation.extend(messages_to_add);
conversation.sort_by_created();
if exit_chat {
break;
}
+4
View File
@@ -103,6 +103,10 @@ impl Conversation {
self.0.clear();
}
pub fn sort_by_created(&mut self) {
self.0.sort_by_key(|m| m.created);
}
pub fn filtered_messages<F>(&self, filter: F) -> Vec<Message>
where
F: Fn(&MessageMetadata) -> bool,
+1 -1
View File
@@ -1082,7 +1082,7 @@ impl SessionStorage {
async fn get_conversation(&self, session_id: &str) -> Result<Conversation> {
let pool = self.pool().await?;
let rows = sqlx::query_as::<_, (String, String, i64, Option<String>, Option<String>)>(
"SELECT role, content_json, created_timestamp, metadata_json, message_id FROM messages WHERE session_id = ? ORDER BY timestamp",
"SELECT role, content_json, created_timestamp, metadata_json, message_id FROM messages WHERE session_id = ? ORDER BY created_timestamp",
)
.bind(session_id)
.fetch_all(pool)