Skip to content

fix(proxy): keep reasoning_items on the streaming fast-serialization path - #38908

Closed
CNSeniorious000 wants to merge 3 commits into
BerriAI:mainfrom
CNSeniorious000:fix-proxy-sse-reasoning-items
Closed

CNSeniorious000 wants to merge 3 commits into
BerriAI:mainfrom
CNSeniorious000:fix-proxy-sse-reasoning-items

Conversation

@CNSeniorious000

@CNSeniorious000 CNSeniorious000 commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Streaming chat completions through the proxy now preserve encrypted reasoning state, so clients can send it back on the next turn. Two regression tests cover the fast-path guard and the complete serialized response

Details

Relevant issues

Fixes #38907

Changes

The Responses-to-chat bridge can emit an empty-content chunk carrying reasoning_items. The proxy's fast serializer treats that chunk as plain text and drops the encrypted state

Add reasoning_items to unsupported_delta_fields so these chunks use the existing model_dump_json(exclude_none=True, exclude_unset=True) fallback

User Flow

Before, the streamed response loses the reasoning state needed for the next turn

  1. Send a streaming chat-completions request through the proxy to a model using the Responses bridge
  2. The reasoning chunk contains empty content but no encrypted reasoning items

After, the streamed response preserves the reasoning state

  1. Send the same streaming chat-completions request through the proxy
  2. The reasoning chunk includes its encrypted reasoning items for reuse in the next request

Validation

Latest validation at 5a55357, after merging main at 81d8c9a

LITELLM_LOCAL_MODEL_COST_MAP=True uv run pytest -q --disable-warnings --tb=short -o addopts= \
  tests/unit/proxy/proxy_server/test_streaming_helpers.py \
  tests/unit/test_utils.py
816 passed, 1 skipped, 30 warnings in 35.58s

Ruff with ruff-tests.toml passes for the streaming helper tests, and ruff format --check passes for litellm/proxy/proxy_server.py

The merged main includes the test-isolation fix from #47559 and the CI scripts required by the current lint workflow

On this commit, Python lint and the root unit shard pass. The root shard reports 6981 passed and 1 skipped, including the previously failing GPT-4o function-calling case

Pre-Submission checklist

  • Meaningful regression tests cover the dropped field
  • The affected test files pass locally
  • All required CI checks pass
  • The PR fixes one specific problem
  • Automated reviews on the current commit have finished

Type

Bug Fix

Caveats

Medium

  • OSV flags Vite dependencies inherited unchanged from main

The scan reports GHSA-698v-4r3x-3vcv for Vite 7.3.5 in the dashboard lockfile and 8.3.0 in the extension lockfile. Both lockfiles are identical to main at 81d8c9a

Low

  • No paid live-model stream was rerun on this commit

The original live-proxy observation is recorded in #38907. Current validation covers serialization and unit tests

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR prevents streaming proxy responses from dropping reasoning_items by routing chunks containing that field through canonical model serialization.

  • Adds reasoning_items to the fields unsupported by the text-only fast serializer.
  • Adds focused tests covering fast-path rejection and preservation in serialized output.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security issues identified.

The new guard handles every non-None reasoning_items value, including empty lists, and the fallback serializer preserves the declared field; the tests exercise the same model types and serialization helper used by the proxy.

Important Files Changed

Filename Overview
litellm/proxy/proxy_server.py Correctly routes deltas containing reasoning_items away from the limited fast serializer and into canonical serialization.
tests/test_litellm/proxy/proxy_server/test_streaming_helpers.py Adds representative regression coverage using production response models and the actual streaming serialization entry point.

Reviews (1): Last reviewed commit: "fix(proxy): keep reasoning_items on the ..." | Re-trigger Greptile

@codspeed

codspeed Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing CNSeniorious000:fix-proxy-sse-reasoning-items (5a55357) with main (81d8c9a)

Open in CodSpeed

@codecov

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:46
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@banVD

banVD commented Sep 18, 2026

Copy link
Copy Markdown

Independent confirmation of this bug on a production gateway, and of the fix.

Setup: LiteLLM proxy v1.101.0 (stock ghcr image), Azure OpenAI GPT reasoning model via the Responses→Chat bridge, stream: true, extra_body: {"include": ["reasoning.encrypted_content"], "store": false}, tool-call
round.

Observed on the wire (unpatched): the terminal chunk that should carry delta.reasoning_items arrives as

data: {"id":"...","object":"chat.completion.chunk","created":...,"model":"...","choices":[{"index":0,"delta":{"content":""}}]}
data: {"id":"...","object":"chat.completion.chunk","created":...,"model":"...","choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}]}

No reasoning_items anywhere in the stream. The client therefore has no encrypted reasoning state to replay on the next turn, so every tool-loop turn restarts reasoning from scratch.

Evidence it is the fast serializer: those two chunks are the only ones in the stream with key order id,object,created,model (the hand-built dict). Every tool-call and usage chunk in the same stream has pydantic's order
id,created,model,object. Offline, the same chunk survives CustomStreamWrapper and is lost only in the proxy serializer, matching the issue description.

Fix verification: cherry-picked this PR's one-line change onto v1.101.0 and onto current main (still missing there as of today). Serializer-level tests fail before, pass after;
tests/test_litellm/proxy/proxy_server/test_streaming_helpers.py, test_response_model_sanitization.py and litellm_core_utils/test_streaming_handler.py show no new failures. Non-reasoning chunks produce byte-identical
output before and after.

We need this on our gateways and will carry the patch locally until it lands. Would appreciate a maintainer look; #38961 is the same change without the test.

@CNSeniorious000
CNSeniorious000 force-pushed the fix-proxy-sse-reasoning-items branch from ba8d403 to 20d4a0d Compare October 7, 2026 19:38
@CNSeniorious000

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T18:57:39.963267Z 5a55357 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20d4a0d5dc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a5535793a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

chunk.choices[0].delta.reasoning_items = [
{"id": "rs_abc", "type": "reasoning", "encrypted_content": "ENCRYPTED-BLOB"}
]
assert _fast_serialize_simple_model_response_stream(chunk) is None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Drop the fast-path sentinel regression test

When fast serialization later supports reasoning_items directly, this assertion fails despite identical output; keep only the output-level serialization regression below.

AGENTS.md reference: AGENTS.md:L26-L26

Useful? React with 👍 / 👎.

Comment on lines +557 to +560
chunk = _simple_chunk(content="")
chunk.choices[0].delta.reasoning_items = [
{"id": "rs_abc", "type": "reasoning", "encrypted_content": "ENCRYPTED-BLOB"}
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Construct complete Final chunks without mutation

These tests leave chunk unannotated and mutate its delta after setup; build complete Final chunks to keep their arrange phase immutable.

AGENTS.md reference: AGENTS.md:L96-L97

Useful? React with 👍 / 👎.

@mateo-berri

Copy link
Copy Markdown
Contributor

Closing as superseded by #49398, which deleted the streaming fast path that dropped reasoning_items from chunks. Thanks for the fix

@mateo-berri mateo-berri closed this Nov 2, 2026
@CNSeniorious000
CNSeniorious000 deleted the fix-proxy-sse-reasoning-items branch November 3, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Proxy strips delta.reasoning_items from streaming chunks on the fast-serialization path

4 participants