DOCS/troubleshooting/250911_happybell80_UUID_체계_전환_및_대화저장_오류.md

3.0 KiB

UUID 체계 전환 및 대화 저장 오류 해결

작성일: 2025-09-11

작성자: happybell80


문제 상황

  1. PostgreSQL 테이블명 단수형 통일 후 발생한 연쇄 문제

    • conversation_log 테이블 id 자동증가 미작동
    • Slack ID를 UUID 필드에 저장 시도로 타입 오류
    • Gateway와 rb8001 간 UUID 전달 미구현
  2. 주요 오류 메시지

    - null value in column "id" of relation "conversation_log" violates not-null constraint
    - invalid input syntax for type uuid: "U09C98KBGHX"
    - 'MemoryManager' object has no attribute 'collection_name'
    - 'RobeingRouter' object has no attribute 'is_valid_uuid'
    

해결 과정

1. rb8001 UUID 체계 전환

# app/router/router.py - X-User-Id 헤더 우선 사용
if request and hasattr(request, 'headers'):
    x_user_id = request.headers.get('X-User-Id')
    if x_user_id and self.is_valid_uuid(x_user_id):
        final_uuid = x_user_id

2. conversation_log id 자동증가 해결

# 테이블에 SERIAL 없어서 명시적 생성
max_id_result = db.execute(text("SELECT COALESCE(MAX(id), 0) FROM conversation_log"))
next_id = max_id_result.scalar() + 1
conversation_log = ConversationLog(id=next_id, ...)

3. Gateway Slack ID→UUID 변환

-- 잘못된 쿼리 (username 사용)
WHERE u.username = :slack_user_id

-- 올바른 쿼리 (oauth_id 사용)  
WHERE u.oauth_id = :slack_user_id AND u.oauth_provider = 'slack'

4. Slack Handler UUID 처리

# X-User-Id 헤더에서 UUID 추출
user_uuid = request.headers.get("X-User-Id")
if user_uuid:
    context["user_uuid"] = user_uuid
    context["original_slack_id"] = user_id  # 원본 보존

데이터 흐름 정리

Frontend → Gateway → rb8001

  1. JWT에서 UUID 추출: 3550cef6-63e1-4ceb-8802-a25c9d1c6917
  2. X-User-Id 헤더로 전달
  3. 정상 저장 및 조회

Slack → Gateway → rb8001

  1. Slack ID: U09C98KBGHX
  2. Gateway에서 oauth_id로 UUID 조회: 53529291-5050-4daa-89fb-008b546feb63
  3. X-User-Id 헤더로 전달
  4. 정상 저장 및 조회

수정된 파일

  • rb8001/app/router/router.py
  • rb8001/app/state/database.py
  • rb8001/app/router/slack_handler.py
  • robeing-gateway/app/main.py

결과 확인

  • 총 545개 대화 저장, NULL user_id 0개
  • 오늘 2개 저장: 김종태(53529291-5050-4daa-89fb-008b546feb63), frontend 사용자
  • Gateway UUID 변환 성공: Slack ID → UUID 정상 작동

추가 수정 사항

뉴스 중복 방지

# skill-news fallback 제거 - dm_skill.py
# 새 뉴스 없을 때 /api/news/latest 호출 제거
return ("오늘의 새로운 뉴스가 없습니다.", [])

헬스체크 로그 레벨 조정

# DEBUG 레벨로 변경 - main.py
logger.debug(f"Health check passed for {settings.ROBEING_ID}")

교훈

  • DB 스키마와 코드 모델 일치 필수
  • UUID 체계 전환 시 모든 경로 점검
  • 헤더 기반 인증 정보는 일관된 위치에서 처리