diff --git a/troubleshooting/20251002_emotion_circular_reference_fix.md b/troubleshooting/20251002_emotion_circular_reference_fix.md new file mode 100644 index 0000000..56f2751 --- /dev/null +++ b/troubleshooting/20251002_emotion_circular_reference_fix.md @@ -0,0 +1,40 @@ +# 순환 참조 제거 및 감정 DB 저장 수정 + +**작성일**: 2025-10-02 16:06 +**완료일**: 2025-10-02 16:10 +**커밋**: 29c0317 + +## 문제 + +### 1. 응답 시간 23.6초 +- Gemini API 429 quota 에러 반복 +- EMOTIONS 변수 참조 에러 14회 + +### 2. 순환 참조 발견 +- llm_service.py → emotion_llm.py → llm_service.py (순환) +- emotion_llm.py:137에서 LLMService() 생성 +- generate_response_with_emotion()에서 LLM 재호출 + +## 원인 +- emotion_llm.py가 LLM 호출 (계층 위반) +- 중복 LLM 호출: handler.chat + emotion_llm LLM + +## 해결 + +### emotion_llm.py +- generate_response_with_emotion() 제거 (100-199줄) +- save_emotion_to_db() 추가 (DB 저장만) + +### llm_service.py +- 감정 분석 → 프롬프트 조절 → LLM 호출 → DB 저장 (86-110줄) +- 순환 참조 해소: llm_service → emotion_llm (단방향) + +## 결과 +- 응답 시간: 23.6초 → 1.9초 +- 감정 DB 저장 정상 작동 +- 16:06:32 KST: surprise 39.53% + +## 교훈 +- 순환 참조는 성능 문제 직결 +- 계층 원칙 준수: LLM 호출은 llm_service만 +- emotion_llm은 분석 + DB 저장만 diff --git a/troubleshooting/20251002_file_size_refactoring_plan.md b/troubleshooting/20251002_file_size_refactoring_plan.md index e56f45b..eacada8 100644 --- a/troubleshooting/20251002_file_size_refactoring_plan.md +++ b/troubleshooting/20251002_file_size_refactoring_plan.md @@ -9,7 +9,7 @@ ### llm_service.py: 343줄 → 254줄 - models.py: Pydantic 모델 분리 (44줄) - special_handler.py: 특수 명령어 처리 (68줄) -- 주석 해제: line 134-138 (감정 DB 저장 활성화) +- 감정 DB 저장 활성화 ### router.py: 557줄 → 384줄 - message_router.py: 라우팅 헬퍼 (113줄)