fix(copilot): check error field (not just content) for transient API errors

The transient error detection was checking str(sdk_msg.content) which
contains content blocks, not the actual error string from sdk_msg.error.
Now checks both the error field and content preview for transient patterns.
This commit is contained in:
Zamil Majdy
2026-03-17 12:45:12 +07:00
parent 2e8b984f8e
commit a31fc008e8

View File

@@ -1093,6 +1093,7 @@ async def stream_chat_completion_sdk(
# so we can debug Anthropic API 400s surfaced by the CLI.
sdk_error = getattr(sdk_msg, "error", None)
if isinstance(sdk_msg, AssistantMessage) and sdk_error:
error_text = str(sdk_error)
error_preview = str(sdk_msg.content)[:500]
logger.error(
"[SDK] [%s] AssistantMessage has error=%s, "
@@ -1107,7 +1108,10 @@ async def stream_chat_completion_sdk(
# ECONNRESET) — replace raw message with a
# user-friendly error and mark as retryable so the
# frontend can offer a retry button.
if is_transient_api_error(error_preview):
# Check both the error field and content for patterns.
if is_transient_api_error(error_text) or is_transient_api_error(
error_preview
):
logger.warning(
"%s Transient Anthropic API error detected, "
"suppressing raw error text",