From b88d335d9213baac2b22192ccd30a11dc5d4bb69 Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 21 Jul 2026 19:13:37 +0200 Subject: [PATCH] memory (sqla): Get original message in thread in `history_get`: When using `thread_id` filter, original message could be missing (notably with a reply). We now include it with `History.uid == filters["thread_id"]`. --- libervia/backend/memory/sqla.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libervia/backend/memory/sqla.py b/libervia/backend/memory/sqla.py index e1d23882..daf9da78 100644 --- a/libervia/backend/memory/sqla.py +++ b/libervia/backend/memory/sqla.py @@ -729,7 +729,13 @@ class Storage: if "origin_id" in filters: stmt = stmt.where(History.origin_id == filters["origin_id"]) if "thread_id" in filters: - stmt = stmt.where(Thread.thread_id == filters["thread_id"]) + # Include both replies and the parent message (thread_id is the parent uid) + stmt = stmt.where( + or_( + Thread.thread_id == filters["thread_id"], + History.uid == filters["thread_id"], + ) + ) if "keyword" in filters: keyword = filters["keyword"] # FIXME: "json_each" works with SQLite, but when PostGreSQL support will