fix(session-recovery): reorder error detection to prevent false tool_result_missing match

Anthropic's extended thinking error messages contain 'tool_use' and 'tool_result'
in the documentation URL text, causing incorrect detection as tool_result_missing
instead of thinking_block_order.

Fix: Check thinking_block_order BEFORE tool_result_missing.
This commit is contained in:
justsisyphus
2026-01-21 11:00:30 +09:00
parent 650e464814
commit 137add8b83
2 changed files with 27 additions and 4 deletions
+7 -4
View File
@@ -125,10 +125,9 @@ function extractMessageIndex(error: unknown): number | null {
export function detectErrorType(error: unknown): RecoveryErrorType {
const message = getErrorMessage(error)
if (message.includes("tool_use") && message.includes("tool_result")) {
return "tool_result_missing"
}
// IMPORTANT: Check thinking_block_order BEFORE tool_result_missing
// because Anthropic's extended thinking error messages contain "tool_use" and "tool_result"
// in the documentation URL, which would incorrectly match tool_result_missing
if (
message.includes("thinking") &&
(message.includes("first block") ||
@@ -145,6 +144,10 @@ export function detectErrorType(error: unknown): RecoveryErrorType {
return "thinking_disabled_violation"
}
if (message.includes("tool_use") && message.includes("tool_result")) {
return "tool_result_missing"
}
return null
}