Skip to content

fix(caching): stop counting an unrun server tool call mark, and follow #49192 and #35602 in their integration tests - #49468

Merged
mateo-berri merged 3 commits into
mainfrom
litellm_deflake_20261031_stale_refusal_cache_marks
Oct 31, 2026
Merged

mateo-berri merged 3 commits into
mainfrom
litellm_deflake_20261031_stale_refusal_cache_marks

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Six integration tests went red on main's scheduled run after #49192 and #35602 landed. Five of them expected the old responses, and one caught a real census bug where the cache_control injection counted a marked web search call that Anthropic never receives, so the system prompt lost its cache breakpoint even with a slot free

Details

TLDR

Problem this solves:

How it solves it:

  • The census never counts an unanswered server tool call mark on Anthropic builds
  • Other builds keep counting it unless a kept result rebuilds it
  • Tests now expect message.refusal, Snowflake stop_details and the Responses cache hit shape
  • The Gemini test now checks the system prompt rides in the context cache

User Flow

Before: a developer replays a Claude turn with an unrun web search and gets no system prompt breakpoint

  1. The proxy admin sets cache_control_injection_points for the system message and the last message
  2. The developer sends POST /v1/chat/completions with a marked ask, two marked tool calls and a marked srvtoolu_ web search with no result
  3. Anthropic receives three breakpoints and an unmarked system prompt, though the cap is four

After: the same request fills the free slot with the system prompt

  1. Same config as before
  2. Same POST /v1/chat/completions
  3. Anthropic receives four breakpoints, the system prompt included

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Shared setup is one proxy per side on anthropic/claude-sonnet-5-5 with a real Anthropic key and cache_control_injection_points of {location: message, role: system} and {location: message, index: -1}. Each side gets the same POST /v1/chat/completions, a system message, a marked ask, an assistant turn with marked call_weather_london, call_weather_paris and srvtoolu_web calls, the two tool results, then a new user message. The outbound Anthropic body comes from --detailed_debug

Commands, run once per side (--port 4001 on the base worktree, --port 4002 on the tip)

# config.yaml
model_list:
  - model_name: claude
    litellm_params:
      model: anthropic/claude-sonnet-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
      cache_control_injection_points:
        - location: message
          role: system
        - location: message
          index: -1
general_settings:
  master_key: sk-qa-key
python -m litellm.proxy.proxy_cli --config config.yaml --port 4002 --detailed_debug > tip.log 2>&1 &
curl -s localhost:4002/v1/chat/completions -H 'Authorization: Bearer sk-qa-key' -H 'Content-Type: application/json' -d @body.json
grep -A3 'POST Request Sent from LiteLLM' tip.log   # the outbound Anthropic body
// body.json
{"model": "claude", "max_tokens": 64,
 "tools": [{"type": "function", "function": {"name": "lookup_weather", "description": "Look up the weather in a city.", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}],
 "messages": [
  {"role": "system", "content": "Use the provided tool results to answer the user."},
  {"role": "user", "content": [{"type": "text", "text": "Look up the weather in London and Paris, and search the web too.", "cache_control": {"type": "ephemeral"}}]},
  {"role": "assistant", "content": "", "tool_calls": [
    {"id": "call_weather_london", "type": "function", "function": {"name": "lookup_weather", "arguments": "{\"city\": \"London\"}"}, "cache_control": {"type": "ephemeral"}},
    {"id": "call_weather_paris", "type": "function", "function": {"name": "lookup_weather", "arguments": "{\"city\": \"Paris\"}"}, "cache_control": {"type": "ephemeral"}},
    {"id": "srvtoolu_web", "type": "function", "function": {"name": "web_search", "arguments": "{}"}, "cache_control": {"type": "ephemeral"}}]},
  {"role": "tool", "tool_call_id": "call_weather_london", "content": "sunny."},
  {"role": "tool", "tool_call_id": "call_weather_paris", "content": "sunny."},
  {"role": "user", "content": "Summarize the weather in one short sentence."}
 ]}

Before (aea0e4f)

Live proxy

  1. The request returns 200 with prompt_tokens 589
  2. The Anthropic body carries an unmarked system block and three marks (ask, London, Paris), srvtoolu_web already dropped
system: [{"type": "text", "text": "Use the provided tool results to answer the user."}]
  user [('text', 'Look up the weather in Lo', True)]
  assistant [('tool_use', 'call_weather_london', True), ('tool_use', 'call_weather_paris', True)]

Integration suite

  1. INTEGRATION_WORKERS=2 tests/integration/run.py providers on the two files gives 13 failed, 143 passed

After (ee85bec)

Live proxy

  1. The request returns 200 with prompt_tokens 589
  2. The Anthropic body now marks the system block as well, four marks in all
system: [{"type": "text", "text": "Use the provided tool results to answer the user.", "cache_control": {"type": "ephemeral"}}]
  user [('text', 'Look up the weather in Lo', True)]
  assistant [('tool_use', 'call_weather_london', True), ('tool_use', 'call_weather_paris', True)]

Integration suite

  1. The same command gives 156 passed, and the Gemini cell reruns at the tip with 2 passed after its cache-write body assertion
  2. The two new census-vs-wire unit cases and the renamed unmatched-call case fail on the base (5 failed) and pass at the tip

Type

🐛 Bug Fix
✅ Test

Caveats (if any)

Medium

Low

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

mateo-berri and others added 2 commits October 31, 2026 18:34
…#49192 and #35602 in their integration tests

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

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Contributor

@greptileai

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no outstanding findings

Summary

Fixes cache-breakpoint counting so an unrun Anthropic server tool call does not consume a slot

  • Unrun Anthropic server tool calls leave cache slots available.
  • Refusal tests now check the details each API returns.
  • Gemini cache tests check that the system prompt enters the cached prefix.

Reviews (4) · Last reviewed commit: "test(integration): assert the Gemini cac..." · Reviewed by Greptile

…rompt

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

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@codecov

codecov Bot commented Oct 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing litellm_deflake_20261031_stale_refusal_cache_marks (ee85bec) with main (ee39de7)

Open in CodSpeed

@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 ee85bec. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri
mateo-berri merged commit 3155aac into main Oct 31, 2026
93 of 94 checks passed
@mateo-berri
mateo-berri deleted the litellm_deflake_20261031_stale_refusal_cache_marks branch October 31, 2026 19:27
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.

2 participants