diff --git a/src/gateway/chat/handle-chat.ts b/src/gateway/chat/handle-chat.ts index 94beb1c..ad40621 100644 --- a/src/gateway/chat/handle-chat.ts +++ b/src/gateway/chat/handle-chat.ts @@ -1882,6 +1882,11 @@ async function handleChat( console.log(`[v2] INLINE REASONING [${resolvedModelThisRound || '?'}] (${inlineThinking.length} chars): ${inlineThinking.slice(0, 100)}...`); allThinking += (allThinking ? '\n\n' : '') + inlineThinking; sendSSE('thinking', { thinking: inlineThinking }); + // 진단(2026-10-03): 추론으로 분류된 분량이 답변보다 압도적으로 큰 경우(실사례: 표 전체가 추론으로 빠지고 + // "Done!"만 답으로 남음) 원문을 남겨 분류 오판을 재현할 수 있게 한다. + if (String(reply || '').trim().length < 40 && inlineThinking.length > 800) { + console.log(`[v2] THINKING-SEPARATION SUSPECT [${resolvedModelThisRound || '?'}]: reply=${JSON.stringify(String(reply || '').slice(0, 80))} thinkingLen=${inlineThinking.length} RAW=${JSON.stringify(String(response.content || '').slice(0, 6000))}`); + } } const rawAssistantText = String(response.content || '').trim(); diff --git a/src/gateway/chat/thinking-separation.ts b/src/gateway/chat/thinking-separation.ts index 4060ece..0db1232 100644 --- a/src/gateway/chat/thinking-separation.ts +++ b/src/gateway/chat/thinking-separation.ts @@ -68,8 +68,15 @@ function classify(cleaned: string, opts?: SeparationOptions): { reply: string; t const reasoningRE = /\b(the user|the tools|the instructions|I need to|I should|let me|the problem|the question|the answer|looking at|first,|second,|wait,|hmm|the response|the correct|the assistant|check the rules|according to|the file|the current|the plan)\b/i; const starterRE = /^(Okay|Ok|Alright|Let me|First|Hmm|So,? |Wait|The user|Looking|I need|I should|Now,? |Since|Given|Based on|Check)/i; + // 마크다운 표/목록/코드블록 문단은 추론 판정에서 제외한다(2026-10-03 실사례: 논문 목록 표의 제목 + // "A Review of the Current Literature"가 `the current`에 걸려 표 전체가 추론으로 분류되고, 마지막 문장 + // 조각 "|" 한 글자만 답으로 남았다). 구조화된 내용은 키워드 한 줄로 추론이라 단정할 수 없다. + const isStructured = (p: string) => + p.split('\n').filter(l => /^\s*(\||[-*]\s|\d+[.)]\s|```)/.test(l)).length >= 3; + let lastIdx = -1; for (let i = 0; i < paragraphs.length; i++) { + if (isStructured(paragraphs[i])) continue; if (reasoningRE.test(paragraphs[i]) || starterRE.test(paragraphs[i])) lastIdx = i; } diff --git a/tests/thinking-separation.test.ts b/tests/thinking-separation.test.ts index c8f464a..41f7ec5 100644 --- a/tests/thinking-separation.test.ts +++ b/tests/thinking-separation.test.ts @@ -164,3 +164,34 @@ describe('glm 영어 셀프토크 접두사 분리', () => { }); }); + +// ── 2026-10-03 실측: 논문 목록 표가 통째로 추론으로 분류돼 "|" 한 글자만 답으로 남은 사고 ── +// 표 첫 행 제목 "A Review of the Current Literature"가 reasoningRE의 `the current`에 걸렸다. +describe('markdown table is never classified as reasoning', () => { + const TABLE = `전체 146건의 검색 결과 중 벌크필 관련 논문 3건을 추출하여 정리해 드립니다. + +| 번호 | PMID | 저널 | 연도 | 제목 | +| :--- | :--- | :--- | :--- | :--- | +| 1 | 28443833 | J Adhes Dent | 2017 | Bulk-Fill Composites: A Review of the Current Literature. | +| 2 | 32030379 | J Adhes Dent | 2020 | Structural/Chemical Characterization and Bond Strength of a New Self-Adhesive Bulk-fill Restorative. | +| 3 | 29178706 | Am J Dent | 2017 | Stress distribution of bulk-fill resin composite in class II restorations. |`; + + test('표 전체가 답변으로 남는다', () => { + const r = separateThinkingFromContent(TABLE, { model: 'gemma4:31b-cloud' }); + assert.equal(r.thinking, ''); + assert.equal(r.reply, TABLE); + }); + + test('표 뒤에 짧은 맺음말이 있어도 표를 지우지 않는다', () => { + const r = separateThinkingFromContent(TABLE + '\n\nDone!', { model: 'gemma4:31b-cloud' }); + assert.ok(r.reply.includes('| 3 | 29178706 |')); + assert.ok(r.reply.includes('A Review of the Current Literature')); + }); + + test('실제 추론 문단은 여전히 분리된다', () => { + const t = 'The user wants a list. Let me check the tools first.\n\n핵심만 말씀드리면 3편입니다. 첫 번째 논문이 가장 최신입니다.'; + const r = separateThinkingFromContent(t, { model: 'gemma4:31b-cloud' }); + assert.ok(r.thinking.includes('The user wants')); + assert.ok(r.reply.startsWith('핵심만')); + }); +});