feat(chat): 검색 1회로 "못 찾았다" 하려는 답을 검색어 바꿔 한 번 더 찾게 하는 REQUERY-ON-MISS 가드 — 구미 집회 질문 사건(프롬프트 규칙 무시). 못 찾았다 판정에 "내용은 없었습니다" 문형 추가

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-09-29 23:16:25 +09:00
1 parent 0d097adaa5
commit f9c8f760fe
4 files changed
+136 -1

No files matched your search

+22
View File
@@ -89,6 +89,7 @@ import { logToolSkip } from './tool-skip-log';
import { checkNumericGrounding } from './numeric-grounding';
import { decideSearchAbandonmentRetry } from './search-abandonment';
import { decideDeadEndFallback, deadEndFallbackPrompt, answerEndedInDeadEnd } from './dead-end-fallback';
import { decideRequeryOnMiss, requeryOnMissPrompt } from './requery-on-miss';
import { correctNewsCategoryForBreadth, fillNewsCategoryWhenExplicit } from '../../tools/news';
const MAX_TOOL_ROUNDS = 50;
@@ -455,6 +456,9 @@ async function handleChat(
// 이미 나와 있는데 라운드만 더 쓴다.
let deadEndFallbackNudges = 0;
const MAX_DEAD_END_FALLBACK_NUDGES = 1;
// 검색 1회 만에 "못 찾았다"로 닫으려 할 때 검색어를 바꿔 한 번 더. 턴당 한 번.
let requeryOnMissNudges = 0;
const MAX_REQUERY_ON_MISS_NUDGES = 1;
// 검색 결과 읽기 지침은 턴당 한 번만 붙인다.
let groundingReadingRuleInjected = false;
let sycophancyNudges = 0;
@@ -2127,6 +2131,24 @@ async function handleChat(
continue;
}
// REQUERY-ON-MISS POST-CHECK (2026-09-29). 검색을 한 번만 하고 "못 찾았다"로 닫는 답을, 검색어를
// 바꿔 한 번 더 찾게 한다(구미 집회 질문 사건 — requery-on-miss.ts). 위 두 가드가 이번 턴을
// 가져갈 때는 비켜선다: 여기까지 왔다는 건 둘 다 continue하지 않았다는 뜻이라 조건은 그 반영이다.
const _requery = decideRequeryOnMiss({
answer: candidateText,
searchQueries: _searchQueriesThisTurn,
otherGuardRetrying: _abandon.retry || _deadEnd.fallback,
});
if (_requery.retry && requeryOnMissNudges < MAX_REQUERY_ON_MISS_NUDGES) {
requeryOnMissNudges++;
console.log(`[v2] REQUERY-ON-MISS POST-CHECK (${requeryOnMissNudges}/${MAX_REQUERY_ON_MISS_NUDGES}): one search (${JSON.stringify(_requery.triedQuery).slice(0, 80)}) ended in "not found". Re-prompting for a reworded search...`);
sendSSE('info', { message: '검색어를 바꿔 다시 찾아봅니다...' });
messages.push({ role: 'assistant', content: candidateText });
messages.push({ role: 'user', content: requeryOnMissPrompt(_requery.triedQuery) });
lastRoundWasGuardReprompt = true;
continue;
}
// SYCOPHANTIC-CONFIRMATION POST-CHECK (2026-09-04). One turn after saying it could not
// verify which Mac mini generation is current, the model answered "아 그럼 M6구나" with
// "네, 맞습니다" and no tool call — confirming, on the user's say-so, the very fact it had
+56
View File
@@ -0,0 +1,56 @@
/**
* requery-on-miss.ts
*
* 검색을 딱 한 번 하고 "찾지 못했습니다"로 답을 닫으려 할 때, 검색어를 바꿔 한 번 더 찾게 한다.
*
* THE INCIDENT (2026-09-29, 메인챗 papa). "오늘 오후 구미시에 데모가 있었나?" →
* web_search("2026년 9월 29일 구미시 시위 데모") 1회 → 무관한 결과 5건 → "확인할 수 없었습니다".
* 검색어가 "시위 데모"로 좁고 어색했다("집회", "파업", "교통 통제"로 바꾸면 잡혔을 질문이다).
* 사용자가 답을 직접 알려 주고서야 대화가 끝났다.
*
* WHY NOT A PROMPT. 시스템 프롬프트에는 이미 "검색 1회는 첫 시도일 뿐, 표현을 바꿔 다시 검색하라"는
* 규칙(searchPersistenceRule)이 있다. 모델은 그걸 무시했다 — 제약이 겹치면 부수 제약을 버리는
* 모델에게 조항을 더 얹어도 듣지 않는다([[feedback_local_model_needs_code_backstop]]).
*
* WHY IT DOES NOT COLLIDE WITH THE OTHER GUARDS.
* - SEARCH-ABANDONMENT: 결과에 알맹이가 있는데 포기한 경우를 맡는다. 그게 이번 턴을 가져가면
* 이 가드는 비켜선다(라운드가 두 배로 들지 않게).
* - DEAD-END FALLBACK: 연속 두 번째 빈손에서 "검색 그만, 아는 걸 말하라"로 끊는다. 이 가드는
* 반대로 "첫 빈손에서 한 번 더 검색하라"라서, 그쪽이 이번 턴을 가져가면 비켜선다.
* - 한 턴에 한 번만, 그리고 이번 턴 검색어가 정확히 1개일 때만 발동한다. 이미 두 번 이상
* 검색하고도 못 찾은 답은 정직한 빈손으로 본다.
*/
import { declaresNothingFound } from './search-abandonment';
export interface RequeryInput {
/** 이번 턴에 모델이 내놓으려는 답변. */
answer: string;
/** 이번 턴에 실제로 나간 검색어들(중복 포함). */
searchQueries: readonly string[];
/** SEARCH-ABANDONMENT나 DEAD-END FALLBACK이 이번 턴을 가져가는가. */
otherGuardRetrying: boolean;
}
export interface RequeryDecision {
retry: boolean;
/** 재프롬프트 문구에 인용할, 이미 시도한 검색어. */
triedQuery: string;
}
export function decideRequeryOnMiss(input: RequeryInput): RequeryDecision {
const distinct = Array.from(new Set(input.searchQueries.map((q) => q.trim()).filter(Boolean)));
const retry = distinct.length === 1
&& !input.otherGuardRetrying
&& declaresNothingFound(input.answer);
return { retry, triedQuery: distinct[0] || '' };
}
/** 재프롬프트 본문. 문구를 테스트에서 고정하려고 분리해 둔다. */
export function requeryOnMissPrompt(triedQuery: string): string {
return `You searched only once (${JSON.stringify(triedQuery)}) and are about to tell the user nothing was found. One query is a first pass, not a conclusion. Search again NOW with a differently-worded query before answering:
- Use the words people and news outlets would actually use, not the user's phrasing or a stiff literal paraphrase (e.g. "시위 데모" → "집회", "파업 결의대회", "교통 통제"; a product nickname → its official name).
- Change the angle: drop the date or the place, broaden or narrow the keywords, or try English if Korean returned nothing (or the reverse).
- Do NOT repeat the previous query.
If the second search also comes back empty, then say plainly that you searched twice and found nothing.`;
}
+1 -1
View File
@@ -45,7 +45,7 @@ import { sourceCoversQuery } from './numeric-grounding';
* "수치가 전혀 포함되어 있지 않아" ×1
* 부정 서술어를 나열하는 대신 "X되어 있지 않다" 꼴을 하나로 묶어 다음 동사에도 견디게 한다.
*/
const NOTHING_FOUND = /확인(되지|할\s*수)\s*(않|없)|찾(을\s*수\s*없|지\s*못했|아볼\s*수\s*없)|(포함|명시|언급|기재|제시|반영|등장|서술)(되어|돼)?\s*있지\s*않|나타나지\s*않|나와\s*있지\s*않|정보(가|는)?\s*(없|부족)|검색되지\s*않|단\s*하나도\s*없|전혀\s*(없|포함되지)|no\s+(results?|information)\s+(found|available)|could\s*n[o']t\s+find|not\s+(?:present|included|mentioned)\s+in\s+the\s+(?:search\s+)?results/i;
const NOTHING_FOUND = /확인(되지|할\s*수)\s*(않|없)|찾(을\s*수\s*없|지\s*못했|아볼\s*수\s*없)|(포함|명시|언급|기재|제시|반영|등장|서술)(되어|돼)?\s*있지\s*않|나타나지\s*않|나와\s*있지\s*않|정보(가|는)?\s*(없|부족)|검색되지\s*않|단\s*하나도\s*없|전혀\s*(없|포함되지)|(내용|정보|기사|소식|기록)(은|이|는|가)?\s*(전혀\s*)?없었|no\s+(results?|information)\s+(found|available)|could\s*n[o']t\s+find|not\s+(?:present|included|mentioned)\s+in\s+the\s+(?:search\s+)?results/i;
/**
* 판정 전에 걷어낼 도입부. 사과·전제 확인만 있고 결론이 없는 문장들이다.
+57
View File
@@ -0,0 +1,57 @@
/**
* requery-on-miss — 검색 1회로 "못 찾았다" 하려는 답을 검색어 바꿔 한 번 더 찾게 하기
*
* 표본은 2026-09-29 메인챗 "오늘 오후 구미시에 데모가 있었나?" — 검색 1회, 무관한 결과, 포기.
*/
import { test, describe } from 'node:test';
import assert from 'node:assert/strict';
import { decideRequeryOnMiss, requeryOnMissPrompt } from '../src/gateway/chat/requery-on-miss';
const GUMI_ANSWER = '제시된 검색 결과들을 모두 확인했으나, 오늘(2026년 9월 29일) 오후 구미시에서 있었던 데모에 관한 내용은 없었습니다.';
const GUMI_QUERY = '2026년 9월 29일 구미시 시위 데모';
describe('decideRequeryOnMiss', () => {
test('구미 사건: 검색 1회 + 못 찾았다 → 재검색', () => {
const d = decideRequeryOnMiss({ answer: GUMI_ANSWER, searchQueries: [GUMI_QUERY], otherGuardRetrying: false });
assert.equal(d.retry, true);
assert.equal(d.triedQuery, GUMI_QUERY);
});
test('이미 두 가지 검색어로 찾고도 빈손이면 정직한 빈손 — 건드리지 않는다', () => {
const d = decideRequeryOnMiss({ answer: GUMI_ANSWER, searchQueries: [GUMI_QUERY, '구미 집회 교통 통제'], otherGuardRetrying: false });
assert.equal(d.retry, false);
});
test('같은 검색어를 두 번 부른 것은 1회로 센다', () => {
const d = decideRequeryOnMiss({ answer: GUMI_ANSWER, searchQueries: [GUMI_QUERY, ` ${GUMI_QUERY} `], otherGuardRetrying: false });
assert.equal(d.retry, true);
});
test('검색이 없었으면 발동하지 않는다(다른 가드의 영역)', () => {
const d = decideRequeryOnMiss({ answer: GUMI_ANSWER, searchQueries: [], otherGuardRetrying: false });
assert.equal(d.retry, false);
});
test('답을 찾아 말한 턴에는 발동하지 않는다', () => {
const d = decideRequeryOnMiss({
answer: '오늘 오후 LS전선 구미1공장 앞에서 파업 결의대회가 열렸고 구미대교 방향이 정체였습니다.',
searchQueries: [GUMI_QUERY],
otherGuardRetrying: false,
});
assert.equal(d.retry, false);
});
test('다른 가드가 이번 턴을 가져가면 비켜선다', () => {
const d = decideRequeryOnMiss({ answer: GUMI_ANSWER, searchQueries: [GUMI_QUERY], otherGuardRetrying: true });
assert.equal(d.retry, false);
});
});
describe('requeryOnMissPrompt', () => {
test('이전 검색어를 인용하고 반복 금지를 명시한다', () => {
const p = requeryOnMissPrompt(GUMI_QUERY);
assert.ok(p.includes(GUMI_QUERY));
assert.match(p, /Do NOT repeat the previous query/);
});
});