Add debug logging when stripping thinking blocks

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Badri Narayanan S
2026-01-03 23:29:21 +05:30
parent 12e427e9d5
commit 53f8d7f6cc

View File

@@ -418,7 +418,9 @@ export function needsThinkingRecovery(messages) {
* @returns {Array<Object>} 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;
}
/**