Skip to content

fix: fingerprint cacheable context prefix#6067

Open
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/context-cache-dynamic-instruction
Open

fix: fingerprint cacheable context prefix#6067
he-yufeng wants to merge 1 commit into
google:mainfrom
he-yufeng:fix/context-cache-dynamic-instruction

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Use the cacheable content prefix for fingerprint-only cache metadata instead of the full request contents.
  • Keep request-scoped dynamic instruction contents out of the initial fingerprint chain.
  • Update CacheMetadata.contents_count docs to match the prefix semantics.

Fixes #6062.

Testing plan

This PR is covered by focused unit tests for the Gemini context cache manager. The important behavior is that cache fingerprints are derived only from the cacheable prefix, while request-local dynamic instructions still flow into the request without changing the cache identity.

Verification output

Run locally on Windows with Python 3.13:

python -m py_compile src\google\adk\models\gemini_context_cache_manager.py src\google\adk\models\cache_metadata.py
# passed

PYTHONPATH=src python -m pytest tests\unittests\agents\test_gemini_context_cache_manager.py -q
# passed

python -m ruff check src\google\adk\models\gemini_context_cache_manager.py src\google\adk\models\cache_metadata.py tests\unittests\agents\test_gemini_context_cache_manager.py
# passed

git diff --check
# passed

Risk

Low. The patch narrows what contributes to fingerprint-only cache metadata; it does not change response generation, model selection, or live cache service calls.

@adk-bot

adk-bot commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Response from ADK Triaging Agent

Hello @he-yufeng, thank you for submitting this pull request!

This is a bug fix (associated with #6062). To help reviewers process your contribution more efficiently, could you please update the PR to include:

  1. A testing plan section describing how you tested your changes (as requested in our Contribution Guidelines).
  2. Logs or verification output (such as the output of the passed pytest results) showing that the tests run successfully after your changes.

Thank you for your help in keeping the codebase robust!

@he-yufeng he-yufeng force-pushed the fix/context-cache-dynamic-instruction branch from 778780d to 02135c2 Compare June 10, 2026 19:34
@rohityan rohityan self-assigned this Jun 11, 2026
@rohityan rohityan added services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc request clarification [Status] The maintainer need clarification or more information from the author labels Jun 11, 2026
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @he-yufeng , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Please fix formatting errors.

@he-yufeng he-yufeng force-pushed the fix/context-cache-dynamic-instruction branch from 62773e9 to 3e848fb Compare June 11, 2026 22:39
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Pushed an updated branch with the formatting fix and rebased it onto current main.

Validation:

  • python -m py_compile src\google\adk\models\cache_metadata.py src\google\adk\models\gemini_context_cache_manager.py tests\unittests\agents\test_gemini_context_cache_manager.py
  • PYTHONPATH=src python -m pytest -q tests\unittests\agents\test_gemini_context_cache_manager.py --basetemp .tmp\pytest-6067 -p no:cacheprovider (30 passed)
  • python -m pre_commit run pyink --files src\google\adk\models\cache_metadata.py src\google\adk\models\gemini_context_cache_manager.py tests\unittests\agents\test_gemini_context_cache_manager.py
  • python -m pre_commit run isort --files src\google\adk\models\cache_metadata.py src\google\adk\models\gemini_context_cache_manager.py tests\unittests\agents\test_gemini_context_cache_manager.py
  • git diff --check upstream/main..HEAD

@he-yufeng he-yufeng force-pushed the fix/context-cache-dynamic-instruction branch 2 times, most recently from 3febc5c to 8dbc9cc Compare June 12, 2026 04:45
@he-yufeng he-yufeng force-pushed the fix/context-cache-dynamic-instruction branch from 8dbc9cc to de5b663 Compare June 12, 2026 13:10
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased this on current main and re-ran the focused local checks:

  • python -m py_compile on the touched Python files
  • PYTHONPATH=src python -m pytest -q tests\unittests\agents\test_gemini_context_cache_manager.py --basetemp .tmp\pytest-6067 -p no:cacheprovider
  • pre_commit run isort on the touched files
  • python -m pyink --check on the touched files
  • git diff --check upstream/main..HEAD

The focused test run passed with 30 tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit context cache never engages (cache_name always None) when a dynamic instruction coexists with static_instruction

3 participants