Skip to content

Commit be1690b

Browse files
fix(qa): 스레드 맥락을 글자수 대신 메시지 단위로 자르기
리뷰 반영: joined[-MAX:] 글자 슬라이스는 경계가 메시지 중간을 끊어 맥락이 깨진 채 LLM 에 들어갈 수 있었음. 최근 메시지부터 budget 까지 채우고 넘치는 오래된 메시지는 통째로 제외하도록 변경 (각 메시지 온전 보존). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cc31e68 commit be1690b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/handler/bigchat/question_response.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ def _fetch_thread_context(self) -> str:
9393
text = re.sub(r"<@[A-Z0-9]+>", "", m.text or "").strip()
9494
if text:
9595
lines.append(f"{m.user}: {text}")
96-
joined = "\n".join(lines)
97-
# 과다 방지: 최근 대화 위주로 뒤에서 잘라 보존
98-
if len(joined) > self.THREAD_CONTEXT_MAX_CHARS:
99-
joined = joined[-self.THREAD_CONTEXT_MAX_CHARS :]
100-
return joined
96+
97+
# 과다 방지: 글자수가 아니라 메시지 단위로 자른다 (메시지 중간이 끊기지 않도록).
98+
# 최근 메시지부터 채우고, budget 을 넘기는 오래된 메시지는 통째로 제외.
99+
kept, total = [], 0
100+
for line in reversed(lines):
101+
if kept and total + len(line) + 1 > self.THREAD_CONTEXT_MAX_CHARS:
102+
break
103+
kept.append(line)
104+
total += len(line) + 1
105+
return "\n".join(reversed(kept))
101106

102107
def can_handle(self):
103108
text_lower = self.text.lower()

0 commit comments

Comments
 (0)