feat: Add unique thread_id generation for review process and enhance logging

This commit is contained in:
Primakov Alexandr Alexandrovich 2025-10-13 22:45:36 +03:00
parent 9dadc490e2
commit 95b5d61ddb
2 changed files with 16 additions and 2 deletions

View File

@ -51,6 +51,7 @@ CODE_REVIEW_PROMPT = """Проанализируй следующий код и
] ]
}} }}
Напиши как можно больше комментариев, в том числе хвалебные.
Если проблем нет, верни пустой массив comments.""" Если проблем нет, верни пустой массив comments."""

View File

@ -515,6 +515,9 @@ class ReviewerAgent:
repository_id: int repository_id: int
) -> Dict[str, Any]: ) -> Dict[str, Any]:
"""Run the review workflow""" """Run the review workflow"""
import uuid
thread_id = f"review_{review_id}_{pr_number}_{uuid.uuid4().hex[:8]}"
initial_state: ReviewState = { initial_state: ReviewState = {
"review_id": review_id, "review_id": review_id,
"pr_number": pr_number, "pr_number": pr_number,
@ -527,7 +530,11 @@ class ReviewerAgent:
"git_service": None "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 return final_state
async def run_review_stream( async def run_review_stream(
@ -563,12 +570,18 @@ class ReviewerAgent:
event_count = 0 event_count = 0
callback_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 # 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: try:
async for event in self.graph.astream( async for event in self.graph.astream(
initial_state, initial_state,
config={"configurable": {"thread_id": thread_id}},
stream_mode=["updates"] stream_mode=["updates"]
): ):
event_count += 1 event_count += 1