From 93ece49f96222c30a895902c00bdba7f151110cf Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Thu, 15 May 2025 15:01:40 -0400 Subject: [PATCH] fix (util): Fix save summary metamessages --- src/crud.py | 3 +++ src/deriver/consumer.py | 10 ++++++++-- src/utils/history.py | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/crud.py b/src/crud.py index ee9eb985..b5ac4f60 100644 --- a/src/crud.py +++ b/src/crud.py @@ -1129,6 +1129,9 @@ async def create_user_protected_collection( name=DEF_PROTECTED_COLLECTION_NAME, ) try: + # This will raise ResourceNotFoundException if user not found + await get_user(db, app_id=app_id, user_id=user_id) + db.add(honcho_collection) await db.commit() except IntegrityError: diff --git a/src/deriver/consumer.py b/src/deriver/consumer.py index 3b6c5296..50dce270 100644 --- a/src/deriver/consumer.py +++ b/src/deriver/consumer.py @@ -51,7 +51,11 @@ async def process_item(db: AsyncSession, payload: dict): await process_ai_message(*processing_args) logger.debug(f"Finished processing message: {payload['message_id']}") await summarize_if_needed( - db, payload["session_id"], payload["user_id"], payload["message_id"] + db, + payload["app_id"], + payload["session_id"], + payload["user_id"], + payload["message_id"], ) return @@ -147,7 +151,7 @@ async def process_user_message( async def summarize_if_needed( - db: AsyncSession, session_id: str, user_id: str, message_id: str + db: AsyncSession, app_id: str, session_id: str, user_id: str, message_id: str ): summary_start = os.times()[4] logger.debug("Checking if summaries should be created") @@ -193,6 +197,7 @@ async def summarize_if_needed( # Save the long summary as a metamessage and capture the returned object latest_long_summary = await history.save_summary_metamessage( db=db, + app_id=app_id, user_id=user_id, session_id=session_id, message_id=message_id, @@ -225,6 +230,7 @@ async def summarize_if_needed( # Save the short summary as a metamessage await history.save_summary_metamessage( db=db, + app_id=app_id, user_id=user_id, session_id=session_id, message_id=message_id, diff --git a/src/utils/history.py b/src/utils/history.py index 22359680..6cec266f 100644 --- a/src/utils/history.py +++ b/src/utils/history.py @@ -220,6 +220,7 @@ Provide a {"comprehensive" if summary_type == SummaryType.LONG else "concise"} s async def save_summary_metamessage( db: AsyncSession, + app_id: str, user_id: str, session_id: str, message_id: str, @@ -247,6 +248,7 @@ async def save_summary_metamessage( # Create and save the metamessage metamessage = models.Metamessage( + app_id=app_id, user_id=user_id, session_id=session_id, message_id=message_id, @@ -389,4 +391,3 @@ def format_messages(messages: list[models.Message]) -> str: return "\n".join( [f"{'user' if msg.is_user else 'assistant'}: {msg.content}" for msg in messages] ) -