feat(cache): add cache token audit logging behind OPENCODE_EXPERIMENTAL_CACHE_AUDIT#27007
Open
martinffx wants to merge 5 commits into
Open
feat(cache): add cache token audit logging behind OPENCODE_EXPERIMENTAL_CACHE_AUDIT#27007martinffx wants to merge 5 commits into
martinffx wants to merge 5 commits into
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Open
3 tasks
…NCODE_CACHE_AUDIT Co-authored-by: Bhagirathsinh Vaghela <bhagirathsinh.vaghela.001@gmail.com>
…NCODE_CACHE_AUDIT Co-authored-by: Bhagirathsinh Vaghela <bhagirathsinh.vaghela.001@gmail.com>
A conflict during the rebase incorrectly removed the const references = yield* Reference.Service line from the prompt.ts layer generator, causing 7 typecheck errors. Adding it back restores the Reference.Service dependency needed by resolvePromptParts.
efd4a32 to
f6b1ccd
Compare
6 tasks
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.
Issue for this PR
Closes #5416, #5224
Related: #14065, #5422, #14203, #14743
Part of the stacked PR decomposition of the prompt caching fix (1 of 4). Adds cache token audit logging as observability foundation, the metrics logged here are what we use to verify cache hit improvements in subsequent PRs.
Type of change
What does this PR do?
Adds cache token audit logging behind
OPENCODE_EXPERIMENTAL_CACHE_AUDIT=1, providing per-LLM-call cache hit/miss visibility. This PR is purely observability — it does not change any caching behavior.Changes:
packages/core/src/flag/flag.ts— addsOPENCODE_EXPERIMENTAL_CACHE_AUDITflag.packages/opencode/src/session/session.ts— addsrawInputTokensto the usage return value (sum of input + cache read + cache write), needed by both the log and sidebar display.packages/opencode/src/session/processor.ts— after each LLM call'sgetUsage(), if the flag is set, logs a[CACHE]line with total input tokens, cache read/write/new breakdown, hit percentage, and output tokens.packages/opencode/src/cli/cmd/tui/feature-plugins/sidebar/context.tsx— when the flag is set, displays a "Cache Audit" box in the TUI sidebar showing the same token breakdown and hit rate in real time.Why this PR first: The subsequent PRs in the stack improve cache hit rates. This PR provides the measurement tooling to verify those improvements work.
How did you verify your code works?
Set
OPENCODE_EXPERIMENTAL_CACHE_AUDIT=1 bun dev, send a prompt, and confirm:[CACHE]log line appears per LLM call in the log outputTests:
bun test packages/opencode/test/session/session.test.tspasses.Screenshots
Checklist
Co-authored-by: Bhagirathsinh Vaghela bhagirathsinh.vaghela.001@gmail.com