fix(session): warn on cache busts - #40796
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #40790
Type of change
What does this PR do?
Adds a small diagnostic for likely Anthropic prompt-cache busts. When a completed step reports a large cache write with zero cache reads for an Anthropic/Claude model, the session processor now emits a warning with the session, model, finish reason, cache-write tokens, cache-read tokens, and cost.
This does not revive the previously rejected object-identity caching approach from #36852. It only makes the high-cost pattern reported in #40790 visible in logs so users and maintainers can confirm when it happens.
How did you verify your code works?
bun test test/session/compaction.test.ts --test-name-pattern "flags likely Anthropic cache busts|does not flag ordinary cache hits" --timeout 30000failed becauseSessionNs.cacheBustWarningdid not exist.bun test test/session/compaction.test.ts --test-name-pattern "SessionNs.getUsage" --timeout 45000— 17 pass.bun run typecheckbun run lint packages/opencode/src/session/session.ts packages/opencode/src/session/processor.ts packages/opencode/test/session/compaction.test.tsgit diff --checkNotes: two broader session tests fail the same way on a clean
devbaseline in this Windows checkout:stops quickly when aborted during retry backoffretry OpenAI-compatible midstream server errorsScreenshots / recordings
Not a UI change.
Checklist