fix(providers): keep serde errors explicit

This commit is contained in:
chengyongru 2026-08-03 17:20:17 +08:00 committed by chengyongru
parent 6eda67b50c
commit 44b7e1bf41
2 changed files with 4 additions and 33 deletions

View File

@ -1082,16 +1082,6 @@ class OpenAICompatProvider(LLMProvider):
"not supported",
"unknown parameter",
"unrecognized request argument",
# Serde-style body rejection: the endpoint could not parse the
# Responses wire format (e.g. DeepSeek's Responses gateway
# rejecting an input item shape with "Failed to deserialize the
# JSON body ... expected a sequence"). These are compatibility
# failures: fall back to Chat Completions for the same model.
"failed to deserialize",
"invalid type",
"expected a sequence",
"expected a struct",
"unknown field",
)
return any(marker in body_text for marker in compatibility_markers)

View File

@ -166,8 +166,9 @@ class _FakeAPIError(Exception):
self.response = None
def test_serde_deserialize_error_triggers_fallback():
# DeepSeek Responses gateway rejecting the wire body (observed Aug 2026).
def test_serde_deserialize_error_does_not_trigger_fallback():
# Serde errors can also identify malformed user-provided request fields.
# The known DeepSeek wire-shape bug is fixed at serialization time instead.
err = _FakeAPIError(400, {
"message": (
"Failed to deserialize the JSON body into the target type: "
@ -177,17 +178,7 @@ def test_serde_deserialize_error_triggers_fallback():
"type": "invalid_request_error",
"param": None,
})
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
def test_invalid_type_error_triggers_fallback():
err = _FakeAPIError(422, "input[0]: invalid type: map, expected a string")
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
def test_unknown_field_error_triggers_fallback():
err = _FakeAPIError(400, "unknown field `foo`, expected one of `input`, `instructions`")
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is False
def test_legacy_compatibility_markers_still_trigger_fallback():
@ -195,16 +186,6 @@ def test_legacy_compatibility_markers_still_trigger_fallback():
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is True
def test_unrelated_400_does_not_trigger_fallback():
err = _FakeAPIError(400, {"message": "rate limit exceeded", "type": "rate_limit_error"})
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is False
def test_server_error_does_not_trigger_fallback():
err = _FakeAPIError(500, {"message": "internal server error"})
assert OpenAICompatProvider._should_fallback_from_responses_error(err) is False
# ======================================================================
# DeepSeek Responses wire shape (PR #5214 root cause)
# ======================================================================