Fix needsThinkingRecovery to require tool loop context
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -83,7 +83,7 @@ export function convertAnthropicToGoogle(anthropicRequest) {
|
|||||||
let processedMessages = messages;
|
let processedMessages = messages;
|
||||||
const targetFamily = isClaudeModel ? 'claude' : isGeminiModel ? 'gemini' : null;
|
const targetFamily = isClaudeModel ? 'claude' : isGeminiModel ? 'gemini' : null;
|
||||||
|
|
||||||
if (isThinking && targetFamily && needsThinkingRecovery(messages, targetFamily)) {
|
if (isThinking && targetFamily && needsThinkingRecovery(messages)) {
|
||||||
logger.debug(`[RequestConverter] Applying thinking recovery for ${targetFamily}`);
|
logger.debug(`[RequestConverter] Applying thinking recovery for ${targetFamily}`);
|
||||||
processedMessages = closeToolLoopForThinking(messages, targetFamily);
|
processedMessages = closeToolLoopForThinking(messages, targetFamily);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,23 +388,24 @@ export function analyzeConversationState(messages) {
|
|||||||
/**
|
/**
|
||||||
* Check if conversation needs thinking recovery.
|
* Check if conversation needs thinking recovery.
|
||||||
*
|
*
|
||||||
* For Gemini: recovery needed when (tool loop OR interrupted tool) AND no valid thinking
|
* Recovery is only needed when:
|
||||||
* For Claude: recovery needed when no valid compatible thinking (cross-model detection)
|
* 1. We're in a tool loop or have an interrupted tool, AND
|
||||||
|
* 2. No valid thinking blocks exist in the current turn
|
||||||
|
*
|
||||||
|
* Cross-model signature compatibility is handled by stripInvalidThinkingBlocks
|
||||||
|
* during recovery (not here).
|
||||||
*
|
*
|
||||||
* @param {Array<Object>} messages - Array of messages
|
* @param {Array<Object>} messages - Array of messages
|
||||||
* @param {string} targetFamily - Target model family ('claude' or 'gemini')
|
|
||||||
* @returns {boolean} True if thinking recovery is needed
|
* @returns {boolean} True if thinking recovery is needed
|
||||||
*/
|
*/
|
||||||
export function needsThinkingRecovery(messages, targetFamily = null) {
|
export function needsThinkingRecovery(messages) {
|
||||||
const state = analyzeConversationState(messages);
|
const state = analyzeConversationState(messages);
|
||||||
|
|
||||||
if (targetFamily === 'claude') {
|
// Recovery is only needed in tool loops or interrupted tools
|
||||||
// Claude: only check if thinking is valid/compatible
|
if (!state.inToolLoop && !state.interruptedTool) return false;
|
||||||
return !state.turnHasThinking;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gemini (default): check tool loop/interrupted AND no thinking
|
// Need recovery if no valid thinking blocks exist
|
||||||
return (state.inToolLoop || state.interruptedTool) && !state.turnHasThinking;
|
return !state.turnHasThinking;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user