DOCS/troubleshooting/250826_frontend_rb8001_chat_endpoint_missing.md
happybell80 87eddf3ec5 docs: robeing_id undefined 문제 원인 분석 추가
- 채팅 엔드포인트: 해결 완료 (rb8001에 /api/message 추가됨)
- robeing_id undefined: Frontend 초기화 타이밍 문제 발견
- Gateway 캐시가 undefined 저장하는 문제 확인
- Frontend game-layout.tsx 수정 필요 사항 명시

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-26 14:38:55 +09:00

5.6 KiB

Frontend-rb8001 대화 엔드포인트 미연결 및 robeing_id undefined 문제

작성일: 2025-08-26

작성자: 서버 관리자

상태: 부분 해결 (채팅 연결 , robeing_id 문제 진행중)

영향: Frontend 채팅 기능 작동, stats 조회 오류


1. 문제 상황

1.1 증상

  • 사용자: goeun2dc@gmail.com (happybell80)
  • 현상: Frontend 채팅 입력 시 응답 없음
  • 경로: Frontend(8000) → Gateway(8100) → (rb8001 도달 실패)

1.2 네트워크 플로우

[예상 플로우]
Frontend → Gateway(51123:8100) → rb8001(51124:8001)

[실제 플로우 - 채팅]
Frontend → Gateway(51123:8100) → rb8001(51124:8001) ✅ (해결됨)

[실제 플로우 - Stats]
Frontend → /api/stats/undefined → Gateway → rb8001 반환 (사용자 기반 매핑)

1.3 추가 발견된 문제

  • robeing_id undefined: Frontend가 /api/stats/undefined로 요청
  • 원인: Frontend 초기화 타이밍 문제

2. 원인 분석

2.1 채팅 엔드포인트 (해결됨)

구성요소 엔드포인트 상태
Frontend /api/chat 요청 전송 중
Gateway /api/chat/api/message 프록시 구현됨
rb8001 /api/message 추가됨 (51124 배포 완료)

2.2 robeing_id undefined 문제 (새로 발견)

Frontend 코드 문제 (game-layout.tsx:114)

  • getUserRobeing() 호출 전에 getRobeingStats(userRobeingId) 실행
  • 초기값 'rb10508_micro' → undefined로 변경되는 타이밍 이슈
  • 결과: /api/stats/undefined 요청 발생

Gateway 동작 (정상)

  • 모든 요청에 사용자 기반 매핑으로 rb8001 반환
  • happybell80 → rb8001 매핑 정상 작동
  • 캐시 때문에 undefined도 rb8001로 응답

2.2 서버별 확인 결과

51123 서버 (Gateway)

# Gateway 환경변수
VITE_API_URL=http://localhost:8001  # 로컬 개발용
VITE_ROBING_API_URL=https://ro-being.com/gateway  # 실제 사용 중

# Gateway 로그
JWT 인증 성공 (happybell80)
/api/chat 라우팅 규칙 없음

51124 서버 (rb8001)

# rb8001 엔드포인트 확인
/complete - LLM 처리용 ✅
/api/slack/events - Slack 전용 ✅
/api/cron/daily-summary - 크론용 ✅
/api/chat - 없음 ❌

# 테스트 결과
curl http://localhost:8001/complete -d '{"prompt":"test"}' # 200 OK
curl http://localhost:8001/api/chat -d '{"message":"test"}' # 404 Not Found

2.3 근본 원인

  1. 엔드포인트 미구현: rb8001에 /api/chat 엔드포인트 없음
  2. Gateway 라우팅 누락: Gateway가 rb8001로 프록시하지 않음
  3. 프로토콜 불일치: Frontend 요청 형식과 rb8001 /complete 형식 다름

3. 해결 현황 및 추가 작업

3.1 완료: rb8001에 /api/message 엔드포인트 추가 (51124 서버)

  • 2025-08-26 14:00경 배포 완료
  • 채팅 기능 정상 작동 확인

3.2 🔧 진행 필요: robeing_id undefined 해결

Frontend 수정 필요 (game-layout.tsx)

// 문제 코드
useEffect(() => {
  getRobeingStats(userRobeingId); // undefined 가능
}, []);

// 수정안
useEffect(() => {
  const fetchStats = async () => {
    await getUserRobeing(); // 먼저 사용자 robeing 조회
    getRobeingStats(userRobeingId); // 이후 stats 조회
  };
  fetchStats();
}, []);

Gateway 캐시 클리어 (임시 조치)

docker restart robeing-gateway  # 캐시 초기화
# 또는 TTL 단축 설정 변경

4. 검증 결과

4.1 채팅 기능 테스트

curl -X POST http://localhost:8100/api/chat \
  -H "Content-Type: application/json" \
  -d '{"text":"테스트 메시지","user_id":"happybell80"}'

# 실제 응답 (성공)
{"user_id":"default","user_message":"테스트 메시지",
 "bot_response":"안녕하세요, 사용자님. 저는 로빙입니다.",
 "status":"success"}

4.2 Stats API 문제 확인

# Gateway 로그
Stats request from user: happybell80 for robeing: undefined
# Frontend에서 /api/stats/undefined 요청 계속 발생

4.3 대화 저장 확인

SELECT COUNT(*) FROM conversation_logs; -- 0건
-- rb8001에서 DB 저장 로직 미구현

5. 해결 계획

5.1 즉시 조치 (51123 서버)

  1. Gateway 캐시 재시작: docker restart robeing-gateway
  2. 로그 모니터링 지속

5.2 Frontend 수정 필요 (로컬)

  1. 타이밍 문제 해결: getUserRobeing() 완료 후 stats 조회
  2. 초기값 처리: undefined 방지 로직 추가

5.3 rb8001 추가 작업 (51124 서버)

  1. 대화 저장 구현: PostgreSQL 직접 저장
  2. user_id 처리: UUID vs Slack ID 통일

7. 관련 파일

51123 서버

  • /home/admin/robeing-gateway/app/main.py - Gateway 라우팅
  • /home/admin/frontend-customer/.env - Frontend 설정

51124 서버

  • /home/happybell/projects/ivada/rb8001/app/router/router.py - rb8001 엔드포인트
  • /home/happybell/projects/ivada/rb8001/.env - rb8001 설정

로컬 개발

  • frontend-customer/src/api/ - API 호출 코드
  • frontend-customer/src/components/Chat/ - 채팅 컴포넌트

8. 참고 사항 (2025-08-26 14:30 업데이트)

해결된 문제

  • 채팅 엔드포인트 연결 (rb8001에 /api/message 추가)
  • Gateway 프록시 정상 작동

남은 문제

  • robeing_id undefined (Frontend 초기화 타이밍)
  • 대화 저장 0건 (DB 저장 로직 미구현)
  • ⚠️ Gateway 캐시에 undefined 저장됨

관련 문서

  • 250826_happybell80_frontend_rb8001_채팅연결_계획.md
  • 250826_happybell80_rb8001_이중저장구현.md