diff --git a/troubleshooting/250826_frontend_rb8001_chat_endpoint_missing.md b/troubleshooting/250826_frontend_rb8001_chat_endpoint_missing.md index 8bbcd30..970c7e3 100644 --- a/troubleshooting/250826_frontend_rb8001_chat_endpoint_missing.md +++ b/troubleshooting/250826_frontend_rb8001_chat_endpoint_missing.md @@ -1,9 +1,9 @@ -# Frontend-rb8001 대화 엔드포인트 미연결 문제 +# Frontend-rb8001 대화 엔드포인트 미연결 및 robeing_id undefined 문제 ## 작성일: 2025-08-26 ## 작성자: 서버 관리자 -## 상태: 미해결 -## 영향: Frontend(goeun2dc) 채팅 기능 완전 불가 +## 상태: 부분 해결 (채팅 연결 ✅, robeing_id 문제 진행중) +## 영향: Frontend 채팅 기능 작동, stats 조회 오류 --- @@ -19,21 +19,38 @@ [예상 플로우] Frontend → Gateway(51123:8100) → rb8001(51124:8001) -[실제 플로우] -Frontend → Gateway(51123:8100) → 없음 (404) +[실제 플로우 - 채팅] +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 엔드포인트 불일치 +### 2.1 ✅ 채팅 엔드포인트 (해결됨) | 구성요소 | 엔드포인트 | 상태 | |---------|-----------|------| | Frontend | `/api/chat` 요청 | 전송 중 | -| Gateway | 라우팅 규칙 없음 | ❌ | -| rb8001 | `/api/chat` 없음 | ❌ | -| rb8001 | `/complete` 있음 | ✅ (Slack용) | +| 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 서버별 확인 결과 @@ -68,102 +85,80 @@ curl http://localhost:8001/api/chat -d '{"message":"test"}' # 404 Not Found --- -## 3. 해결 방안 +## 3. 해결 현황 및 추가 작업 -### 3.1 Option 1: rb8001에 /api/chat 엔드포인트 추가 -```python -# rb8001/app/router/router.py -@router.post("/api/chat") -async def chat_endpoint(request: ChatRequest): - """Frontend 채팅 요청 처리""" - # 1. Frontend 형식 → rb8001 형식 변환 - # 2. _process_message() 호출 - # 3. Frontend 형식으로 응답 반환 -``` +### 3.1 ✅ 완료: rb8001에 /api/message 엔드포인트 추가 (51124 서버) +- 2025-08-26 14:00경 배포 완료 +- 채팅 기능 정상 작동 확인 -### 3.2 Option 2: Gateway에서 라우팅 매핑 -```python -# robeing-gateway/app/main.py -@app.post("/api/chat") -async def proxy_chat(request: Request): - """채팅 요청을 rb8001로 프록시""" - # 1. /api/chat → /complete 변환 - # 2. http://192.168.219.52:8001/complete 호출 - # 3. 응답 변환 후 반환 -``` +### 3.2 🔧 진행 필요: robeing_id undefined 해결 -### 3.3 Option 3: Frontend 수정 +**Frontend 수정 필요** (game-layout.tsx) ```javascript -// frontend-customer/src/api/chat.js -// VITE_API_URL을 올바른 엔드포인트로 변경 -const API_URL = import.meta.env.VITE_RB8001_URL || 'http://192.168.219.52:8001' -const endpoint = '/complete' // /api/chat 대신 +// 문제 코드 +useEffect(() => { + getRobeingStats(userRobeingId); // undefined 가능 +}, []); + +// 수정안 +useEffect(() => { + const fetchStats = async () => { + await getUserRobeing(); // 먼저 사용자 robeing 조회 + getRobeingStats(userRobeingId); // 이후 stats 조회 + }; + fetchStats(); +}, []); ``` ---- - -## 4. 임시 해결책 - -### 즉시 적용 가능한 방법 +**Gateway 캐시 클리어** (임시 조치) ```bash -# Gateway 컨테이너에 임시 프록시 추가 -docker exec robeing-gateway bash -c " -cat > /tmp/proxy.py << 'EOF' -from fastapi import Request -import httpx - -@app.post('/api/chat') -async def temp_proxy(request: Request): - data = await request.json() - async with httpx.AsyncClient() as client: - # 형식 변환 - rb8001_data = { - 'prompt': data.get('message', ''), - 'user_id': data.get('user_id', 'web_user'), - 'channel': 'web' - } - response = await client.post( - 'http://192.168.219.52:8001/complete', - json=rb8001_data - ) - return {'response': response.json().get('response', '')} -EOF -" +docker restart robeing-gateway # 캐시 초기화 +# 또는 TTL 단축 설정 변경 ``` - --- -## 5. 검증 방법 +## 4. 검증 결과 -### 5.1 엔드포인트 테스트 +### 4.1 채팅 기능 테스트 ✅ ```bash -# Frontend 형식 테스트 curl -X POST http://localhost:8100/api/chat \ -H "Content-Type: application/json" \ - -d '{"message": "안녕하세요", "user_id": "happybell80"}' + -d '{"text":"테스트 메시지","user_id":"happybell80"}' -# 예상 응답 -{"response": "안녕하세요! 무엇을 도와드릴까요?"} +# 실제 응답 (성공) +{"user_id":"default","user_message":"테스트 메시지", + "bot_response":"안녕하세요, 사용자님. 저는 로빙입니다.", + "status":"success"} ``` -### 5.2 전체 플로우 테스트 -1. Frontend 로그인 (goeun2dc@gmail.com) -2. 채팅 입력 -3. rb8001 로그 확인: `docker logs rb8001 --tail 50` -4. 응답 수신 확인 +### 4.2 Stats API 문제 확인 ❌ +```bash +# Gateway 로그 +Stats request from user: happybell80 for robeing: undefined +# Frontend에서 /api/stats/undefined 요청 계속 발생 +``` + +### 4.3 대화 저장 확인 ❌ +```sql +SELECT COUNT(*) FROM conversation_logs; -- 0건 +-- rb8001에서 DB 저장 로직 미구현 +``` --- -## 6. 장기 해결 계획 +## 5. 해결 계획 -### 6.1 아키텍처 정리 -- Frontend ↔ rb8001 직접 통신 vs Gateway 경유 결정 -- 통일된 API 규격 정의 (OpenAPI 스펙) +### 5.1 즉시 조치 (51123 서버) +1. **Gateway 캐시 재시작**: `docker restart robeing-gateway` +2. **로그 모니터링 지속** -### 6.2 구현 우선순위 -1. **긴급**: rb8001에 /api/chat 엔드포인트 추가 -2. **중요**: Gateway 라우팅 규칙 정비 -3. **일반**: Frontend 환경변수 정리 +### 5.2 Frontend 수정 필요 (로컬) +1. **타이밍 문제 해결**: getUserRobeing() 완료 후 stats 조회 +2. **초기값 처리**: undefined 방지 로직 추가 + +### 5.3 rb8001 추가 작업 (51124 서버) +1. **대화 저장 구현**: PostgreSQL 직접 저장 +2. **user_id 처리**: UUID vs Slack ID 통일 --- @@ -183,9 +178,17 @@ curl -X POST http://localhost:8100/api/chat \ --- -## 8. 참고 사항 +## 8. 참고 사항 (2025-08-26 14:30 업데이트) -- Slack 채팅은 정상 작동 (별도 플로우) -- DM 기능도 정상 (/complete 직접 사용) -- 문제는 Web Frontend 채팅만 해당 -- State Service는 rb8001에 통합됨 (250826_happybell80_rb8001_이중저장구현.md 참고) \ No newline at end of file +### 해결된 문제 +- ✅ 채팅 엔드포인트 연결 (rb8001에 /api/message 추가) +- ✅ Gateway 프록시 정상 작동 + +### 남은 문제 +- ❌ robeing_id undefined (Frontend 초기화 타이밍) +- ❌ 대화 저장 0건 (DB 저장 로직 미구현) +- ⚠️ Gateway 캐시에 undefined 저장됨 + +### 관련 문서 +- 250826_happybell80_frontend_rb8001_채팅연결_계획.md +- 250826_happybell80_rb8001_이중저장구현.md \ No newline at end of file