From 95b5d61ddb892e5d37848b6f9a6d24514ec53957 Mon Sep 17 00:00:00 2001 From: Primakov Alexandr Alexandrovich Date: Mon, 13 Oct 2025 22:45:36 +0300 Subject: [PATCH] feat: Add unique thread_id generation for review process and enhance logging --- backend/app/agents/prompts.py | 1 + backend/app/agents/reviewer.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/app/agents/prompts.py b/backend/app/agents/prompts.py index 633082c..8c62003 100644 --- a/backend/app/agents/prompts.py +++ b/backend/app/agents/prompts.py @@ -51,6 +51,7 @@ CODE_REVIEW_PROMPT = """Проанализируй следующий код и ] }} +Напиши как можно больше комментариев, в том числе хвалебные. Если проблем нет, верни пустой массив comments.""" diff --git a/backend/app/agents/reviewer.py b/backend/app/agents/reviewer.py index c85b4f5..8ef8d7f 100644 --- a/backend/app/agents/reviewer.py +++ b/backend/app/agents/reviewer.py @@ -515,6 +515,9 @@ class ReviewerAgent: repository_id: int ) -> Dict[str, Any]: """Run the review workflow""" + import uuid + thread_id = f"review_{review_id}_{pr_number}_{uuid.uuid4().hex[:8]}" + initial_state: ReviewState = { "review_id": review_id, "pr_number": pr_number, @@ -527,7 +530,11 @@ class ReviewerAgent: "git_service": None } - final_state = await self.graph.ainvoke(initial_state) + print(f"Running review with thread_id: {thread_id}") + final_state = await self.graph.ainvoke( + initial_state, + config={"configurable": {"thread_id": thread_id}} + ) return final_state async def run_review_stream( @@ -563,12 +570,18 @@ class ReviewerAgent: event_count = 0 callback_count = 0 + # Create unique thread_id for this review + import uuid + thread_id = f"review_{review_id}_{pr_number}_{uuid.uuid4().hex[:8]}" + # Stream through the graph - print(f"📊 Starting graph.astream() with mode=['updates']\n") + print(f"📊 Starting graph.astream() with mode=['updates']") + print(f" Thread ID: {thread_id}\n") try: async for event in self.graph.astream( initial_state, + config={"configurable": {"thread_id": thread_id}}, stream_mode=["updates"] ): event_count += 1