Skip to content

fix(agent): turn_end event.message 객체 처리로 /report 502 해결 - #97

Merged
GoBeromsu merged 2 commits into
devfrom
feature/C-fix-pi-session-finaltext-type
May 28, 2026
Merged

fix(agent): turn_end event.message 객체 처리로 /report 502 해결#97
GoBeromsu merged 2 commits into
devfrom
feature/C-fix-pi-session-finaltext-type

Conversation

@GoBeromsu

Copy link
Copy Markdown
Owner

Summary

/report/[corpCode] 재분석 시 502 Bad Gateway 발생.

Root cause: Pi SDK turn_end 이벤트의 event.message는 문자열이 아니라 {role, content, ...} 객체. finalText = candidate.message || currentTurnText로 객체를 그대로 할당 → finalText.trim() 호출에서 TypeError → agent 500 → backend 500 → Next.js 502.

Fix (agent/src/pi/piSession.ts:252, 2줄):

  • finalText = candidate.message || currentTurnTextfinalText = currentTurnText
  • message?: stringmessage?: unknown (잘못된 타입 가정 제거)

Test plan

  • POST http://127.0.0.1:8787/report → 200 OK
  • POST http://127.0.0.1:8000/api/reports/00126380/refresh → 200 OK (삼성전자 전체 리포트)
  • 브라우저에서 /report/00126380 재분석 버튼 클릭 → 리포트 정상 생성

🤖 Generated with Claude Code

GoBeromsu and others added 2 commits May 28, 2026 20:48
- build_report_list_response에서 워치리스트 종목을 함께 조회해
  리포트가 없는 종목도 목록에 포함 (hasReport=False 마커)
- ReportSummaryContract에 hasReport 옵션 필드 추가
- /report 페이지에서 미생성 종목은 "리포트 생성" 버튼 표시,
  클릭 시 /report/[corpCode]로 이동 (캐시미스 UI + 재분석 버튼 활용)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pi SDK turn_end 이벤트의 message 필드는 {role, content, ...} 메시지 객체이며
문자열이 아니다. finalText = candidate.message || currentTurnText 패턴으로
객체가 finalText에 할당되면 finalText.trim()에서 TypeError가 발생하고
결국 재분석 버튼 클릭 시 502가 반환된다.

텍스트는 message_update 이벤트로 누적된 currentTurnText를 직접 사용한다.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@GoBeromsu
GoBeromsu merged commit 33efe95 into dev May 28, 2026
8 checks passed
@GoBeromsu
GoBeromsu deleted the feature/C-fix-pi-session-finaltext-type branch May 28, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant