fix: 루프 감지를 인자 보정 전 원본으로 판정한다

실사고(2026-08-12): "오늘 미국 주요 뉴스"에 모델이 분야를 나눠 세 번 불렀다.

  news_search({category:"technology", country:"us"})
  news_search({category:"business",   country:"us"})
  news_search({category:"world",      country:"us"})

category 보정(8a8c81e)이 셋을 전부 {"country":"us"}로 접었고, 그 뒤에 도는
루프 감지가 이를 "같은 호출 3회"로 읽어 LOOP WARN x3을 찍었다. 모델은 루프에
빠진 적이 없다 — 서로 다른 세 호출을 우리가 같게 만든 것이다.

동작에는 지장이 없었다(중복 제거가 받아 1회만 실행, 같은 초 안에 끝났고 답변
품질은 오히려 개선). 문제는 경고가 거짓이라는 것이다. 이 소음이 쌓이면 진짜
루프를 디버깅할 때 묻힌다.

두 판정의 질문이 다르므로 인자도 달라야 한다:
- 루프 감지 = "모델이 같은 행동을 반복하는가" → 보정 전 원본 인자
- 중복 실행 방지 = "이 실행이 불필요한가"     → 보정 후 인자(접힌 뒤 같아진
  호출은 실제로 불필요하므로 그대로 둔다)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Opus 5 committed 2026-08-12 12:47:06 +09:00
1 parent bc2ae25a34
commit 2f6872b026
1 file changed
+13 -3
+13 -3
View File
@@ -2150,7 +2150,9 @@ async function handleChat(
for (const call of toolCalls) {
const toolCallId = String((call as any)?.id || '').trim();
const toolName = call.function?.name || 'unknown';
const toolArgs = correctNewsCategoryForBreadth2(toolName, normalizeToolArgs(call.function?.arguments), recentUserText);
// 루프 감지는 모델이 보낸 원본 인자로 한다 — 아래 loopSig/checkLoopDetection 참고.
const rawToolArgs = normalizeToolArgs(call.function?.arguments);
const toolArgs = correctNewsCategoryForBreadth2(toolName, rawToolArgs, recentUserText);
// Block PageDown / browser_scroll on interactive pages when the model hasn't
// filled or clicked anything yet. This is the #1 cause of the scroll loop bug
@@ -2196,9 +2198,17 @@ async function handleChat(
browserScrollBeforeActCount = 0;
}
const loopSig = `${toolName}:${hashArgs(toolArgs)}`;
// 원본 인자로 판정한다. 루프 감지가 재는 것은 "모델이 같은 행동을 반복하는가"인데,
// 우리 인자 보정을 거친 뒤로 재면 서로 다른 호출이 같아 보인다 — 2026-08-12 실제로
// 모델이 category=technology/business/world 로 분야를 나눠 부른 것을 보정이 전부
// {"country":"us"} 로 접었고, 루프 감지가 그걸 "같은 호출 3회"로 오인해 경고를 찍었다.
// 모델은 루프에 빠진 적이 없다. 이 경고가 소음이 되면 진짜 루프를 디버깅할 때 묻힌다.
//
// 중복 실행 방지(아래 SKIP)는 반대로 보정 후 인자로 판정해야 한다 — 거긴 "이 실행이
// 불필요한가"를 묻는 자리이고, 접힌 뒤 같아진 호출은 실제로 불필요하다.
const loopSig = `${toolName}:${hashArgs(rawToolArgs)}`;
const loopPivotNudge = 'Loop detector: you are looping on this tool, try a different approach or ask the user.';
const loopCheck = checkLoopDetection(toolName, toolArgs);
const loopCheck = checkLoopDetection(toolName, rawToolArgs);
if (loopCheck.state === 'block') {
// weather_kma specifically: a real 2026-08-06 case (gemma-4-26b-a4b, 미세먼지 question)
// showed the generic pivot nudge alone wasn't enough — the model kept re-calling