DOCS/troubleshooting/250826_frontend_rb8001_chat_endpoint_missing.md
happybell80 8c02b80359 Fix incorrect table names in documentation
- gmail_tokens → gmail_token (33 files)
- companies → company (17 files)
- conversation_logs → conversation_log (27 files)
- workspace_members → workspace_member (28 files)

All table names now match the actual PostgreSQL schema
2025-09-26 00:49:47 +09:00

203 lines
6.1 KiB
Markdown

# Frontend-rb8001 대화 엔드포인트 미연결 및 robeing_id undefined 문제
## 작성일: 2025-08-26
## 작성자: 서버 관리자 / happybell80
## 상태: ✅ 해결 완료 (채팅 연결 ✅, robeing_id undefined 해결 ✅)
## 영향: Frontend 채팅 기능 정상 작동
## 최종 업데이트: 2025-08-26 18:30
---
## 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)
```bash
# Gateway 환경변수
VITE_API_URL=http://localhost:8001 # 로컬 개발용
VITE_ROBING_API_URL=https://ro-being.com/gateway # 실제 사용 중
# Gateway 로그
JWT 인증 성공 (happybell80)
/api/chat 라우팅 규칙 없음
```
#### 51124 서버 (rb8001)
```bash
# 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 해결 (2025-08-26 17:00)
**Frontend 수정 완료** (game-layout.tsx)
```javascript
// 수정 완료 - getUserRobeing() 완료 후 stats 조회
useEffect(() => {
const fetchUserRobeingAndStats = async () => {
const robeingInfo = await getUserRobeing();
if (robeingInfo) {
setUserRobeingId(robeingInfo.robeing_id);
const data = await getRobeingStats(robeingInfo.robeing_id); // 직접 전달
}
};
fetchUserRobeingAndStats();
}, [user]);
```
**⚠️ 캐시 클리어 필요** (서버 작업)
```bash
# 1. Gateway 캐시 클리어
docker restart robeing-gateway # undefined 캐시 제거
# 2. 브라우저 캐시 클리어
Ctrl+Shift+R 또는 F12 → Network → Disable cache
```
---
## 4. 검증 결과
### 4.1 채팅 기능 테스트 ✅
```bash
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 문제 확인 ❌
```bash
# Gateway 로그
Stats request from user: happybell80 for robeing: undefined
# Frontend에서 /api/stats/undefined 요청 계속 발생
```
### 4.3 대화 저장 확인 ❌
```sql
SELECT COUNT(*) FROM conversation_log; -- 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 17:00 업데이트)
### 해결된 문제
- ✅ 채팅 엔드포인트 연결 (rb8001에 /api/message 추가)
- ✅ Gateway 프록시 정상 작동
- ✅ robeing_id undefined 코드 수정 완료 (Frontend 타이밍 문제 해결)
- ✅ Stats API 정상 작동 (undefined 없이 rb8001 스탯 조회)
### 남은 작업 (별도 문서 참조)
- ❌ 대화 저장 실패 → 250826_rb8001_conversation_storage_failure.md 참조
- PostgreSQL UUID 타입 에러로 저장 실패
- ChromaDB는 정상 저장됨
### 보안 이슈 감지
- phpunit eval-stdin.php 접근 시도
- .env 파일 무단 접근 시도
- 차단 조치 필요
### 관련 문서
- 250826_happybell80_frontend_rb8001_채팅연결_계획.md
- 250826_happybell80_rb8001_이중저장구현.md