Repository navigation
Conversation
Greptile SummaryThis PR makes the Anthropic Messages Responses bridge emit terminal error events for failed Responses streams instead of reporting a successful empty turn or silently ending
Confidence Score: 4/5The PR appears safe to merge after addressing the non-blocking source-style issue in the new failure conversion branch The reachable Responses iterator raises one MidStreamFallbackError and then terminates, so the new handler emits one terminal error frame as intended; only maintainability conventions remain Files Needing Attention: litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/responses_adapters/streaming_iterator.py | Correctly surfaces the reachable mid-stream failure path, with non-blocking repository-style violations in the new parsing branch |
| tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py | Adds focused regression tests covering failed stream conversion and preserving successful completion behavior |
Reviews (1): Last reviewed commit: "fix(anthropic): surface response.failed ..." | Re-trigger Greptile
| # ---- response failed -> terminal error event ---- | ||
| if event_type == "response.failed": | ||
| event_obj = cast("object", event) | ||
| failed_response: object | None | ||
| if _is_json_object(event_obj): | ||
| failed_response = event_obj.get("response") | ||
| else: | ||
| failed_response = getattr(event_obj, "response", None) | ||
|
|
||
| failed_error: object | None = None | ||
| if failed_response is not None: | ||
| if _is_json_object(failed_response): | ||
| failed_error = failed_response.get("error") | ||
| else: | ||
| failed_error = getattr(failed_response, "error", None) | ||
|
|
||
| error_type: str | None = None | ||
| error_message: str | None = None | ||
| if failed_error is not None: | ||
| if _is_json_object(failed_error): | ||
| raw_type: object | None = failed_error.get("type") or failed_error.get("code") | ||
| raw_message: object | None = failed_error.get("message") | ||
| else: | ||
| raw_type = getattr(failed_error, "type", None) or getattr(failed_error, "code", None) | ||
| raw_message = getattr(failed_error, "message", None) | ||
| if isinstance(raw_type, str): | ||
| error_type = raw_type |
There was a problem hiding this comment.
The new failure branches add narration and rebind parsing variables, increasing maintenance cost and violating the repository's immutable-code convention
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
This rebinding is intentional: the failure payload can arrive as either an attr-style object or a dict, and the two shapes parse through different paths before converging on the error event (the file's guard-ok/mutable-ok annotations cover this contract). A pure-helper refactor would add indirection without changing behavior — happy to do it if maintainers prefer.
There was a problem hiding this comment.
That’s fair. The rebinding is serving as shape normalization: mappings and attribute-style objects need different extraction paths before converging on the terminal error event. Given the existing guard/mutable-ok annotations and no demonstrated benefit from adding a helper, I’m withdrawing this comment; no refactor is needed.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
pengzh1 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| "type": "error", | ||
| "error": { # mutable-ok: nested Anthropic error object | ||
| "type": error_type or "api_error", | ||
| "message": error_message or "Upstream response failed", |
There was a problem hiding this comment.
Low: Upstream error details bypass response redaction
A caller who triggers an in-stream failure receives the raw upstream message, including any credential-shaped values, filesystem paths, or internal hostnames present in it. Because this wrapper converts failures into SSE frames, the message bypasses redact_internal_details_from_client_message() in the proxy exception path; apply that redaction centrally in _make_error_event so both response.failed and MidStreamFallbackError are covered.
There was a problem hiding this comment.
Thanks for flagging. This mirrors the non-streaming pass-through path, which forwards the upstream error body as-is, and the streaming layer has no redaction hook to apply selectively. If maintainers want redaction here it is a semantic change across both paths, so deferring that to review rather than unilaterally diverging the two.
There was a problem hiding this comment.
Thanks for the detail. I can't automatically confirm this is safe to dismiss, so I'm leaving the thread open for a maintainer to make the call.
PR overviewThis PR updates the Anthropic Responses bridge so streaming One security issue remains open in the streaming error path. In-stream failures can expose unredacted upstream error text to callers, potentially revealing credentials, filesystem paths, or internal hostnames when those details are present. No issues have yet been addressed. Open issues (1)
Fixed/addressed: 0 · PR risk: 3/10 |
648d8e8 to
421f058
Compare
…dge streaming response.failed inside an already-200 stream used to share the response.completed branch and was relabelled as a successful empty turn (stop_reason end_turn), and the MidStreamFallbackError raised by the Responses iterator in 1.97+ was swallowed by a blanket except, leaving an unterminated stream. Emit the Anthropic streaming spec's terminal error event carrying the upstream error instead. Fixes BerriAI#39703
421f058 to
7dbd808
Compare
What changed
When
/v1/messagesstreams through the Responses bridge, a provider-side failure that arrives inside an already-200 stream (response.failed, e.g. exhausted quota) never reached the client: it shared theresponse.completedbranch and was relabelled as a successful empty turn (stop_reason: "end_turn", usage 0/0), and theMidStreamFallbackErrorraised by the Responses stream iterator was swallowed by a blanketexceptin__anext__, leaving a lonemessage_startand an unterminated stream.Now
response.failedand mid-streamMidStreamFallbackErrorare surfaced as the Anthropic streaming spec's terminalerrorevent, carrying the upstream error type/message (status-mapped per the Anthropic error taxonomy). Successfulresponse.completed/response.incompleteturns are unchanged.Fixes #39703
Verification
tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_streaming_iterator.py: on the unfixed source all 4 fail (fabricatedend_turn/ swallowed raise), with the fix all pass —173 passedin the directory,939 passedacrossexperimental_pass_through/+anthropic/messages/.ruff format --check/ruff check/ruff check --config ruff-tests.tomlclean on touched files.