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:
@@ -418,7 +418,9 @@ export function needsThinkingRecovery(messages) {
|
|||||||
* @returns {Array<Object>} Messages with invalid thinking blocks removed
|
* @returns {Array<Object>} Messages with invalid thinking blocks removed
|
||||||
*/
|
*/
|
||||||
function stripInvalidThinkingBlocks(messages, targetFamily = null) {
|
function stripInvalidThinkingBlocks(messages, targetFamily = null) {
|
||||||
return messages.map(msg => {
|
let strippedCount = 0;
|
||||||
|
|
||||||
|
const result = messages.map(msg => {
|
||||||
const content = msg.content || msg.parts;
|
const content = msg.content || msg.parts;
|
||||||
if (!Array.isArray(content)) return msg;
|
if (!Array.isArray(content)) return msg;
|
||||||
|
|
||||||
@@ -427,7 +429,10 @@ function stripInvalidThinkingBlocks(messages, targetFamily = null) {
|
|||||||
if (!isThinkingPart(block)) return true;
|
if (!isThinkingPart(block)) return true;
|
||||||
|
|
||||||
// Check generic validity (has signature of sufficient length)
|
// 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
|
// Check family compatibility if targetFamily is provided
|
||||||
if (targetFamily) {
|
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,
|
// 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.
|
// we drop it. We don't assume validity for unknown signatures.
|
||||||
if (signatureFamily !== targetFamily) {
|
if (signatureFamily !== targetFamily) {
|
||||||
|
strippedCount++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,6 +457,12 @@ function stripInvalidThinkingBlocks(messages, targetFamily = null) {
|
|||||||
}
|
}
|
||||||
return msg;
|
return msg;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (strippedCount > 0) {
|
||||||
|
logger.debug(`[ThinkingUtils] Stripped ${strippedCount} invalid/incompatible thinking block(s)`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user