fix: address cubic review — broaden error detection, add test coverage

1. isAgentNotFoundError now handles:
   - Plain objects with .message field (not just Error instances)
   - "agent.name"/"undefined" error variants from SDK validation
   - The original "Agent not found" format

2. New tests:
   - agent.name/undefined error variant triggers fallback
   - Plain object errors with .message field trigger fallback
   - "fallback also fails" test now verifies retry was attempted (callCount=2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jim Park
2026-04-04 22:17:22 -07:00
parent 9470cbe090
commit 51508c4949
2 changed files with 142 additions and 2 deletions
+13 -2
View File
@@ -11,8 +11,19 @@ import type { ConcurrencyManager } from "./concurrency"
export const FALLBACK_AGENT = "general"
export function isAgentNotFoundError(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error)
return message.includes("Agent not found")
const message =
typeof error === "string"
? error
: error instanceof Error
? error.message
: typeof error === "object" && error !== null && typeof (error as { message?: unknown }).message === "string"
? (error as { message: string }).message
: String(error)
return (
message.includes("Agent not found") ||
message.includes("agent.name") ||
(message.includes("agent") && message.includes("undefined"))
)
}
export function buildFallbackBody(