Skip to content

fix(responses/mcp): keep follow-up calls stateless when store=false - #36575

Merged
mateo-berri merged 5 commits into
litellm_internal_stagingfrom
litellm_mcp_stateless_follow_up_zdr
Sep 5, 2026
Merged

mateo-berri merged 5 commits into
litellm_internal_stagingfrom
litellm_mcp_stateless_follow_up_zdr

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • MCP auto-execution breaks for store=false (zero data retention) callers
  • Follow-up call always sent previous_response_id, which was never persisted
  • Reasoning items were dropped, losing reasoning.encrypted_content

How it solves it:

  • With store=false, the follow-up call keeps the caller's own previous_response_id (usually none)
  • Replay reasoning output items (with encrypted content) in the follow-up input, in output order
  • Same behavior for streaming and non-streaming MCP paths
  • Stateful (store unset/true) behavior is unchanged

User Flow

Before: a developer on zero data retention calls /v1/responses with an MCP tool and the request fails once the tool has run

  1. They send POST https://litellm-domain/v1/responses with "store": false, a reasoning model, "include": ["reasoning.encrypted_content"], and "tools": [{"type": "mcp", "server_url": "litellm_proxy", "require_approval": "never"}]
  2. The model asks for an MCP tool, the gateway runs it and asks the model again, this time pointing at the id of the first response
  3. The provider answers Previous response with id 'resp_...' not found, so the caller gets HTTP 400 instead of an answer
  4. With "stream": true the answer does stream back, but the second model turn is sent without the model's encrypted reasoning from the first turn, so the model reasons again from scratch

After: the same request completes and returns the tool-informed answer

  1. They send the same POST https://litellm-domain/v1/responses with "store": false and the same MCP tool
  2. The model asks for an MCP tool and the gateway runs it, then asks the model again by resending the whole turn, its encrypted reasoning included, instead of referencing an id
  3. A normal response comes back with HTTP 200, status: "completed", and output text that uses the tool result
  4. With "stream": true the answer streams back and the second model turn carries the encrypted reasoning from the first turn
  5. Sending "store": true (or omitting it) behaves exactly as before

Relevant issues

Linear ticket

Resolves LIT-5427

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Shared setup for both sides: two proxies ran at the same time, one per commit, each from its own checkout and venv with its own Postgres, booted with python litellm/proxy/proxy_cli.py --config lit5427-qa-config.yaml --port <port> --num_workers 2 --detailed_debug. Before is the merge base b3c867c on port 25797, After is the PR tip 4b24e3b on port 30453. Every model call is real: OpenAI gpt-5.6 and gpt-5.5, Anthropic claude-sonnet-5, and a real stdio MCP server registered as math_stdio (tests/mcp_tests/mcp_server.py). The verdict for each case is the HTTP status and body the caller gets back; the "outbound follow-up" line under it is the second request the proxy sent to the provider, read from the --detailed_debug log, and is there only to show why. gpt-5.6 returned no reasoning items in most of these runs, so the reasoning replay cases use gpt-5.5, which does

general_settings:
  master_key: sk-lit5427-qa

litellm_settings:
  drop_params: true

model_list:
  - model_name: gpt-5.6
    litellm_params:
      model: openai/gpt-5.6
      api_key: os.environ/OPENAI_API_KEY
  - model_name: gpt-5.5
    litellm_params:
      model: openai/gpt-5.5
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude
    litellm_params:
      model: anthropic/claude-sonnet-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: gpt-5.6-zdr
    litellm_params:
      model: openai/gpt-5.6
      api_key: os.environ/OPENAI_API_KEY
      store: false

mcp_servers:
  math_stdio:
    transport: stdio
    command: python3
    args:
      - tests/mcp_tests/mcp_server.py
    allow_all_keys: true

Every request below uses the same tool list, TOOLS='[{"type":"mcp","server_url":"litellm_proxy","server_label":"litellm","require_approval":"never"}]', and the same headers, -H "Authorization: Bearer sk-lit5427-qa" -H "Content-Type: application/json". Prompts: P1 is Use the available tools to compute 17 + 25, then tell me the result., P2 is Using the tools, compute 17 + 25 and separately compute 6 * 7 (one tool call each), then report both results in one sentence., P3 is Use the tools to compute 17 + 25 and separately 6 * 7 (one tool call each), then decide whether each result is prime and explain briefly., P4 is First use a tool to compute 17 + 25. Only after you have that result, use a tool to multiply that result by 2. Then report both numbers in one sentence.

Before (b3c867c)

ZDR, single tool, non-streaming (gpt-5.6, effort low)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P1"'","store":false,"reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 400 with {"error":{"message":"litellm.BadRequestError: OpenAIException - {\"error\": {\"message\": \"Previous response with id 'resp_07cbb0153c6939bf016a9b5cbfc1c087d0896af95efc90612c' not found.\", \"type\": \"invalid_request_error\", \"param\": \"previous_response_id\", \"code\": \"previous_response_not_found\"}}. Received Model Group=gpt-5.6", "code":"400"}}
  3. Outbound follow-up: store=False previous_response_id=resp_07cbb0153c69... input=[message, function_call call_34TyY4s, function_call_output call_34TyY4s]

ZDR, two tools, non-streaming (gpt-5.6, effort medium)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P2"'","store":false,"reasoning":{"effort":"medium"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 400 with the same previous_response_not_found error for resp_0d73e735e1f87178016a9b5cc4868887d0b5995bacf109c73a
  3. Outbound follow-up: store=False previous_response_id=resp_0d73e735e1f8... input=[message, function_call call_3ZAbsxb, function_call call_94OVPFd, function_call_output call_3ZAbsxb, function_call_output call_94OVPFd]

ZDR, streaming (gpt-5.6, effort low)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P1"'","store":false,"stream":true,"reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 200, SSE events response.created: 2, response.output_item.done: 4, response.output_text.done: 1, response.completed: 2, [DONE]: 1, text 42
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_7nrwdKy, function_call_output call_7nrwdKy] (no reasoning item, none emitted by this model)

Stateful regression (gpt-5.6, store unset)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P1"'","reasoning":{"effort":"low"},"tools":'"$TOOLS"'}'
  2. HTTP 200, status: completed, output types [message, mcp_tools_fetched, tool_execution_results], text 42
  3. Outbound follow-up: store=None previous_response_id=resp_09ef2659e00c... input=[message, function_call call_I5mFTs1, function_call_output call_I5mFTs1]

ZDR, high reasoning, non-streaming (gpt-5.5)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.5","input":"'"$P3"'","store":false,"reasoning":{"effort":"high"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 400 with previous_response_not_found for resp_0e1f5bfc730f57be016a9b5cd6e37487d0b803426e2c216ab3
  3. Outbound follow-up: store=False previous_response_id=resp_0e1f5bfc730f... input=[message, function_call ..., function_call_output ...] (the rs_ reasoning item from the first response is missing)

ZDR, high reasoning, streaming (gpt-5.5)

  1. Same body as the previous case plus "stream":true, sent with curl -sS -N
  2. HTTP 200, SSE response.created: 2, response.output_item.done: 7, response.completed: 2, [DONE]: 1, text starts 17 + 25 = 42 and says neither result is prime
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_7HlYe1Q, function_call call_GEaMp90, function_call_output call_7HlYe1Q, function_call_output call_GEaMp90] (the rs_ reasoning item from the first response is missing)

ZDR without include (gpt-5.5, effort low, non-streaming)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.5","input":"'"$P1"'","store":false,"reasoning":{"effort":"low"},"tools":'"$TOOLS"'}'
  2. HTTP 400 with previous_response_not_found for resp_013f73d48ffc18f9016a9b5ce904bc87d0a560830742f90a87
  3. Outbound follow-up: store=False previous_response_id=resp_013f73d48ffc... input=[message, function_call ..., function_call_output ...]

ZDR with a caller-supplied previous_response_id (gpt-5.6)

  1. Store a prior turn first: curl -sS -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"Remember: my favorite number is 42. Reply with OK.","store":true,"reasoning":{"effort":"low"}}' returns id: resp_...006...
  2. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"Use the tools to add my favorite number and 8, then tell me the result.","store":false,"previous_response_id":"<that id>","reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  3. HTTP 400 with previous_response_not_found for resp_02bfee05b7e97d33016a9b5cf3d24c87d09b751cc01671d62e, the unstored first-turn id, not the caller's stored one
  4. Outbound follow-up: store=False previous_response_id=resp_02bfee05b7e9... input=[message, function_call ..., function_call_output ...]

ZDR, high reasoning, no include, non-streaming (gpt-5.5)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.5","input":"'"$P3"'","store":false,"reasoning":{"effort":"high"},"tools":'"$TOOLS"'}'
  2. HTTP 400 with previous_response_not_found for resp_00b96e9013209c42016a9b5ed1024c87d088e36bc73748112e
  3. Outbound follow-up: store=False previous_response_id=resp_00b96e901320... input=[message, function_call call_0kLfwF4, function_call_output call_0kLfwF4]

ZDR, high reasoning, no include, streaming (gpt-5.5)

  1. Same body as the previous case plus "stream":true, sent with curl -sS -N
  2. HTTP 200, SSE response.created: 6, response.output_item.done: 24, response.completed: 6, [DONE]: 1, six model rounds whose text fragments are 42 five times and then a summary sentence
  3. Outbound follow-ups: six, each store=False previous_response_id=None carrying only the latest round's function_call and function_call_output, never a reasoning item

store: false set in the model's config, not the request (gpt-5.6-zdr)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6-zdr","input":"'"$P1"'","reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 400 with previous_response_not_found for resp_096f04a1a6dcca31016a9b5ecc773487d0b6f72aa002bc2239, Received Model Group=gpt-5.6-zdr
  3. Outbound follow-up: store=False previous_response_id=resp_096f04a1a6dc... input=[message, function_call call_hBRksDb, function_call_output call_hBRksDb]

ZDR through the Anthropic bridge, non-streaming (claude-sonnet-5)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"claude","input":"'"$P1"'","store":false,"reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 200, status: completed, text 17 + 25 = 42
  3. Outbound follow-up: a chat-style user, assistant, user turn to Anthropic, no previous_response_id involved

ZDR through the Anthropic bridge, streaming (claude-sonnet-5)

  1. Same body as the previous case plus "stream":true, sent with curl -sS -N
  2. HTTP 200, text 17 + 25 = 42
  3. Outbound follow-up: same chat-style turn as the non-streaming case

/v1/chat/completions control with store: false (gpt-5.6)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/chat/completions -d '{"model":"gpt-5.6","messages":[{"role":"user","content":"'"$P1"'"}],"store":false,"reasoning_effort":"low","tools":'"$TOOLS"'}'
  2. HTTP 200, text 17 + 25 = **42**.
  3. Outbound follow-up: previous_response_id=None (the chat path never chained on a response id)

Stateful, high reasoning control (gpt-5.5, store unset)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.5","input":"'"$P3"'","reasoning":{"effort":"high"},"tools":'"$TOOLS"'}'
  2. HTTP 200, status: completed; this run the model asked for its two tools one after the other, so the single follow-up round ended on a function_call and the text was empty
  3. Outbound follow-up: store=None previous_response_id=resp_0a54535db0c1... input=[message, function_call call_olu5ynn, function_call_output call_olu5ynn]

ZDR, sequential tool rounds, streaming (gpt-5.6)

  1. curl -sS -N -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P4"'","store":false,"stream":true,"reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 200, SSE response.created: 6, response.output_item.done: 15, response.completed: 6, response.output_text.done: 1, text 17 + 25 = 42, and 42 × 2 = 84.
  3. Outbound follow-ups: five, each store=False previous_response_id=None input=[message, function_call ..., function_call_output ...], never a reasoning item

ZDR, sequential tool rounds, non-streaming (gpt-5.6)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P4"'","store":false,"reasoning":{"effort":"low"},"include":["reasoning.encrypted_content"],"tools":'"$TOOLS"'}'
  2. HTTP 400 with previous_response_not_found for resp_0593dd2d18f64279016a9b5da2c87487d09eea1a195b10b464
  3. Outbound follow-up: store=False previous_response_id=resp_0593dd2d18f6... input=[message, function_call ..., function_call_output ...]

Stateful, sequential tool rounds, non-streaming (gpt-5.6, store unset)

  1. curl -sS -w '\nHTTP %{http_code}\n' -X POST http://127.0.0.1:25797/v1/responses -d '{"model":"gpt-5.6","input":"'"$P4"'","reasoning":{"effort":"low"},"tools":'"$TOOLS"'}'
  2. HTTP 200, status: completed, empty text: the single follow-up round ended on the second function_call
  3. Outbound follow-up: store=None previous_response_id=resp_03798bfc145d... input=[message, function_call ..., function_call_output ...]

Spend rows

  1. curl -sS http://127.0.0.1:25797/spend/logs -H "Authorization: Bearer sk-lit5427-qa"
  2. 36 rows, total spend $0.0183: every ZDR /v1/responses case above is logged as a failed call

After (4b24e3b)

ZDR, single tool, non-streaming (gpt-5.6, effort low)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, output types [message, mcp_tools_fetched, tool_execution_results], text 17 + 25 = **42**.
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_cgIY87q, function_call_output call_cgIY87q]

ZDR, two tools, non-streaming (gpt-5.6, effort medium)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, text 17 + 25 = 42, and 6 × 7 = 42.
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_yjSfxLA, function_call call_mSNurOU, function_call_output call_yjSfxLA, function_call_output call_mSNurOU]

ZDR, streaming (gpt-5.6, effort low)

  1. Same command as Before, against port 30453
  2. HTTP 200, SSE events response.created: 2, response.output_item.done: 4, response.output_text.done: 1, response.completed: 2, [DONE]: 1, text 17 + 25 = **42**.
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_miALrfB, function_call_output call_miALrfB] (no reasoning item, none emitted by this model)

Stateful regression (gpt-5.6, store unset)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, output types [message, mcp_tools_fetched, tool_execution_results], text 17 + 25 = **42**.
  3. Outbound follow-up: store=None previous_response_id=resp_0f1b2c2cecb8... input=[message, function_call call_q6PfdlV, function_call_output call_q6PfdlV] (unchanged: still chained on the first response id)

ZDR, high reasoning, non-streaming (gpt-5.5)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed; this run the model asked for its two tools one after the other, so the single follow-up round ended on a function_call and the text was empty (same limit the stateful control hits below)
  3. Outbound follow-up: store=False previous_response_id=None input=[message, reasoning rs_096f709b2... (encrypted_content set), function_call call_2u4bjhT, function_call_output call_2u4bjhT]

ZDR, high reasoning, streaming (gpt-5.5)

  1. Same command as Before, against port 30453
  2. HTTP 200, SSE response.created: 6, response.output_item.done: 15, response.output_text.done: 1, response.completed: 6, [DONE]: 1, text starts 17 + 25 = 42 and says neither result is prime
  3. Outbound follow-ups: five, the first store=False previous_response_id=None input=[message, reasoning rs_04adff0ee... (encrypted_content set), function_call call_FIGfTKQ, function_call_output call_FIGfTKQ], the last carrying reasoning rs_0ef3a884d... (encrypted_content set) with call_ldrnwSJ

ZDR without include (gpt-5.5, effort low, non-streaming)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, text 17 + 25 = 42
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_yqJFGGJ, function_call_output call_yqJFGGJ]

ZDR with a caller-supplied previous_response_id (gpt-5.6)

  1. Same two commands as Before, against port 30453; the stored prior turn returns id: resp_04c8c3c84a67...006...
  2. HTTP 200, status: completed, text The result is **50**. (42 + 8, so the stored turn was honored)
  3. Outbound follow-up: store=False previous_response_id=resp_04c8c3c84a67...006... input=[message, function_call call_lG2Euk9, function_call_output call_lG2Euk9] (the caller's own id, kept as sent)

ZDR, high reasoning, no include, non-streaming (gpt-5.5)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, output types [reasoning, message, mcp_tools_fetched, tool_execution_results], text starts - **17 + 25 = 42** and says neither result is prime
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_BlRDxSG, function_call call_RKGqKsw, function_call_output call_BlRDxSG, function_call_output call_RKGqKsw] (the first response carried no reasoning item this run; the final one carried rs_017d30fe... with encrypted_content set even without include)

ZDR, high reasoning, no include, streaming (gpt-5.5)

  1. Same command as Before, against port 30453
  2. HTTP 200, SSE response.created: 2, response.output_item.done: 6, response.output_text.done: 1, response.completed: 2, [DONE]: 1, text starts 17 + 25 = 42 and says neither result is prime
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_7Tqh1Ak, function_call call_V6tEfPt, function_call_output call_7Tqh1Ak, function_call_output call_V6tEfPt]

store: false set in the model's config, not the request (gpt-5.6-zdr)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, output types [message, mcp_tools_fetched, tool_execution_results], text 17 + 25 = **42**.
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_gPVpZGc, function_call_output call_gPVpZGc]

ZDR through the Anthropic bridge, non-streaming (claude-sonnet-5)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, text 17 + 25 = 42
  3. Outbound follow-up: the same chat-style user, assistant, user turn to Anthropic (unchanged)

ZDR through the Anthropic bridge, streaming (claude-sonnet-5)

  1. Same command as Before, against port 30453
  2. HTTP 200, text 17 + 25 = 42
  3. Outbound follow-up: same chat-style turn as the non-streaming case (unchanged)

/v1/chat/completions control with store: false (gpt-5.6)

  1. Same command as Before, against port 30453
  2. HTTP 200, text 17 + 25 = **42**.
  3. Outbound follow-up: previous_response_id=None (unchanged)

Stateful, high reasoning control (gpt-5.5, store unset)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, text starts 17 + 25 = 42 and says neither result is prime (this run the model asked for both tools in one round)
  3. Outbound follow-up: store=None previous_response_id=resp_0f1685d9b228... input=[message, function_call call_LeGfUET, function_call call_F4wdmEY, function_call_output call_LeGfUET, function_call_output call_F4wdmEY] (unchanged: chained on the first response id, no reasoning replay)

ZDR, sequential tool rounds, streaming (gpt-5.6)

  1. Same command as Before, against port 30453
  2. HTTP 200, SSE response.created: 6, response.output_item.done: 15, response.completed: 6, response.output_text.done: 1, text 17 + 25 = 42, and 42 × 2 = 84.
  3. Outbound follow-ups: five, each store=False previous_response_id=None; the rounds where the model emitted reasoning carry it, e.g. input=[message, reasoning rs_03b2fdb8c... (encrypted_content set), function_call call_j1sOMEA, function_call_output call_j1sOMEA]

ZDR, sequential tool rounds, non-streaming (gpt-5.6)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, empty text: the single follow-up round ended on the second function_call, exactly as the stateful case below
  3. Outbound follow-up: store=False previous_response_id=None input=[message, function_call call_yRLQecQ, function_call_output call_yRLQecQ]

Stateful, sequential tool rounds, non-streaming (gpt-5.6, store unset)

  1. Same command as Before, against port 30453
  2. HTTP 200, status: completed, empty text: the single follow-up round ended on the second function_call (unchanged)
  3. Outbound follow-up: store=None previous_response_id=resp_01987751b5da... input=[message, function_call ..., function_call_output ...] (unchanged)

Spend rows

  1. curl -sS http://127.0.0.1:30453/spend/logs -H "Authorization: Bearer sk-lit5427-qa"
  2. 41 rows, total spend $0.0258: the ZDR /v1/responses cases are now logged as successful calls, the MCP list_tools and call_mcp_tool rows alongside them

Observations from the run, each with whether this PR causes it, worsens it, or leaves it alone:

  • Non-streaming MCP runs one follow-up round only: pre-existing, left alone
  • Sequential tool asks then end on a bare function_call: pre-existing, left alone
  • Streaming loops rounds but replays only the latest round: pre-existing, left alone
  • Streaming emits one response.created/response.completed pair per round: pre-existing, left alone
  • OpenAI returns encrypted_content under store: false without include: observed, why the no-include cases pass
  • gpt-5.6 emitted no reasoning items in these runs: observed, replay evidence is from gpt-5.5

Type

🐛 Bug Fix

Caveats (if any)

Low

  • Stateless replay resends the prior turn, so follow-up prompts are larger
    • Inherent to the fix: the provider has nothing stored to chain on
  • Non-streaming MCP still runs one follow-up round, so sequential tool asks end on a function_call
    • Pre-existing on the stateful path too; multi-round non-streaming is separate work
  • Streaming follow-ups carry only the latest round's tool call and output
    • Pre-existing and unchanged here
  • Reasoning items are replayed as-is, so one without encrypted_content would be sent back verbatim
    • Not observed: OpenAI sets it on every reasoning item under store: false; handling an unseen shape is net-negative
  • proxy-infra / Run tests (Python 3.10) is red on staging's own test_http_parsing_utils.py (fails on every PR and on staging itself, fix in fix(proxy): strip every TypedDict qualifier before numeric form-field detection #39780), not on this diff, and it is not a required check
  • ci/circleci: proxy_store_model_in_db_tests is red on tests/store_model_in_db_tests/test_openai_error_handling.py::test_chat_completion_bad_model_with_spend_logs (assert '' == 'non-existent-model'), which also fails on staging's six latest pipelines (89086 through 89115) and is not a required check

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Link to Devin session: https://app.devin.ai/sessions/59dc2762429347968e755ac996c90c34
Requested by: @mateo-berri


Note

Medium Risk
Changes MCP follow-up request shaping and previous_response_id for a sensitive ZDR path; scope is limited to Responses MCP auto-execute with broad test coverage, but incorrect replay could still break reasoning models or multi-tool turns.

Overview
Fixes MCP auto-execution on zero data retention (store: false) Responses requests, where the post-tool follow-up used to chain on the first turn’s previous_response_id even though that response was never stored.

When persistence is off, the non-streaming MCP path now passes the caller’s previous_response_id into _make_follow_up_call instead of the ephemeral first-response id, and builds follow-up input with preserve_reasoning so reasoning items (including encrypted_content) are replayed in original output order alongside function calls—not batched separately.

Adds _is_persistence_disabled and extends _create_follow_up_input with ordered turn_items; the streaming MCP iterator uses the same reasoning replay when store is false. Stateful requests (store true/unset) still chain on the first response id and do not resend reasoning. Regression tests cover LIT-5427 for both paths.

Reviewed by Cursor Bugbot for commit 4b24e3b. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri mateo-berri self-assigned this Aug 11, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR keeps MCP follow-up calls stateless when store=false by retaining the caller’s response-chain identifier and replaying encrypted reasoning items in output order. Stateful behavior remains unchanged, and both streaming and non-streaming paths have regression coverage

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness or repository-rule issues in its current changes

The stateless MCP paths consistently avoid chaining to an unpersisted response while replaying encrypted reasoning, and the stateful paths preserve their existing behavior. Both previous review threads are resolved, including the test-patching concern that Greptile withdrew after the implementation constraints were clarified

Important Files Changed

Filename Overview
litellm/responses/main.py Selects stateless follow-up request behavior when persistence is explicitly disabled
litellm/responses/mcp/litellm_proxy_mcp_handler.py Detects disabled persistence and preserves ordered reasoning items while constructing follow-up input
litellm/responses/mcp/mcp_streaming_iterator.py Applies the same reasoning replay behavior to streaming MCP follow-ups
tests/test_litellm/responses/mcp/test_litellm_proxy_mcp_handler.py Covers stateless response identifiers, encrypted reasoning replay, ordering, and stateful behavior
tests/test_litellm/responses/mcp/test_mcp_streaming_iterator.py Covers streaming reasoning replay and unchanged stateful chaining

Reviews (4): Last reviewed commit: "Merge remote-tracking branch 'origin/lit..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@codspeed

codspeed Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_mcp_stateless_follow_up_zdr (4b24e3b) with litellm_internal_staging (b3c867c)

Open in CodSpeed

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri changed the title fix(responses/mcp): make MCP follow-up calls stateless when store=false fix(responses/mcp): keep follow-up calls stateless when store=false Sep 3, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@mateo-berri
mateo-berri requested a review from a team September 5, 2026 00:05
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri added run-ci and removed run-ci labels Sep 5, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4b24e3b. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mateo-berri
mateo-berri merged commit 6960a42 into litellm_internal_staging Sep 5, 2026
233 of 237 checks passed
@mateo-berri
mateo-berri deleted the litellm_mcp_stateless_follow_up_zdr branch September 5, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant