feat(core): diagnose prompt cache prefix changes - #39139
Merged
Merged
Conversation
kitlangton
force-pushed
the
cache-prefix-diagnostics
branch
from
July 27, 2026 16:21
f19144e to
1e479c4
Compare
kitlangton
force-pushed
the
cache-prefix-diagnostics
branch
from
July 27, 2026 17:43
0778f17 to
9ccff5d
Compare
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.
What
Add opt-in prompt cache diagnostics for V2 model requests. Set:
Consecutive provider-bound Physical Attempts in a Session are then classified as:
initialstableappend-onlychanged, with the first changed component identified as settings, tools, system, or messagesThis makes intermittent provider cache misses actionable without enabling unrelated debug logs or logging prompt, tool, or message contents.
How
packages/core/src/session/prompt-cache-diagnostics.tsbuilds truncated SHA-256 snapshots of cache-sensitive request components and compares their ordered prefixes.SessionModelRequestallocates diagnostics state and hashes requests only whenOPENCODE_PROMPT_CACHE_DIAGNOSTICSis enabled.infologs, so the dedicated flag is sufficient on its own.SessionModelRequest.prepare, so snapshots correspond to provider-bound Physical Attempts.Example structured log classifications:
Scope
packages/core; it does not touch V1packages/opencode.Testing
bun run test test/prompt-cache-diagnostics.test.tsfrompackages/core: 5 passedbun typecheckfrompackages/corebun turbo typecheck --concurrency=3: 32 packages passedgit diff --checkv2base independently fails existingsession-runner.test.tsexpectations after recent Code Mode/tool-result changes; reproduced from an untouchedorigin/v2worktree. The added prefix assertion passes before the existing stale expectation fails.