Skip to content

refactor: AnalysisCompletedHandler 책임 분리#81

Merged
Boyeon-Shin merged 3 commits into
mainfrom
refactor/analysis-handler
May 14, 2026
Merged

refactor: AnalysisCompletedHandler 책임 분리#81
Boyeon-Shin merged 3 commits into
mainfrom
refactor/analysis-handler

Conversation

@Boyeon-Shin
Copy link
Copy Markdown
Collaborator

📌 관련 이슈 (Related Issue)

📝 작업 내용 (Description)

  • AllAnalysisCompletedHandler 책임 분리
  • PromptBuilder 도메인별 분리
  • dto 패키지를 request/response/internal로 재구성

🔄 변경 유형 (Type of Change)

  • ✨ 새로운 기능 (feat)
  • 🐛 버그 수정 (fix)
  • 📝 문서 수정 (docs)
  • 💄 스타일 (style)
  • ♻️ 리팩토링 (refactor)
  • ✅ 테스트 (test)
  • 🔧 기타 (chore)

✅ 체크리스트 (Checklist)

  • 코드가 정상적으로 동작하는지 확인했습니다
  • 기존 테스트가 통과합니다
  • 필요한 경우 새로운 테스트를 추가했습니다

@Boyeon-Shin Boyeon-Shin self-assigned this May 14, 2026
@Boyeon-Shin Boyeon-Shin merged commit e1a0ea2 into main May 14, 2026
3 checks passed
@Boyeon-Shin Boyeon-Shin changed the title Refactor/analysis handler refactor: AnalysisCompletedHandler 책임 분리 May 14, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the interview feedback logic by reorganizing DTOs into specialized subpackages and delegating processing logic to the new AnalysisCompletionService and SessionCompletionNotifier. It also decouples prompt generation by splitting PromptBuilder into QuestionPromptBuilder and FeedbackPromptBuilder. The review feedback points out a potential race condition in the session completion trigger and recommends adding a merge function to a Collectors.toMap operation to prevent potential exceptions from duplicate keys.

Comment on lines +62 to +71
private void completeSessionIfReady(InterviewAnswer answer) {
InterviewSession session = getSession(answer);
if (session == null) {
log.warn("[최종평가] 세션 없음 - answerId: {}", answer.getId());
return;
}

if (!isFinalFeedbackReady(session)) {
return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a potential race condition in completeSessionIfReady. If multiple answers for the same session complete their analysis simultaneously, multiple threads might pass the isFinalFeedbackReady check and proceed to call the expensive OpenAI API (feedbackGenerator.generateFinal) and trigger session completion notifications multiple times.

Consider adding a check to verify if the session is already completed or using a synchronization mechanism (like a distributed lock or an atomic status update in the database) to ensure that the final evaluation logic is executed exactly once per session.


private Map<UUID, InterviewAnswer> getAnswerMap(UUID sessionId) {
return answerRepository.findBySessionId(sessionId).stream()
.collect(Collectors.toMap(a -> a.getInterviewQuestion().getId(), a -> a));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using Collectors.toMap without a merge function will throw an IllegalStateException if duplicate keys are encountered. While the business logic might currently ensure one answer per question per session, it is safer to provide a merge function or use groupingBy if multiple answers could ever exist (e.g., due to retries or future changes).

Suggested change
.collect(Collectors.toMap(a -> a.getInterviewQuestion().getId(), a -> a));
.collect(Collectors.toMap(a -> a.getInterviewQuestion().getId(), a -> a, (existing, replacement) -> existing));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: AnalysisCompletedHandler 책임 분리

1 participant