From 53f8d7f6cc626b43efd2de41af00941137eac5a2 Mon Sep 17 00:00:00 2001 From: Badri Narayanan S Date: Sat, 3 Jan 2026 23:29:21 +0530 Subject: [PATCH] Add debug logging when stripping thinking blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/format/thinking-utils.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/format/thinking-utils.js b/src/format/thinking-utils.js index 3dcf883..06bca85 100644 --- a/src/format/thinking-utils.js +++ b/src/format/thinking-utils.js @@ -418,7 +418,9 @@ export function needsThinkingRecovery(messages) { * @returns {Array} Messages with invalid thinking blocks removed */ function stripInvalidThinkingBlocks(messages, targetFamily = null) { - return messages.map(msg => { + let strippedCount = 0; + + const result = messages.map(msg => { const content = msg.content || msg.parts; if (!Array.isArray(content)) return msg; @@ -427,7 +429,10 @@ function stripInvalidThinkingBlocks(messages, targetFamily = null) { if (!isThinkingPart(block)) return true; // Check generic validity (has signature of sufficient length) - if (!hasValidSignature(block)) return false; + if (!hasValidSignature(block)) { + strippedCount++; + return false; + } // Check family compatibility if targetFamily is provided if (targetFamily) { @@ -437,6 +442,7 @@ function stripInvalidThinkingBlocks(messages, targetFamily = null) { // Strict validation: If we don't know the family (cache miss) or it doesn't match, // we drop it. We don't assume validity for unknown signatures. if (signatureFamily !== targetFamily) { + strippedCount++; return false; } } @@ -451,6 +457,12 @@ function stripInvalidThinkingBlocks(messages, targetFamily = null) { } return msg; }); + + if (strippedCount > 0) { + logger.debug(`[ThinkingUtils] Stripped ${strippedCount} invalid/incompatible thinking block(s)`); + } + + return result; } /**