From dd9f8abb0cd075e24998fe13ba787dc885d7b555 Mon Sep 17 00:00:00 2001 From: Rahul Selvaraj <55731288+Laihu08@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:33:02 +0800 Subject: [PATCH] fix(hooks): normalize whitespace before matching the classifier notice isClassifierNotice now collapses whitespace runs itself, so the session-end hook drops a notice wrapped across lines the same way the LLM summary path already did. Assisted-by: Claude --- scripts/lib/llm-summary.js | 5 +++-- tests/hooks/session-end.test.js | 12 ++++++++++++ tests/lib/llm-summary.test.js | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/lib/llm-summary.js b/scripts/lib/llm-summary.js index dd85b39a2..71bfc21c7 100644 --- a/scripts/lib/llm-summary.js +++ b/scripts/lib/llm-summary.js @@ -35,10 +35,11 @@ function getContextThreshold() { /** * True when a user-turn text is the harness notice left after a * safety-classifier stop. Anchored to the whole message so user text that - * quotes or follows the notice is kept. + * quotes or follows the notice is kept. Whitespace runs (including + * newlines) are collapsed first so every caller matches the same text. */ function isClassifierNotice(text) { - return CLASSIFIER_NOTICE.test(text); + return CLASSIFIER_NOTICE.test(String(text).replace(/\s+/g, ' ').trim()); } /** diff --git a/tests/hooks/session-end.test.js b/tests/hooks/session-end.test.js index 044b3766c..875e5f58e 100644 --- a/tests/hooks/session-end.test.js +++ b/tests/hooks/session-end.test.js @@ -105,6 +105,17 @@ function testNoticeOnlyTranscript() { }); } +function testDropsMultilineClassifierNotice() { + const wrapped = CLASSIFIER_NOTICE_TEXT.replace('safety classifier', 'safety\nclassifier'); + withTranscript('3867eeee-ffff-4aaa-8bbb-cccccccc3867', [ + JSON.stringify({ type: 'user', content: 'Refactor the config loader' }), + JSON.stringify({ type: 'user', content: wrapped }), + ], out => { + assert.ok(out.includes('- Refactor the config loader'), `expected the real user task in:\n${out}`); + assert.ok(!/safety\s+classifier/.test(out), `wrapped notice must not be summarized:\n${out}`); + }); +} + function testKeepsMessageQuotingNotice() { const userText = 'Why did I see "Your response above was stopped by a safety classifier" earlier?'; withTranscript('3867cccc-dddd-4eee-8fff-aaaaaaaa3867', [JSON.stringify({ type: 'user', content: userText })], out => { @@ -116,6 +127,7 @@ function runClassifierNoticeTests() { const results = [ test('drops safety-classifier notices from summary tasks', testDropsClassifierNotice), test('drops the longer classifier notice from summary tasks', testDropsLongClassifierNotice), + test('drops a classifier notice wrapped across lines', testDropsMultilineClassifierNotice), test('writes no summary for a transcript holding only a classifier notice', testNoticeOnlyTranscript), test('keeps a user message that only mentions the classifier notice', testKeepsMessageQuotingNotice), ]; diff --git a/tests/lib/llm-summary.test.js b/tests/lib/llm-summary.test.js index 49b792cf6..322436d6c 100644 --- a/tests/lib/llm-summary.test.js +++ b/tests/lib/llm-summary.test.js @@ -196,6 +196,15 @@ test('isClassifierNotice matches only the whole notice', () => { assert.strictEqual(isClassifierNotice('Why did I see "Your response above was stopped by a safety classifier"?'), false); }); +test('drops a classifier notice wrapped across lines', () => { + const wrapped = CLASSIFIER_NOTICE_LONG_TEXT.replace('safety classifier', 'safety\nclassifier').replace(' The rest', ' \nThe rest'); + assert.strictEqual(isClassifierNotice(wrapped), true); + const p = writeTranscript([userEntry('Refactor the config loader'), userEntry(wrapped), assistantEntry('Done.')]); + const result = extractConversationText(p); + assert.ok(result.includes('Refactor the config loader')); + assert.ok(!result.includes('withheld') && !result.includes('safety classifier'), result); +}); + // --- getContextRemainingPct --- console.log('\ngetContextRemainingPct:');