Repository navigation
fix(cache): keep cache hits free of unset fields, and follow intentional behavior changes in CircleCI suites - #46359
Conversation
…pricing in CircleCI suites 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>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. Both cache writers now use Checks and execution details
View review · Reviewed |
|
bugbot run |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…_count_tokens_decisions_cost
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>
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>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
|
@litereview code-review |
| ) | ||
| else: | ||
| result_json: Final = result.model_dump_json() | ||
| result_json: Final = result.model_dump_json(exclude_unset=True) |
There was a problem hiding this comment.
Low · Undisclosed production change to cached response serialization in a test-only PR
- The title is
test(integration): .... The description covers only three test suites. The attached Bugbot summary says "Test-only changes; no production code paths modified." - The diff also changes two production writers to
model_dump_json(exclude_unset=True):LLMCachingHandler.async_set_cacheandCache._add_cache_logic. - With that change, every cached
ModelResponse,ResponsesAPIResponse,TranscriptionResponseandRerankResponseloses its unset fields in the stored payload. Examples aresystem_fingerprint,message.provider_specific_fields, transcriptionusageand rerankmeta. Cache hits now return a different body shape than before. - The new unit test and the edited observability and team-admin assertions depend on this behavior. Nothing in the PR explains why the change belongs here, how it affects callers, or what happens to cache entries written before it.
I found no functional break with a local cache: completion, streaming-from-cache and Responses round-trips still work. The fix is to split the cache change into its own PR with a fix:/feat: title and an explanation, or to document it in this PR's title and description.
Evidence
Diff: litellm/caching/caching.py:712 and litellm/caching/caching_handler.py:1183 change model_dump_json() to model_dump_json(exclude_unset=True).
Local script (uv env, local cache): fields dropped by exclude_unset: ModelResponse -> system_fingerprint, message.provider_specific_fields; TranscriptionResponse -> usage; RerankResponse -> meta; ResponsesAPIResponse -> error, instructions, tools, tool_choice, temperature, top_p, ....
Mutation: reverting caching_handler.py to model_dump_json() makes test_async_cache_preserves_presence_of_provider_optional_fields[False] fail, so the new test depends on the production change.
PR body lists only the decisions, PDF count_tokens and budget count_tokens fixes. It does not mention the caching edit or the team-admin, MCP and observability assertion edits.
Latest summary by code-review · View this review · Reviewed 57a1ea8423d1
There was a problem hiding this comment.
Title and TLDR now name the cache change, and item 1 explains it. Hits rebuild unset defaults on load, so only presence-aware dumps change shape
There was a problem hiding this comment.
Finding withdrawn
I'm withdrawing this finding because the PR now covers what it said was missing. The finding didn't claim the cache change was functionally broken. It flagged a production change hidden inside a test(...)-titled PR with no explanation. The PR has since been updated:
- The title is now
fix(cache): keep cache hits free of unset fields, ..., so it names the production change. - The TLDR says "Cache writes keep only fields the response actually set". A User Flow section covers the caller-visible effect: a cache hit no longer adds
system_fingerprint: null, and a provider's explicit null still comes back as null. - Item 1 under "Failing tests, culprits, mechanism" ties the change to fix(proxy): keep provider refusal, logprobs and system_fingerprint in chat completions #44788 and names both writers,
caching.pyandcaching_handler.py. It also names the regression test.
Entries written before this change still store every field. On load they behave as they did before the PR, so no migration is needed. The code is unchanged since the finding: both writers still use exclude_unset=True.
Evidence
litellm/caching/caching.py:712: result = result.model_dump_json(exclude_unset=True)
litellm/caching/caching_handler.py:1183: result_json: Final = result.model_dump_json(exclude_unset=True)
PR title: fix(cache): keep cache hits free of unset fields, and follow intentional behavior changes in CircleCI suites
PR description, item 1: "Fix: both cache writes in litellm/caching/caching.py and litellm/caching/caching_handler.py use exclude_unset=True, with a regression test in tests/unit/caching/test_caching_handler.py covering omitted and explicit-null fields"
GitHub does not allow this App to resolve this thread. A repository maintainer must do it manually.
Reviewed 81661df21eeb · View follow-up
Merging this PR will not alter performance
|
|
@litereview code-review |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
|
@litereview code-review |
There was a problem hiding this comment.
✅ 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 81661df. Configure here.
|
@litereview code-review |
TLDR
Problem this solves:
integrationon main is red in seven jobssystem_fingerprint: nullthe provider never sentHow it solves it:
_decisionscost-map rates feat(decisions): bill decisions and systemone from _decisions cost map fields #45904 introducedUser Flow
Before: a developer with response caching on gets a different body on a cache hit than on the original call
system_fingerprintkey, matching what the provider returned"system_fingerprint": null, so a client diffing or strictly parsing responses sees a new fieldAfter: the cache hit has exactly the same keys as the original response
system_fingerprintkeyFailing tests, culprits, mechanism
Red on main in pipeline 91228 (checkout 7fa52b2) and the runs before it
tests/integration/observability/test_logging_only_scope_runtime.py::test_cache_hit_directional_scope_uses_measured_base_default[C1-chat-cache-output]and[C2-chat-cache-input]inintegration-extensions(job 2259639)model_dump_json()with every default, so the rebuilt hit markedsystem_fingerprintandrefusalas setlitellm/caching/caching.pyandlitellm/caching/caching_handler.pyuseexclude_unset=True, with a regression test intests/unit/caching/test_caching_handler.pycovering omitted and explicit-null fieldsAbout 20 Arize OTel v2 tests in
integration-extensions(test_arize_otel_v2_openinference_chaos.py,_family.py,_modes.py) expectedprovider_specific_fields: {"refusal": None}on chat messagesmessage.refusal, present only when the provider sends it_openinference_support.pydrops that fieldtests/integration/observability/test_apply_guardrail_endpoint.py::test_apply_guardrail_forwards_messages_to_the_guardrailexpected the Akto URL withoutingest_data=true&ingest_data=trueon both callstests/integration/authorization/test_team_admin_gate.py::test_only_proxy_admin_reads_or_changes_credentials[*]inintegration-management(job 2259618) andintegration-management-replicadisplay_nameto credential responses, and the pin from 013c440 (test(integration): cover model_management endpoint contracts #44684) left it out"display_name": Nonewith strict equalitytests/integration/mcp/test_mcp_accounting_guardrails.py::test_a_schema_past_the_scan_depth_is_not_published_while_one_at_the_limit_is_scanned_on_the_callinintegration-mcp(job 2259632)Tool deep not foundtests/integration/providers/test_decisions_openai_format_wire.py::test_each_provider_gets_its_own_path_key_and_body_and_is_billed[openai/gpt-6-luna]inintegration-providers/v1/decisionsfrom<field>_decisionsrates_decisionsfields from the cost map JSON, falling back per fieldtests/integration/messages_endpoint/providers/anthropic/test_pdf_document_count_tokens_wire.pyandtest_pdf_document_count_tokens_chaos.pygot 400count_tokens is not supported/v1/messages/count_tokenssurfaces as 400tests/integration/spend/test_cache_and_quota.py::test_repeated_count_tokens_on_budgeted_key_does_not_reserve_budget_or_block_later_completioninintegration-accountinggot404 Unknown scenario/v1/responses/input_tokens/v1/responses/input_tokensand every budget assertion staystests/integration/providers/test_cursor_responses_wire.py::test_cursor_messages_body_uses_chat_completions_wire[False-*]inintegration-providers, red on main in pipeline 91231 at 30b8db3message.provider_specific_fields: {"refusal": None}Mutation checks: restoring the default cache dump turns the new unit test and the cache-hit integration cases red, and reverting each test-contract change turns its test red against current main
Deferred
integration-accountingtest_shutdown_flush.py::test_daily_spend_batch_cancelled_while_waiting_for_a_pool_connection_is_written_by_the_final_flushintegration-providerstest_cache_control_tool_call_marks_wire.py[breakpoint-dialect], twotest_chat_completions_basic_openroutercases, bedrock mantle count_tokens[int]and the pre-content retry wire testintegration-costbridge cost paritydictionary changed size during iteration, seen onceintegration-managementand-replicarevocation tests from test(integration): cover orgs_users_customers endpoint contracts #44725 (test_end_user_block,test_user_delete_revokes_keys,test_access_group_model_listing,test_organization_lifecycle), equally red on main in pipeline 91231 and green locally on both sidesintegration-accountingtest_team_member_spend.py::test_member_update_lowering_the_budget_below_spend_blocks_the_next_callfails inpeersetup on main and heretest_user_updates_wedged_coordination_redis.pyandtest_prometheus_shared_custom_labels.py, flaky on main and at the merge basee2e_ui_testing, flaky on main and owned by the deflake automationtest_messages_stream_retry_budget_sources_owned_proxy,test_team_model_tpm_limitconcurrent reservation,test_cli_sso_login_ui_disabledlogin burst,test_background_interaction_settlementGemini 404 andtest_logging_only_scope_chaosK2, left to the deflake automationosv-scanformlflow 3.15.0PYSEC-2026-3865 inuv.lock, no fixed release, unrelated to this diffPre-Submission checklist
Screenshots / Proof of Fix
Setup is the same on both sides. A proxy with 2 workers, its own Postgres DB, and a shared local Redis cache (
cache: true,type: redis) servesclaude-qa(anthropic/claude-haiku-5-5),gpt-qa(openai/gpt-5.4-mini) andembed-qa(openai/text-embedding-3-small) against the real providers. Each case sends one request with a fresh uuid in the prompt, then repeats it for a cache hitBefore (14e820e)
Claude chat cache hit
choices, created, id, model, object, usagex-litellm-cache-keyset, spend logcache_hit=true) and returns the same keys plus"system_fingerprint": nullOpenAI chat cache hit
system_fingerprintas sent by OpenAI (null for this model)Streaming and embeddings cache hits
"stream": truehit has the same first and last chunk keys as the missdata, model, object, usageand a 1536 long vector, same as the missAfter (57a1ea8)
Claude chat cache hit
choices, created, id, model, object, usagex-litellm-cache-keyset, spend logcache_hit=true) and returns exactlychoices, created, id, model, object, usageOpenAI chat cache hit
system_fingerprintas sent by OpenAI (null for this model)"system_fingerprint": null, so an explicit provider null survives the cacheStreaming and embeddings cache hits
"stream": truehit has the same first and last chunk keys as the missdata, model, object, usageand a 1536 long vector, same as the missEvery hit made no provider call on either side, and spend logs show
cache_hit=truewith 0 spendObservations from the run
choices[0].provider_specific_fields, also on before, left aloneCircleCI pipelines on this branch
integration-securitywent green on rerun after one connection resetBugbot found no issues at 81661df and LiteReview scored it 5/5 with no correctness findings
Type
🐛 Bug Fix
✅ Test
Final Attestation