Repository navigation
fix(responses): honor caller stream flag when provider forces SSE (internal copy of #34095) #41235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 5 commits into
main
from
litellm_fix_responses_honor_caller_stream_flag
Oct 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5e2e009
fix(responses): honor caller stream flag when provider forces SSE
SunSet0418 04e164b
test(chatgpt): inject the authenticator into the responses config so …
mateo-berri 20fe356
Merge remote-tracking branch 'origin/main' into litellm_fix_responses…
mateo-berri 78b0bea
fix(responses): treat an extra_body stream flag as the caller's own a…
mateo-berri f1cdfae
test(integration): audit the chatgpt caller stream flag across respon…
mateo-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
| from collections.abc import Mapping, Sequence | ||
| from pathlib import Path | ||
| from typing import Final | ||
|
|
||
| from integration._support import responses_vendor as rv | ||
| from pydantic import JsonValue | ||
|
|
||
| from litellm.integrations.custom_logger import CustomLogger | ||
|
|
||
| OUT_ENVIRONMENT: Final = "AGENTIC_PROBE_OUT" | ||
|
|
||
|
|
||
| class AgenticProbe(CustomLogger): | ||
| """Records every agentic-loop hook call the proxy makes, one JSON line per call, and never runs a loop.""" | ||
|
|
||
| async def async_should_run_agentic_loop( | ||
| self, | ||
| response: object, | ||
| model: str, | ||
| messages: Sequence[Mapping[str, object]], | ||
| tools: Sequence[Mapping[str, object]] | None, | ||
| stream: bool, | ||
| custom_llm_provider: str, | ||
| kwargs: Mapping[str, object], | ||
| ) -> tuple[bool, dict[str, object]]: # mutable-ok: the CustomLogger hook contract returns a dict | ||
| out: Final = os.environ.get(OUT_ENVIRONMENT) | ||
| if out: | ||
| line: Final[Mapping[str, JsonValue]] = { | ||
| "marker": rv.newest_marker(f"{messages!s} {response!s}"), | ||
| "surface": str(kwargs.get("_agentic_loop_api_surface")), | ||
| "response_type": type(response).__name__, | ||
| "stream": stream, | ||
| "model": model, | ||
| "provider": custom_llm_provider, | ||
| } | ||
| with open(out, "a", encoding="utf-8") as sink: | ||
| sink.write(json.dumps(line) + "\n") | ||
| return False, {} | ||
|
|
||
|
|
||
| probe: Final = AgenticProbe() | ||
|
|
||
|
|
||
| def lines(path: Path, marker: str) -> tuple[Mapping[str, JsonValue], ...]: | ||
| recorded: Final = tuple(rv.JSON_OBJECT.validate_json(line) for line in path.read_text().splitlines() if line) | ||
| return tuple(line for line in recorded if line["marker"] == marker) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a Manus caller sets
extra_body={"stream": true}without setting the top-levelstreamflag, this line selects a real streaming iterator. Butshould_fake_streamreceives only the top-level flag, so Manus does not enable the fake-stream path it needs because it does not support real-time streaming. The request is sent through the SSE iterator instead and fails to produce the expected stream. The async handler has the same mismatch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing: fake_stream is decided in responses/main.py from the top-level flag before this handler runs, the same on main, and extra_body.stream never fed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right — this mismatch is pre-existing and is not introduced by this PR.
fake_streamis determined earlier from the top-levelstreamflag, and this handler has never propagatedextra_body.streaminto that decision (on main or in this change). The newcaller_requested_streamonly selects the response shape after that existing decision, so this comment does not identify a regression here. I’m withdrawing it.