From 7dac269429917ddf8ee3bf44734aaadc0f2ad473 Mon Sep 17 00:00:00 2001 From: Daniel Derefaka <101010297+DanielDerefaka@users.noreply.github.com> Date: Wed, 31 Dec 2025 03:25:49 +0100 Subject: [PATCH] fix: correct session reference initialization to prevent dialogue misalignment (#12343) ## Summary Fixes #12311 Changes the `reference` field initialization from `[{}]` to `[]` in session creation. ### Problem When creating a session via the SDK API, the `reference` field was incorrectly initialized as `[{}]`. This caused: - First dialogue round: Empty reference - Second dialogue round: Reference pointing to first round's data - Overall misalignment between dialogue rounds and their references ### Solution Changed the initialization to `[]` (empty list), which: - Matches the `Conversation` model's expected default - Ensures references grow correctly one-to-one with assistant responses - Aligns with the service layer's expectations ### Testing After applying this fix: 1. Create a session via `POST /api/v1/chats/{conversation_id}/sessions` 2. Send multiple questions via `POST /api/v1/chats/{conversation_id}/completions` 3. View the conversation on web - references should now align correctly with each dialogue round --- api/apps/sdk/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py index c143d3104..f9615e36b 100644 --- a/api/apps/sdk/session.py +++ b/api/apps/sdk/session.py @@ -60,7 +60,7 @@ async def create(tenant_id, chat_id): "name": req.get("name", "New session"), "message": [{"role": "assistant", "content": dia[0].prompt_config.get("prologue")}], "user_id": req.get("user_id", ""), - "reference": [{}], + "reference": [], } if not conv.get("name"): return get_error_data_result(message="`name` can not be empty.")