Fix cache-corrupted token metrics in multi-turn Claude Code eval - #509
Open
prernakakkar-google wants to merge 6 commits into
Open
Fix cache-corrupted token metrics in multi-turn Claude Code eval#509prernakakkar-google wants to merge 6 commits into
prernakakkar-google wants to merge 6 commits into
Conversation
prernakakkar-google
requested review from
IsmailMehdi and
helloeve
as code owners
July 21, 2026 08:29
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Collaborator
Author
|
/gcbrun |
IsmailMehdi
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Multi-turn claude_code evaluations drove each turn with a fresh claude -p --resume --fork-session subprocess. Prompt-cache continuity does not survive across separate claude -p invocations, so every turn after the first re-paid a cold cache_creation cost instead of reading from cache. This inflated cache_creation_input_tokens and corrupted the token metrics the eval exists to measure (tokens_processed, effective_billed_tokens). (known issue)
Fix
Drive an entire scenario through one persistent claude process using Claude Code's streaming-input mode (-p --input-format stream-json --output-format stream-json --verbose): each turn is a newline-delimited user message on stdin, and the process stays alive across turns, so session context and the prompt cache persist. Closing stdin ends the session.
Introduces a small per-scenario session abstraction (AgentCliSession) so the change is backward-compatible:
Also included (related: Vertex cache accuracy)
Default Claude Vertex calls to the global endpoint (vertex_region: "global"); regional pinning worsens cache-hit determinism and is unsupported past Sonnet 4.6.
https://paste.googleplex.com/newui/?id=5943794385158144