fix(agent): turn_end event.message 객체 처리로 /report 502 해결 - #97
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 || currentTurnText→finalText = currentTurnTextmessage?: string→message?: unknown(잘못된 타입 가정 제거)Test plan
POST http://127.0.0.1:8787/report→ 200 OKPOST http://127.0.0.1:8000/api/reports/00126380/refresh→ 200 OK (삼성전자 전체 리포트)/report/00126380재분석 버튼 클릭 → 리포트 정상 생성🤖 Generated with Claude Code