Skip to content

fix(models): Port Gemini context cache fingerprint scoping to v1 - #6804

Open
GWeale wants to merge 1 commit into
v1from
backport-v1-pr15
Open

fix(models): Port Gemini context cache fingerprint scoping to v1#6804
GWeale wants to merge 1 commit into
v1from
backport-v1-pr15

Conversation

@GWeale

@GWeale GWeale commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

This PR ports one fix to the v1 branch.

  1. fix: scope Gemini cache identity (8de4237e)
    • The explicit-cache fingerprint includes the model id and a cache_scope recording the backend, the client base URL when one is set, and, for Vertex, the project and location.
    • Fingerprint inputs are dumped with mode="json" and hashed as canonical JSON with sorted keys.
    • A system instruction that will not serialize to JSON falls back to its string form.

Behaviour change. Existing explicit context caches are invalidated and recreated once on upgrade, with no opt-out. A stored cache_name matches only for the same model, backend, base URL, and Vertex project and location.

No public API change. _generate_cache_fingerprint keeps its signature and its 16-character hexadecimal return value.

The explicit-cache fingerprint was computed from the system instruction,
tools, tool config and content prefix alone. It did not include the model,
and it did not include the backend the cache lives in. An identical prompt
prefix under a different model, or under a different Vertex project or
location, produced the same fingerprint, so a stored cache_name belonging
to another context was treated as reusable and attached to a request that
had no relationship to it.

The fingerprint is now seeded with the model id and a cache scope. The
scope records whether the client talks to Vertex or the Developer API, and
for Vertex it records the project, the location and the base URL. Model
dumps run in JSON mode and the hash input is canonical JSON with sorted
keys, rather than the repr of a Python dict. A system instruction the SDK
accepts but cannot serialize to JSON falls back to its string form.

Behaviour change: every fingerprint value changes, so on upgrade a user
with an active explicit context cache takes one cache miss and one cache
re-creation. That cost is unavoidable while fixing the identity, because
the old fingerprints did not identify what they were caching. In the other
direction, argument mappings that differ only in key insertion order now
hash the same, which removes cache misses that were happening for no
reason.
@GWeale GWeale changed the title fix(models): Port Gemini context cache identity scoping to v1 fix(models): Port Gemini context cache fingerprint scoping to v1 Aug 19, 2026
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